相关疑难解决方法(0)

什么是"Argument-Dependent Lookup"(又名ADL或"Koenig Lookup")?

什么是关于什么参数依赖查找的好解释?很多人也称它为Koenig Lookup.

我最好知道:

  • 为什么这是好事?
  • 为什么这是一件坏事?
  • 它是如何工作的?

c++ c++-faq name-lookup argument-dependent-lookup

163
推荐指数
4
解决办法
3万
查看次数

为Enum提升自定义验证器

我试图验证命令行输入到我已定义的枚举,但得到编译器错误.我使用Handle复杂选项和Boost的program_options作为例子.

namespace po = boost::program_options;

namespace Length
{

enum UnitType
{
    METER,
    INCH
};

}

void validate(boost::any& v, const std::vector<std::string>& values, Length::UnitType*, int)
{
    Length::UnitType unit;

    if (values.size() < 1)
    {   
        throw boost::program_options::validation_error("A unit must be specified");
    }   

    // make sure no previous assignment was made
    //po::validators::check_first_occurence(v); // tried this but compiler said it couldn't find it
    std::string input = values.at(0);
    //const std::string& input = po::validators::get_single_string(values); // tried this but compiler said it couldn't find it

    // I'm …
Run Code Online (Sandbox Code Playgroud)

c++ validation boost boost-program-options

21
推荐指数
1
解决办法
7090
查看次数