本文整理匯總了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;
}
示例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;
}
示例3: dequeue
int dequeue() {
if (!count_) {
throw length_error("empty queue");
}
--count_;
int ret = data_[head_];
head_ = (head_ + 1) % data_.size();
return ret;
}
示例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");
}
}
示例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");
}
示例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;
}
示例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;
}
示例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");
}
示例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
}
示例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");
}
示例11: Max
int Max() const {
if (!Empty()) {
return element_with_cached_max_.top().second;
}
throw length_error("Max(): empty stack");
}
示例12: length_error
const T& max() const {
if (!empty()) {
return aux_.top().first;
}
throw length_error("empty stack");
}
示例13: Max
int Max() const {
if (!Empty()) {
return cached_max_with_count_.top().first;
}
throw length_error("Max(): empty stack");
}