Boost logo

Boost :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2004-03-19 10:00:09


Thorsten Ottosen wrote:

> Could you explain?
> ---------
> writing
>
> const char* help = "help";
>
> would enable the compiler to catch spell-errors in the constants.

I see. I did not run into problems with hardcoded strings yet, so did not
consider this important.

> > 2. each line should have a comment about what it does.
>
> Actually, that would duplicate explanations that are already in the
> tutorial.
> Don't you think?
> ------------------
> I'm in doubt :-) I do like comments because they can easily be compared to
> code; when you're reading
> block text, it can be harder to focus on where the comments apply.

Ok, I'll note your opinion.

> > 9. Could this way of specifying composing()/default_value() be of any use
> >
> > option += option<int>( "xx", "xx msg" ), option_with_default<int>( ""yy",
> > var_name, 0, "yy msg" ),
> > option_with_compose< vector<string> >( "zz", "zz msg" );
> >
> > ?.
>
> I think that syntantically, it requires the same number (or even larger)
> number of characters. Besides, what if you want to specified both default
> value and 'composing' flags? options_with_default_and_compose looks too
> long.
> ---------
>
> yeah, then what about
>
> option += option<int>( ""xx"", var_name, compose_flag | other_flag )
>
> ? That use of flags might be more idiomatic.

The problem here is different: some modifiers, like "default_value" and
"notifier" have a parameter, so they can't be just bitwise-ored. So, even if
"compose_flag" can be used as you suggest, there will be two syntaxes from
specifying modifiers:

    option<int>( ""xx"", var_name, compose_flag | other_flag ).
             notifier(print_values)

and I'd prefer just one syntax -- for consistency.

> > 10. This
> >
> > po::options_description cmdline_options;
> > cmdline_options.add(generic).add(config).add(hidden);
> >
> > might be
> >
> > po::options_description cmdline_options;
> > cmdline_options += generic, config, hidden;
> >
> > ?
>
> Interesting! I just found some-years-old code of mine which provides
> support for such initialization. It worked for vectors, like:
>
> v << 1, 2, 3, 4, 5, 6;
>
> but can be easily used for +=, too. I'm just not sure this is justified
> here.
> --------------
>
> Actually, one could choose to use my assign library if it gets accepted.

I did not know about it. I think I'll take a look

> You would probably only have to write one overload of operator+= so
> it can recognize your types. There is also another use. Let's say you
> make a function add():
>
> program_options po;
>
> add( po )( "xx", df, "xx msg)(...)(...)
>
> that should work ou of the box with different tuplesizes. Making add() and
> operator+()
> is about the same amount of work, probably 3-4 four lines each.

That's handy!

- Volodya


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk