Boost logo

Boost Users :

Subject: [Boost-users] program_options: one-of-set option format
From: Ivan Godard (igodard_at_[hidden])
Date: 2008-10-10 08:52:45

The boost::program_options library appears to lack the capability for
one-of-set options, i.e. one of -a, -b, or -c, but not more than one,
returned as an enumeration value in a common result for all the options.

Currently I have a function:
    template<typename T>
  options_description& oneOf(options_description& od,
std::vector<std::string>& names, T& t);
which adds options for all the names to "od", with notifiers that update
"t" with the "T" enumeration value corresponding to the particular
option that the parser finds present using the ordinal position in
"names" as a value. However, this is somewhat unsatisfying because
detected errors (missing or too many choices) don't feed into the
program_options reporting system. It also does not fit with the rather
nice syntax used by the program_options library for option declarations.

I also looked at using an external parser as supported by
program_options, but this seems low-level overkill - you get a raw
string to parse, but none of the nice facilities for abbreviation, long
or short forms, etc. are usable.

Lastly, I considered adding the capability as a native feature of
program_options, but while the library is reasonably clean it doesn't
seem to be designed to support any inter-option linkages as required for
reporting the result and verifying that only one of the set was present.

So the question for this list: am I reinventing the wheel here and this
oneOf capability already exists somewhere? If not, is there a better
approach than my present purely extra-library solution?

Thank you


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at