本文整理汇总了C++中out_of_range函数的典型用法代码示例。如果您正苦于以下问题:C++ out_of_range函数的具体用法?C++ out_of_range怎么用?C++ out_of_range使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了out_of_range函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: out_of_range
void denseMatrix<T>::setsize(const int size)
{
if (size < 0)
{
throw out_of_range("Invalid setsize param");
}
m_dimentions = size;
m_data.setsize(size);
for (int i=0; i < size; i++)
{
m_data[i].setsize(size);
}
return;
}
示例2: out_of_range
int wstring::compare(const wstring& str, size_t pos, size_t n) const {
if (pos > length())
throw out_of_range("pos > length()");
size_t rlen = length() - pos;
if (rlen > n)
rlen = n;
if (rlen > str.length())
rlen = str.length();
int r = wchar_traits::compare(data() + pos, str.data(), rlen);
if (r != 0)
return r;
if (rlen == n)
return 0;
return(length() - pos) - str.length();
}
示例3: operator
std::pair<R, RO> operator()(T& t, R r, RO ro)
{
if (!r) return throw_t<_except_>( t, unexpected_end_fragment(), r );
string_range< typename TChars::value_type > rr = srange( tchars()() );
for ( ; rr; ++rr ) if ( *r == *rr )
{
if (!ro)
return throw_t<_except_>( t, out_of_range( tchars()(), distance(r) ), r, ro );
*(ro++) = *rr;
return std::make_pair(++r, ro);
}
return throw_t<_except_>( t, expected_of( tchars()(), distance(r) ), r, ro );
}
示例4: msg
CRef<IQueryFactory>
CQuerySplitter::GetQueryFactoryForChunk(Uint4 chunk_num)
{
if (chunk_num >= m_NumChunks) {
string msg("Invalid query chunk number: ");
msg += NStr::IntToString(chunk_num) + " out of " +
NStr::IntToString(m_NumChunks);
throw out_of_range(msg);
}
if (m_SplitBlk.Empty()) {
Split();
}
return m_QueryChunkFactories[chunk_num];
}
示例5: _copy
std::pair<R, RO> _copy(T& t, R r, RR rr, RO ro)
{
for ( ;r && rr && ro && *r==*rr; ++r, ++rr)
*(ro++) = *r;
if (rr && !r)
return throw_t<_except_>( t, unexpected_end_fragment(), r, ro );
if (rr && !ro)
return throw_t<_except_>( t, out_of_range( distance(r) ), r, ro );
if (rr)
return throw_t<_except_>( t, expected_of( typename string_list::left_type()(), distance(r) ), r, ro);
return std::make_pair(r, ro);
}
示例6: check_range
/**
* Check if specified index is within range.
*
* This check is 1-indexed by default. This behavior can be
* changed by setting <code>stan::error_index::value</code>.
*
* @param function Function name (for error messages)
* @param name Variable name (for error messages)
* @param max Maximum size of the variable
* @param index Index to check
* @param nested_level Nested level (for error messages)
* @param error_msg Additional error message (for error messages)
*
* @throw <code>std::out_of_range</code> if the index is not in range
*/
inline void check_range(const char* function,
const char* name,
int max,
int index,
int nested_level,
const char* error_msg) {
if ((index >= stan::error_index::value)
&& (index < max + stan::error_index::value))
return;
std::stringstream msg;
msg << "; index position = " << nested_level;
std::string msg_str(msg.str());
out_of_range(function, max, index, msg_str.c_str(), error_msg);
}
示例7: findBook
//removes next person from queue
void BookTracker::sellBook(string bookNameIn) {
try {
BookNode *node = findBook(bookNameIn);
WaitList *list = node->getList();
//if the list is not empty
if (list->peek() != nullptr) {
throw out_of_range("There are people waiting for this book. ");
}
node->addToHaveValue(-1);
} catch (invalid_argument e) {
//rethrow error
throw e;
} catch (out_of_range x) {
//rethrow error
throw x;
}
}
示例8: out_of_range
bool repository::extractor::need_update(
const boost::filesystem::path &destination, const std::time_t lifetime) {
try {
BUNSAN_LOG_DEBUG << "Starting " << destination << " " << __func__;
const boost::filesystem::path meta =
destination / m_config.installation.meta;
return !boost::filesystem::is_regular_file(meta) ||
out_of_range(std::time(nullptr), lifetime,
boost::filesystem::last_write_time(meta));
} catch (std::exception &) {
BOOST_THROW_EXCEPTION(
extractor_need_update_error()
<< extractor_need_update_error::destination(destination)
<< extractor_need_update_error::lifetime(lifetime)
<< enable_nested_current());
}
}
示例9: check_row_index
inline bool check_row_index(const char* function,
const char* name,
const Eigen::Matrix<T_y, R, C>& y,
size_t i) {
if (i >= stan::error_index::value
&& i < static_cast<size_t>(y.rows()) + stan::error_index::value)
return true;
std::stringstream msg;
msg << " for rows of " << name;
std::string msg_str(msg.str());
out_of_range(function,
y.rows(),
i,
msg_str.c_str());
return false;
}
示例10: stoull
unsigned long long
stoull(const wstring& str, size_t* idx, int base)
{
wchar_t* ptr;
const wchar_t* const p = str.c_str();
unsigned long long r = wcstoull(p, &ptr, base);
if (ptr == p)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
if (r == 0)
throw invalid_argument("stoull: no conversion");
throw out_of_range("stoull: out of range");
#endif // _LIBCPP_NO_EXCEPTIONS
}
if (idx)
*idx = static_cast<size_t>(ptr - p);
return r;
}
示例11: stold
long double
stold(const string& str, size_t* idx)
{
char* ptr;
const char* const p = str.c_str();
typename remove_reference<decltype(errno)>::type errno_save = errno;
errno = 0;
long double r = strtold(p, &ptr);
swap(errno, errno_save);
#ifndef _LIBCPP_NO_EXCEPTIONS
if (errno_save == ERANGE)
throw out_of_range("stold: out of range");
if (ptr == p)
throw invalid_argument("stold: no conversion");
#endif // _LIBCPP_NO_EXCEPTIONS
if (idx)
*idx = static_cast<size_t>(ptr - p);
return r;
}
示例12: stol
long
stol(const wstring& str, size_t* idx, int base)
{
wchar_t* ptr;
const wchar_t* const p = str.c_str();
typename remove_reference<decltype(errno)>::type errno_save = errno;
errno = 0;
long r = wcstol(p, &ptr, base);
swap(errno, errno_save);
#ifndef _LIBCPP_NO_EXCEPTIONS
if (errno_save == ERANGE)
throw out_of_range("stol: out of range");
if (ptr == p)
throw invalid_argument("stol: no conversion");
#endif // _LIBCPP_NO_EXCEPTIONS
if (idx)
*idx = static_cast<size_t>(ptr - p);
return r;
}
示例13: pythonAddEdge
// addedge(x1, y1, x2, y2, angle = 0, marker = "none")
void pythonAddEdge(double x1, double y1, double x2, double y2, double angle, char *marker)
{
logMessage("pythonAddEdge()");
if (angle > 90.0 || angle < 0.0)
throw out_of_range(QObject::tr("Angle '%1' is out of range.").arg(angle).toStdString());
SceneBoundary *boundary = Util::scene()->getBoundary(QString(marker));
if (!boundary)
throw invalid_argument(QObject::tr("Boundary '%1' is not defined.").arg(marker).toStdString());
// start node
SceneNode *nodeStart = Util::scene()->addNode(new SceneNode(Point(x1, y1)));
// end node
SceneNode *nodeEnd = Util::scene()->addNode(new SceneNode(Point(x2, y2)));
// FIXME 0 -> variable
Util::scene()->addEdge(new SceneEdge(nodeStart, nodeEnd, boundary, angle, 0));
}
示例14: operator
RR operator()(T& t, RR rr)
{
for (register int i=0; i < 4; ++i)
{
if ( !this->peek(t, rr.first) )
{
if (rr.first)
return throw_<_except_>( t, parse_error( distance(rr.first) ), rr);
else
return throw_<_except_>( t, unexpected_end_fragment(), rr);
}
if ( !rr.second )
return throw_<_except_>( t, out_of_range( distance(rr.first) ), rr );
*(rr.second++)= *(rr.first++);
}
return rr;
}
示例15: stof
float
stof(const string& str, size_t* idx)
{
char* ptr;
const char* const p = str.c_str();
int errno_save = errno;
errno = 0;
double r = strtod(p, &ptr);
swap(errno, errno_save);
#ifndef _LIBCPP_NO_EXCEPTIONS
if (errno_save == ERANGE)
throw out_of_range("stof: out of range");
if (ptr == p)
throw invalid_argument("stof: no conversion");
#endif // _LIBCPP_NO_EXCEPTIONS
if (idx)
*idx = static_cast<size_t>(ptr - p);
return static_cast<float>(r);
}