當前位置: 首頁>>代碼示例>>C++>>正文


C++ std::length_error方法代碼示例

本文整理匯總了C++中std::length_error方法的典型用法代碼示例。如果您正苦於以下問題:C++ std::length_error方法的具體用法?C++ std::length_error怎麽用?C++ std::length_error使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在std的用法示例。


在下文中一共展示了std::length_error方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。

示例1: length_error

 String<Ch,Tr,Capacity>& String<Ch,Tr,Capacity>::operator+=(const Ch* x) {
     size_t n = Tr::length(x);
     if(n + sz > Capacity)
         throw length_error("String::operator+=");
     Tr::copy(s + sz, x, n);
     sz += n;
     s[sz] = 0;
 }
開發者ID:Nobody-7,項目名稱:tcpppl_answers,代碼行數:8,代碼來源:ex12.cpp

示例2: Pop

 int Pop() {
     if (Empty()) {
         throw length_error("Pop(): empty stack");
     }
     int pop_element = element_with_cached_max_.top().first;
     element_with_cached_max_.pop();
     return pop_element;
 }
開發者ID:walrus7521,項目名稱:code,代碼行數:8,代碼來源:09.01.cpp

示例3: dequeue

 int dequeue() {
   if (!count_) {
     throw length_error("empty queue");
   }
   --count_;
   int ret = data_[head_];
   head_ = (head_ + 1) % data_.size();
   return ret;
 }
開發者ID:Oliveck10,項目名稱:elements-of-programming-interviews,代碼行數:9,代碼來源:Circular_queue.cpp

示例4: max

 int max() const {
   if (!A_.empty()) {
     return B_.empty() ? A_.max() : std::max(A_.max(), B_.max());
   } else {  // A_.empty() == true.
     if (!B_.empty()) {
       return B_.max();
     }
     throw length_error("empty queue");
   }
 }
開發者ID:Oliveck10,項目名稱:elements-of-programming-interviews,代碼行數:10,代碼來源:Queue_with_max.cpp

示例5: dequeue

 int dequeue() {
   if (B_.empty()) {
     while (!A_.empty()) {
       B_.push(A_.pop());
     }
   }
   if (!B_.empty()) {
     return B_.pop();
   }
   throw length_error("empty queue");
 }
開發者ID:Oliveck10,項目名稱:elements-of-programming-interviews,代碼行數:11,代碼來源:Queue_with_max.cpp

示例6: pop

 T pop() {
   if (empty()) {
     throw length_error("empty stack");
   }
   T ret = s_.top();
   s_.pop();
   if (ret == aux_.top().first) {
     --aux_.top().second;
     if (aux_.top().second == 0) {
       aux_.pop();
     }
   }
   return ret;
 }
開發者ID:Codec1988,項目名稱:EpiCode,代碼行數:14,代碼來源:Stack_with_max_improved.cpp

示例7: Pop

 int Pop() {
   if (Empty()) {
     throw length_error("Pop(): empty stack");
   }
   int pop_element = element_.top();
   element_.pop();
   const int kCurrentMax = cached_max_with_count_.top().first;
   if (pop_element == kCurrentMax) {
     int& max_frequency = cached_max_with_count_.top.second;
     --max_frequency;
     if (max_frequency == 0) {
       cached_max_with_count_.pop();
     }
   }
   return pop_element;
 }
開發者ID:Heuristack,項目名稱:Productivity,代碼行數:16,代碼來源:Stack_with_max_improved.cpp

示例8: length_error

// @include
const BinaryTreeNode<int>* FindKthNodeBinaryTree(
    const unique_ptr<BinaryTreeNode<int>>& root, int k) {
  const auto* n = root.get();
  while (n) {
    int left_size = n->left ? n->left->size : 0;
    if (left_size < k - 1) {
      k -= (left_size + 1);
      n = n->right.get();
    } else if (left_size == k - 1) {
      return n;
    } else {  // left_size > k - 1.
      n = n->left.get();
    }
  }
  throw length_error("no k-th node in binary tree");
}
開發者ID:JohnKurlak,項目名稱:epibook.github.io,代碼行數:17,代碼來源:k-th_node_binary_tree.cpp

示例9: find_k_th_largest

