本文整理汇总了C++中std::domain_error方法的典型用法代码示例。如果您正苦于以下问题:C++ std::domain_error方法的具体用法?C++ std::domain_error怎么用?C++ std::domain_error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std
的用法示例。
在下文中一共展示了std::domain_error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parse
Resources JSONFormatter::parse( const Bytes& value )
{
auto json = json::parse( String::to_string( value ) );
if ( json.count( "data" ) == 0 )
{
throw domain_error( "Root property must be named 'data'." );
}
auto data = json[ "data" ];
Resources resources;
if ( data.is_array( ) )
{
for ( const auto object : data )
{
if ( not object.is_object( ) )
{
throw domain_error( "Root array child elements must be objects." );
}
resources.push_back( parse_object( object ) );
}
}
else if ( data.is_object( ) )
{
resources.push_back( parse_object( data ) );
}
else
{
throw domain_error( "Root property must be unordered set or object." );
}
return resources;
}
示例2: read_point
Point read_point(const Json& json) {
if (json.is_array()) {
auto coords = json.array_items();
return Point(coords[0].number_value(), coords[1].number_value());
}
throw domain_error("Invalid JSON");
}
示例3: parameterCount
size_t XmlRpcFunction::parameterCount (size_t synopsis_index) {
XmlRpcValue func_synop = mSynopsis.arrayGetItem(synopsis_index);
size_t size = func_synop.arraySize();
if (size < 1)
throw domain_error("Synopsis contained no items");
return size - 1;
}
示例4: Insert
void ListAsArray::Insert (Object& object)
{
if (count == array.Length ())
throw domain_error ("list is full");
array [count] = &object;
++count;
}
示例5: idevice
rawmem_idevice (const context& ctx, unsigned image_count = 1)
: idevice (ctx), image_count_(image_count)
{
if (context::unknown_size == ctx_.width ()) {
BOOST_THROW_EXCEPTION (domain_error ("cannot handle unknown sizes"));
}
reset ();
}
示例6: grade
double grade(double mid_exam, double final_exam, const vector<double>& homework) {
if (homework.size() == 0) {
throw domain_error("student has no homework.");
}
double hw_grade = median(homework);
return grade(mid_exam, final_exam, hw_grade);
}
示例7: angle
double angle(const std::vector<Point>& pg){
if(pg.size() < 3)
throw domain_error("Can't compute angle with less than 3 points");
else{
vector<Point>::size_type i = pg.size()-1;
return angle(pg[i-2],pg[i-1],pg[i]);
}
}
示例8: decreaseProbability
/**
* Reduces the probability of the cell being occupied in the grid with given x
* and y indices. Probability of the cell will be decreased by 2, only if
* the probability is not already set to the lowest possible value of 1.
*
* @param x The x index of the cell which will have its probability decreased
* @param y The y index of the cell which will have its probability decreased
* @throws The index out of bounds domain error will be thrown if one of the
* indices will indicate a cell outside of the 50x50 grid
*/
void Grid::decreaseProbability(int x, int y) {
if (x < 0 || x >= COLS_NUMBER || y < 0 || y >= ROWS_NUMBER) {
throw domain_error("Index out of bounds!");
}
if (rawGrid[x][y] > MIN_PROBABILITY) {
rawGrid[x][y] -= 2;
}
}
示例9: median
double median(vector<double> vec){
typedef vector<double>::size_type vec_size;
vec_size size = vec.size();
if(size == 0){
throw domain_error("The size is zero");
}
sort(vec.begin(), vec.end());
return size%2 == 0 ? (vec[mid]+vec[mid-1])/2 : vec[mid];
}
示例10: median
T median(vector<T> v)
{
typedef typename vector<T>::size_type vec_sz;
vec_sz size = v.size();
if (size == 0)
throw domain_error("median of an empty vector");
sort(v.begin(), v.end());
vec_sz mid = size/2;
return size % 2 == 0 ? (v[mid] + v[mid-1]) / 2 : v[mid];
}
示例11: median
double median(vector<double> vec) {
typedef vector<double>::size_type vz;
vz size = vec.size();
if (size == 0) {
throw domain_error("median of an empty vector");
}
sort(vec.begin(), vec.end());
vz mid = size / 2;
return size % 2 == 0 ? (vec[mid - 1] + vec[mid]) / 2 : vec[mid];
}
示例12: nrand
int nrand(const int n) {
if (n <= 0 || n > RAND_MAX) {
throw domain_error("Argument to nrand is out of range.");
}
time_t t = time(nullptr);
srand(t);
const int r = rand() % n;
cout << "r = " << r << endl;
return r;
}
示例13: median
double median(vector<double> v){
typedef vector<double>::size_type vec_sz;
sort(v.begin(), v.end());
vec_sz sz=v.size();
if(sz==0) throw domain_error("Median of an empty vector");
vec_sz mid=sz/2;
return sz%2?v[mid]:(v[mid]+v[mid-1])/2;
}
示例14: getFloatArg
static double getFloatArg( const char * arg )
{
char * endptr;
double x = strtod( arg, &endptr );
if ( endptr == arg )
{
cout << "Error processing argument: " << arg << endl;
throw domain_error( "bad argument" );
}
return x;
}
示例15: median
T median (In begin, In end)
{
int size = end - begin;
if (size == 0)
throw domain_error("median of an empty vector");
sort (begin, end);
int mid = size / 2;
return size % 2 == 0 ? (*(begin+mid) + *(begin+mid-1)) / 2 : *(begin+mid);
}