Boost logo

Boost Users :

From: Ian McCulloch (ianmcc_at_[hidden])
Date: 2006-12-12 23:46:20


Edward Z. Yang wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> I'm using program_options in a few programs that I'm doing, and I'd like
> to clarify what's going on at certain points.
>
> vm.count("key") appears to tell us the number of times a flag is
> specified, but the documentation here:
> <http://www.boost.org/doc/html/variables_map.html> doesn't seem to say
> anything about it. Where is it specified? Does abstract_variables_map
> actually inherit off of std map? Why don't we use !vm["key"].empty()
> instead? (slightly more verbose, but it's clearer about what it's doing).

This catches me out too, IMHO it is the most annoying aspect of an otherwise
great library. The variables map is an ordinary map, not a multimap, so
the count() only ever returns 1 or zero. Instead, multiple occurances of a
flag are specified by using a parameter of type std::vector<T>, so it
should be vm["key"].as<std::vector<T> >().size().

> The vm["term"].as<int>() template seems to combust spectacularly (as in
> cause a stack dump) when it turns out that vm["term"] doesn't actually
> exist. This doesn't seem very robust, and according to the
> documentation, an exception ought to be thrown. Am I just
> misunderstanding the docs?

I don't know about that one.

> What is the preferred method determining that no parameters were passed?
> I'm currently using argc == 1, which seems a bit hacky, and doesn't
> catch errant parameters.

Nor that one.

Cheers,
Ian


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