Boost logo

Boost :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2004-11-30 08:33:52


Hi Tony,

> Can anyone tell me the precise definition or behaviour of the order of
> execution of the user supplied functions to handle command line options
> defined in boost program options library.
...

>
> For example, my option menu was defined as follows
>
> boost::program_options::options_description menu("Valid Options");
> menu.add_options()
> ("help,h", "Display this menu.")
> ("time,t", boost::program_options::value<double>(&time_arg_value)
> -> notifier(&my_function1) "Description of option")
> ("memory,m",
> boost::program_options::value<double>(&memory_arg_value) ->
> notifier(&my_function2), "Description of option")
> ("file,f", boost::program_options::value<std::vector<std::string>
> >(&file_arg_value) -> composing() ->
> notifier(&file_arg_handler<std::vector<std::string> >), "Something");
>
> boost::program_options::variables_map menu_map;
>
> boost::program_options::store(boost::program_options::
> parse_command_line(argc, argv, menu), menu_map);
> boost::program_options::notify(menu_map);

This example misses one important piece -- the call to "nofity" function. As
mentioned in

   http://boost.org/doc/html/program_options/overview.html#id548990

the user-provided notifiers are called by the "program_options::notify"
function. The order of invocation is independed of the order on the command
line, it's just lexicographical order of the option names.

> Question is: Will the following two calls to the program result in
> different behaviour?
>
> >./Test --time 76 --memory 97 --help
> >./Test --memory 97 --time 76 --help

No.

> I want my two functions for time and memory be independent of each
> other but I would like the function be called in the same order as the
> options specified on the command line. Sure I can test but can someone
> guarantee that what I discovered will remain valid in the future
> release of the library.

Why do you need specific order?

> Another question: What will happen if this program was called on the
> command line with the following options.
>
> >./Test --file myfile1 --time 87 --file myfile2
>
> Will the file_arg_handler be called first with composed arguments and
> then time function (my_function1) or will the time function
> (my_function1) be called first and then the
> file_arg_handler function. Can I count on it that what happens will
> always happen in the future? Is there definitions for the order of
> execution guarantee by the library?

There's no guarantee at all. The idea is most of the time you don't need
specific order. If you describe your problem, I might offer more specific
help.

- Volodya


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