Subject: Re: [boost] [program_options]
From: Phil Richards (news_at_[hidden])
Date: 2010-03-06 14:03:49
On Sat, 2010-03-06 at 13:22 +0100, vicente.botet wrote:
[In reply to my comment of:]
> > I can't see how taking a std::string const& as an argument has any
> > detrimental effect on conversions or code bloat. The std::string
> > version of set_name would just remove the first line of the function
> > (creating the temporary "name"), and use _name throughout the function
> > body.
> > Description is even simpler: it just uses the const char* argument as a
> > parameter to a std::string constructor. Accepting a std::string const&
> > instead of a const char* will have minimal overheads (possibly one extra
> > temporary string creation).
> > But maybe I'm missing something obvious?
> The fact that currently the implementation use a temporary string doesn't means that we can not change the implementation.
Indeed - and any change to using a const std::string& rather than const
char* interface will also be backward compatible.
> What about having both overloads? const char * is the best for literals,
> while string cont& is the best for strings variables.
My point was that there is no need for having both overloads: it doesn't
(as far as I can see) provide any benefit having an "efficient" const
char* call - there isn't any (obvious) extra conversions or code bloat
by providing just the const std::string& interface because internally
the const char* are immediately converted to std::string.
But, as I said before, I might be missing something.
-- Phil Richards, <news_at_[hidden]>