|
Boost : |
From: Vladimir Prus (ghost_at_[hidden])
Date: 2003-05-07 01:05:59
Hi Neal,
Neal D. Becker wrote:
> It looks like when setting variables using
> options_description.add_options(), bool variables are set to false if no
> option is actually given, but variables of other types, such as int, are
> not initialized if not given on the command line? This is my understanding
> based on the program behaviour - is this correct?
Yes, this is so. The behaviour is due to code in
parameter_creator<bool>::operator(), in options_description.tcc:211
Two things are done:
- the default value of bool parameters is "0"
- the value when options is present withouth a value (like in "--switch") is
"1"
The rationale is that for boolean values default is quite obvious, and test
for boolean option can be as simple as
if (vm["switch"].as<bool>())
For ints, there's no such obvious default, so if default value is desired it
should be specified manually.
I've updated the docs to specify the semantics.
Thanks,
Volodya
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk