Boost logo

Boost Users :

From: Bryan Green (bgreen_at_[hidden])
Date: 2007-06-12 15:32:11


"Chris Weed" writes:
> On 6/12/07, Bryan Green <bgreen_at_[hidden]> wrote:
> > Hello,
> >
> > Is there a mechanism in boost::program_options for supporting optional
> > arguments? If not, is there a suggested program_options-based alternative?
> >
>
> What exactly do you mean by optional arguments?
> Do you mean like this?
> http://www.boost.org/doc/html/program_options/howto.html#id1593176
>
> Chris

The quotation in my email goes into exact detail - basically, I'm looking
for functionality equivalent to GNU getopt_long, which has an
"optional_argument" specifier. It is a method for optionally associating a
value with a particular option.
For example, if I specify a getopt_long parameter to enable listening on a
socket:

 {"listen",optional_argument,NULL,'l'}

Then, on the command line,
 '--listen' means to enable listening, using a default port number.
 '--listen=5000' means enable listening, using port number 5000.

The only way I see to accomplish this with program_options is to make a
second option called "listen_port".

I've been playing with 'po::value<uint16_t>()->zero_tokens()', but it does
not work as I had hoped. I don't really understand how 'zero_tokens' is
supposed to work, frankly. It seems to be useful when the value type is
'bool', but I don't understand its use for non-boolean types.

-Bryan


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net