When using boost::program_options, how does one set the name of the argument?

后端 未结 6 1823
借酒劲吻你
借酒劲吻你 2021-02-01 18:02

When using boost::program_options, how do I set the name of an argument for boost::program_options::value<>()?

#include 

        
6条回答
  •  生来不讨喜
    2021-02-01 18:44

    daminetreg's answer works, but it can be a little verbose when used for lots of option entries. I just hacked together an overload for the value( T* v ) template to construct my value_sematics with an additional value_name: using

    template
    typed_value*
    value(T* v, const char * value_typename)
    {
        typed_value* r = new typed_value(v);
        r->value_name( value_typename );
    
        return r;        
    }
    

    you can create and add a new program_option like this:

    int width;
    desc.add_options()
        ("width", boost::program_options::value( &width, "NUM"),
         "Give width");
    

    (Note: this doesn't address all the other construction templates, especially not the default value() constructor that the OP wants to use)

提交回复
热议问题