ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> boost
boost
Re: [boost] program options - default values question
by Vladimir Prus other posts by this author
May 7 2003 6:05AM messages near this date
[boost] program options - default values question | [boost] Boost implementation of the Library TR?
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

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Thread:
Neal D. Becker
Vladimir Prus
Neal D. Becker
Vladimir Prus

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved