Vladimir Prus writes:
I assume you mean that, for example
--foobar=10
explicitly provides a value of 'foobar', and
--foobar
Precisely.
provides some default value of 'foobar'. Something like that was actually supported, but it was somewhat messy. First of all, it requires two default values -- default value if the option is not provided at all, and value that is used when the option is provided, but without any explicit value. This is already nasty interface.
Would it not be that, if not given, vm.count("arg") == 0; and if it was given, vm["arg"] would either be user-specified, or a default? Something like this perhaps: desc.add_options() ("listen,l", po::value<int>()->optional_token()->default_value(5555), "listen on a port") ; ... bool do_listening = false; if (vm.count() != 0) { do_listening = true; listen_port = vm["listen"].as<int>(); }
Further, given
--foo -1
what is '-1'? Is it value to '--foo'? Or is it separate option?
I don't see the relationship here. In terms of GNU's optional_argument feature, the optional token must be appended with an '=', so that it is unambiguous. Your example above is therefore unambiguous: -1 is a separate option. -Bryan