Boost logo

Boost :

Subject: [boost] [program_options] custom validator overrides
From: Roger Martin (roger_at_[hidden])
Date: 2018-10-15 23:11:39


Hi,

The Custom Validators documentation
https://www.boost.org/doc/libs/1_68_0/doc/html/program_options/howto.html
shows

void validate(boost::any& v,
               const std::vector<std::string>& values,
               magic_number* target_type, int)
{

but the possible templates don't match; the last variable type is an
int; the key is matching this last type:

int goes with std::vector<T>*

long goes with T*

it also seems possible to hit the

 Â Â Â  void validate(boost::any& v,
 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  const std::vector<std::basic_string<charT> >& s,
 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  boost::optional<T>*,
 Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  int)
 Â Â Â  {

where it then calls for get_single_string and if you are trying for a
multitokens switch args, it'll throw " only takes a single argument".

which also varies if it was parsed by command_line_parser or
parse_config_file

command_line_parser: vector size can >= 1 up to number of switch args

parse_config_file: vector size ==1 no matter what the number of args are
on the input.  just one string with all switch args.

This was tested with 1.65 yet I don't see anything changing in
https://github.com/boostorg/program_options/blob/develop/include/boost/program_options/detail/value_semantic.hpp


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk