What is the difference between default_value and implicit_value in boost::program_options?

default_value() is the value that will be put in the variables_map if the user didn’t specify another value: ./a.out # implies width=75 if that’s the default_value for width ./a.out –width=80 # default_value not used implicit_value() is the value that will be used if the user specifies the option but without an adjacent value. ./a.out –width … Read more

Vector arguments in Boost Program Options

This is a late answer but I hope it helps someone. You could easily use the same technique in item #1, except you need to add another validation on the number of items in your vector: from rcollyer’s example: namespace po = boost::program_options; po::option_descriptions desc(“”); desc.add_options() (“opt”, po::value<std::vector<int> >()->multitoken(), “description”); po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), … Read more

Required and Optional Arguments Using Boost Library Program Options

I’ve run into this issue myself. The key to a solution is that the function po::store populates the variables_map while po::notify raises any errors encountered, so vm can be used prior to any notifications being sent. So, as per Tim, set each option to required, as desired, but run po::notify(vm) after you’ve dealt with the … Read more

tech