Boost logo

Boost Users :

From: Bryan Green (bgreen_at_[hidden])
Date: 2007-08-15 13:41:02


"Christian Henning" writes:
> Hi there, a while ago I was asking some questions about the short
> option feature. If I'm not mistaken a short option can only be one
> letter long. Is that correct to say?
>
> In my project I need more than this. So I started to just add the
> short names to the options list like I would do for all options. But
> in this case they would share the same variable. Like this:
>
> po::options_description settings( "" );
> settings.add_options()
> ( "input_1"
> , po::value< string >( &_input )
> ->default_value( "" )
> , "" )
> ( "i1"
> , po::value< string >( &_input )
> ->default_value( "" )
> , "" );
>
>
> Both options are pointing to the same variable. For some reasons this
> code works only for "input_1" and not for "i1". Why is that? If I use
> --i1="Hallo" the _input is empty.

That makes sense. The default value for 'input_1' is getting applied *after* the
provided 'i1' value is applied, so it overwrites the 'i1' value.

I'm not %100 sure, but you might get the right effect by initializing '_input' yourself
(or leaving it uninitialized), and remove the 'default_value' settings.
Then you can test the value of '_input' to see if it got set.
The only problem is the usage statement won't print what the default value is, but
is that something you want in this case?

-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