Boost logo

Boost :

Subject: Re: [boost] [program_options] Some methods take const char*, others take std::string
From: Vladimir Prus (vladimir_at_[hidden])
Date: 2011-08-10 16:13:01


Gabriel Redner wrote:

> Hi all,
>
> Some methods in program_options accept const char*s (e.g.
> option_description constructor), while others take const std::string&s
> (e.g. option_description::key). This makes no difference to the user
> if he is passing string literals, but becomes annoying if he wants to
> pass strings, or expressions which return strings. Of course he can
> put (...).c_str() everywhere, but this is ugly and unnecessary, since
> program_options just takes its parameters and shoves them into string
> variables anyways. Since changing the parameter types to const
> std::string& should not break existing code, I do not see a downside
> to doing so (plus, it would allow me to get rid of .c_str()s
> everywhere :-).
>
> Does it seem reasonable for program_options public APIs to accept
> std::strings instead of const char*s? If so I would be happy to do
> the legwork and submit a patch.

This is: https://svn.boost.org/trac/boost/ticket/4142

The point is that using std::string would impose code size overhead when
you pass string literal. I would be happy to see a patch, but such a
patch would have to retain overloads taking const char*.

Thanks,

-- 
Vladimir Prus
CodeSourcery / Mentor Graphics
+7 (812) 677-68-40

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