当前位置: 首页>>代码示例>>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;未经允许,请勿转载。