当前位置: 首页>>代码示例>>C++>>正文


C++ std::domain_error方法代码示例

本文整理汇总了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;
}
开发者ID:sandeshghimire,项目名称:restq,代码行数:35,代码来源:json_formatter.cpp

示例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");
}
开发者ID:Retord,项目名称:kmeans-1,代码行数:7,代码来源:benchmark.cpp

示例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;
}
开发者ID:BenedictHiddleston,项目名称:xmlrpc-c-1.06.30,代码行数:7,代码来源:XmlRpcFunction.cpp

示例4: Insert

void ListAsArray::Insert (Object& object)
{
    if (count == array.Length ())
	throw domain_error ("list is full");
    array [count] = &object;
    ++count;
}
开发者ID:lbaby,项目名称:codeGarden,代码行数:7,代码来源:ListAsArray.cpp

示例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 ();
 }
开发者ID:jlpoolen,项目名称:utsushi,代码行数:8,代码来源:memory.hpp

示例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);
}
开发者ID:lichunming,项目名称:learn-cpp,代码行数:8,代码来源:grade.cpp

示例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]);
    }
}
开发者ID:kxtells,项目名称:convex_hull,代码行数:8,代码来源:geom.cpp

示例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;
    }
}
开发者ID:MichalGoly,项目名称:CS22510-OccupancyGridMapping,代码行数:19,代码来源:Grid.cpp

示例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];
}
开发者ID:570468837,项目名称:Daily-pracitce,代码行数:10,代码来源:median.cpp

示例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];
}
开发者ID:mkzol,项目名称:cpp-exp,代码行数:10,代码来源:t_tmpl_double.cpp

示例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];
}
开发者ID:gdshen95,项目名称:accelerated-cpp-code,代码行数:10,代码来源:median.cpp

示例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;
}
开发者ID:lichunming,项目名称:learn-cpp,代码行数:11,代码来源:generate_sentence.cpp

示例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;
}
开发者ID:ashuto0sh,项目名称:AccelaratedC,代码行数:11,代码来源:median.cpp

示例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;
}
开发者ID:EQ4,项目名称:Paraphrasis,代码行数:11,代码来源:loris_synthesize.C

示例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);
}
开发者ID:yellowjacket05,项目名称:AcceleratedCppExercises,代码行数:12,代码来源:8-4.cpp


注:本文中的std::domain_error方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。