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?
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())
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With