// @include
int find_k_th_largest(vector<int> A, int k) {
  int left = 0, right = A.size() - 1;

  while (left <= right) {
    default_random_engine gen((random_device())());
    // Generates random int in [left, right].
    uniform_int_distribution<int> dis(left, right);
    int p = partition(left, right, dis(gen), &A);
    if (p == k - 1) {
      return A[p];
    } else if (p > k - 1) {
      right = p - 1;
    } else {  // p < k - 1.
      left = p + 1;
    }
  }
  // @exclude
  throw length_error("no k-th node in array A");
  // @include
}
開發者ID:Oliveck10,項目名稱:elements-of-programming-interviews,代碼行數:21,代碼來源:k-th_largest_element.cpp

示例10: rethrow_located

    /**
     * Rethrow an exception of type specified by the dynamic type of
     * the specified exception, adding the specified line number to
     * the specified exception's message.
     *
     * @param[in] e original exception
     * @param[in] line line number in Stan source program where
     *   exception originated
     * @param[in] reader trace of how program was included from files
     */
    inline void rethrow_located(const std::exception& e, int line,
                                const io::program_reader& reader =
                                  stan::io::program_reader()) {
      using std::bad_alloc;          // -> exception
      using std::bad_cast;           // -> exception
      using std::bad_exception;      // -> exception
      using std::bad_typeid;         // -> exception
      using std::ios_base;           // ::failure -> exception
      using std::domain_error;       // -> logic_error
      using std::invalid_argument;   // -> logic_error
      using std::length_error;       // -> logic_error
      using std::out_of_range;       // -> logic_error
      using std::logic_error;        // -> exception
      using std::overflow_error;     // -> runtime_error
      using std::range_error;        // -> runtime_error
      using std::underflow_error;    // -> runtime_error
      using std::runtime_error;      // -> exception
      using std::exception;

      // create message with trace of includes and location of error
      std::stringstream o;
      o << "Exception: " << e.what();
      if (line < 1) {
        o << "  Found before start of program.";
      } else {
        io::program_reader::trace_t tr = reader.trace(line);
        o << "  (in '" << tr[tr.size() - 1].first
          << "' at line " << tr[tr.size() - 1].second;
        for (int i = tr.size() - 1; --i >= 0; )
          o << "; included from '" << tr[i].first
            << "' at line " << tr[i].second;
        o << ")" << std::endl;
      }
      std::string s = o.str();

      if (is_type<bad_alloc>(e))
        throw located_exception<bad_alloc>(s, "bad_alloc");
      if (is_type<bad_cast>(e))
        throw located_exception<bad_cast>(s, "bad_cast");
      if (is_type<bad_exception>(e))
        throw located_exception<bad_exception>(s, "bad_exception");
      if (is_type<bad_typeid>(e))
        throw located_exception<bad_typeid>(s, "bad_typeid");
      if (is_type<domain_error>(e))
        throw domain_error(s);
      if (is_type<invalid_argument>(e))
        throw invalid_argument(s);
      if (is_type<length_error>(e))
        throw length_error(s);
      if (is_type<out_of_range>(e))
        throw out_of_range(s);
      if (is_type<logic_error>(e))
        throw logic_error(s);
      if (is_type<overflow_error>(e))
        throw overflow_error(s);
      if (is_type<range_error>(e))
        throw range_error(s);
      if (is_type<underflow_error>(e))
        throw underflow_error(s);
      if (is_type<runtime_error>(e))
        throw runtime_error(s);

      throw located_exception<exception>(s, "unknown original type");
    }
開發者ID:stan-dev,項目名稱:stan,代碼行數:74,代碼來源:rethrow_located.hpp

示例11: Max

 int Max() const {
     if (!Empty()) {
         return element_with_cached_max_.top().second;
     }
     throw length_error("Max(): empty stack");
 }
開發者ID:walrus7521,項目名稱:code,代碼行數:6,代碼來源:09.01.cpp

示例12: length_error

 const T& max() const {
   if (!empty()) {
     return aux_.top().first;
   }
   throw length_error("empty stack");
 }
開發者ID:Codec1988,項目名稱:EpiCode,代碼行數:6,代碼來源:Stack_with_max_improved.cpp

示例13: Max

 int Max() const {
   if (!Empty()) {
     return cached_max_with_count_.top().first;
   }
   throw length_error("Max(): empty stack");
 }
開發者ID:Heuristack,項目名稱:Productivity,代碼行數:6,代碼來源:Stack_with_max_improved.cpp


注:本文中的std::length_error方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。