I am having a problem with boost program_options (v1_49) in the case of an option defined as composing() and also implicit(). My intent is to implement a -D option similar to the way perl does, so that you can do -D or -Dname and use it multiple times. My options_description is:
( "debug,D",
bpo::value<vector<string> >()
->composing()
->implicit_value(vector<string>(1,"1")),
"Set debug level."
),
This seems to work OK in most cases, but whenever -D with no value appears on the command line, all earlier values are erased, e.g.:
$ ./a.out -D abc -D 255 -D xyz
variables_map["debug"] = {"abc", "255", "xyz"}
$ ./a.out -D -D 255 -D xyz
variables_map["debug"] = {"1", "255", "xyz"}
$ ./a.out -D abc -D -D xyz
variables_map["debug"] = {"1", "xyz"}
$ ./a.out -D abc -D 255 -D
variables_map["debug"] = {"1"}
I think I see why this happens, the implicit value {"1"} replaces the existing vector instead of adding to it. Is there something I can do to get this to work or is it a limitation of boost::program_options?