Boost logo

Boost Users :

From: Nathan LeZotte (lezotten_at_[hidden])
Date: 2006-02-14 00:34:43


On 2/13/06, Edward Diener <eddielee_at_[hidden]> wrote:
> Sohail Somani wrote:
> >> -----Original Message-----
> >> Edward Diener
> >> Why not have the parameter as:
> >>
> >> "--first=11,12"
> >>
> >> instead of trying to create more than one parameter with the same
> >> parameter name.
> >>
> >> Personally because of the type of solution I suggested, which is
> >> probably the way most uses of such a multi-value value
> >> parameter would
> >> look like, with possibly a different separator than a comma, I do not
> >> think a parameter library should have to cater to the same parameter
> >> name more than once on the command line.
> >
> > What about parameters like -I for gcc? Utilities can add -I's to the
> > command line. It would be an added headache to synchronize all these
> > tools to eventually come up with a -I arg1,arg2,...
>
> You are right about that. I think, then, you have to take this up with
> the creator of the program_options library.

I believe this functionality is built right in to the program_options
library if you use value< vector<T> > as your value semantic. There
is an example of this in the "Getting Started" section of the
program_options documentation
(http://www.boost.org/doc/html/program_options/tutorial.html). Here
is a small snippet of what's in the docs:

int opt;
po::options_description desc("Allowed options");
desc.add_options()
    ("help", "produce help message")
    ("optimization", po::value<int>(&opt)->default_value(10),
  "optimization level")
    ("include-path,I", po::value< vector<string> >(),
  "include path")
    ("input-file", po::value< vector<string> >(), "input file")
;

The tutorial section in the docs isn't 100% clear about what this
does, but I'm pretty sure if you have a command-line with (for
example) multiple --include-path options, then push_back is called on
a vector in the variables_map for each instance of the --include-path
option. There is probably a different section in the docs that
describes this in detail, but I'm not sure where it is.

Hope this helps,

Nathan.


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