Boost logo

Boost :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2005-02-08 03:08:26

Lars Iversen wrote:

> I assume that the constructor for
> program_options::basic_command_line_parser (and function
> program_options::parse_command_line) in
> boost/boost/boost/program_options/parsers.hpp revision 1.11 could accept
> pointers to const char instead of non-const pointers?!

There's a problem. The standard says that the two-parameter 'main' has this

  int main(int ac, char* av[])

Note: there's no const there. If I make the above functions accept const
parameters, users will have to do manual conversions. Try this:

  void do_it(const char* av[]) {}

  int main(int ac, char* av[])
      return 0;

It won't compile:

   argv.cpp:8: error: invalid conversion from `char**' to `const char**'

Such convertion is now allowed without explicit cast because it can be used
to break const-correctness in a very subtle way, and:

- many users will be confused by this error
- requiring manual cast for parsing argv is overkill

I don't have better solution than using non-const argument to
parse_command_line. Maybe, this should go to FAQ?

- Volodya

Boost list run by bdawes at, gregod at, cpdaniel at, john at