Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Boost program options detect whether default value was used

Tags:

boost

I'm using Boost program_options with an argument that has a ->default_value(). Is there any way to tell whether the value that results was specified by the user on the command line, or by the default value?

like image 471
Timmmm Avatar asked Feb 23 '18 13:02

Timmmm


1 Answers

There is a way - variable_value::defaulted():

  po::variables_map vm;
  try {
    po::store(po::parse_command_line(argc, argv, desc), vm);
  } catch (std::exception& e) {
    std::cerr << "error parsing command line: " << e.what() << "\n";
    return 1;
  }

  // Needed to set default arguments.
  po::notify(vm);

  if (vm["myparam"].defaulted())
     ...
like image 164
Timmmm Avatar answered Sep 22 '22 06:09

Timmmm