Boost logo

Boost Users :

From: Bryan Green (bgreen_at_[hidden])
Date: 2007-07-18 16:46:44


Vladimir Prus writes:
>
> I assume you mean that, for example
>
> --foobar=10
>
> explicitly provides a value of 'foobar', and
>
> --foobar

Precisely.

> provides some default value of 'foobar'. Something like that was actually
> supported, but it was somewhat messy. First of all, it requires
> two default values -- default value if the option is not provided at
> all, and value that is used when the option is provided, but without any
> explicit value. This is already nasty interface.

Would it not be that, if not given, vm.count("arg") == 0; and if it was
given, vm["arg"] would either be user-specified, or a default?
Something like this perhaps:

desc.add_options()
    ("listen,l", po::value<int>()->optional_token()->default_value(5555),
    "listen on a port")
    ;
...
bool do_listening = false;
if (vm.count() != 0) {
    do_listening = true;
    listen_port = vm["listen"].as<int>();
}

> Further, given
>
> --foo -1
>
> what is '-1'? Is it value to '--foo'? Or is it separate option?

I don't see the relationship here. In terms of GNU's optional_argument
feature, the optional token must be appended with an '=', so that it is
unambiguous. Your example above is therefore unambiguous: -1 is a separate
option.

-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