Boost logo

Boost :

Subject: Re: [boost] Boost.Convert+Boost.Parameter
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-03-03 17:15:23


AMDG

Emil Dotchevski wrote:
> On Tue, Mar 3, 2009 at 1:26 PM, Steven Watanabe <watanabesj_at_[hidden]> wrote:
>
>> AMDG
>> Emil Dotchevski wrote:
>>
>>> 2) convert<std::string> necessarily returns std::string (I think it's
>>> important user-defined conversions to have the freedom to return char
>>> const *. Many interfaces that take strings are commonly overloaded for
>>> std::string and char const * for efficiency reasons.)
>>>
>> How common is this going to be in reality? Won't returning
>> const char* usually introduce problems with memory management?
>>
>
> I think that whether this is common or not is not important, my point
> is that it is a valuable optimization technique.
>

I don't think it is. It's too fragile. Functions
taking const char* arguments don't have the same problems.

> If conversion of objects of type foo to string is for some reason
> critical for performance, you can have foo contain a std::string and
> make its to-string overload return a char const *, through
> std::string::c_str().

which will work fine, until some generic code converts a temporary
to a string.

> Even if I wanted to-string to return std::string
> const &, convert<std::string> won't work.
>

In Christ,
Steven Watanabe


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