Boost logo

Boost :

Subject: Re: [boost] Formal Review Request: Boost.String.Convert
From: Emil Dotchevski (emildotchevski_at_[hidden])
Date: 2009-02-18 18:36:38


On Wed, Feb 18, 2009 at 3:10 PM, Andrey Semashev
<andrey.semashev_at_[hidden]> wrote:
> Emil Dotchevski wrote:
>
>>>>>> You can define template operator<<
>>>>>
>>>>> How is that?
>>>>
>>>> What do you mean how? You just define a template operator<< and the
>>>> library-supplied to_string/to_wstring templates will bind to it,
>>>> assuming the user's calls to_string or to_wstring doesn't bind to a
>>>> better overload of to_string/to_wstring.
>>>
>>> Which of the to_string/to_wstring functions should I call from the
>>> operator<< template?
>>
>> If all you want is to implement operator<< template in terms of
>> to_string/to_wstring, you won't have to do that because the library
>> will do it for you. That is, if I give you a foo overload of to_string
>> only, but you want to use operator<< for foo, all you'd have to do is
>> include the appropriate header from the library and foo.hpp, and then
>> you can call operator<< as needed, which in this case will forward
>> your call to to_string.
>
> I'm confused. So, the users will have to specify to_string overloads instead
> of streaming operators?

No. The users will be able to pick what they provide, and whether it
is a template or not; the library will provide the rest.

>>> It looks like you suggest that the library should implement wide
>>> streaming
>>> capability for all classes that it can reach (i.e. those have the narrow
>>> operator<<). Somehow, I don't quite like that kind of a "helping hand". I
>>> suspect it may introduce problems with efficiency, as it will have to
>>> unnecessarily transcode strings.
>>
>> If this inefficiency is a problem, it can be easily addressed by
>> introducing the appropriate optimal overloads. If not, you're arguing
>> premature optimization.
>
> That's right, overloads for all character types, which is the duplication
> I'm against.

Overloads for all character types can be provided through template
operator<< overload. The whole point of overload resolution is that
overloads can be as specific or as generic as needed, without the
caller having to know about it.

Apropos, one of the reasons why I dislike the convert<string> syntax
is that it unnecessarily demands that the call binds to a template.

Emil Dotchevski
Reverge Studios, Inc.
http://www.revergestudios.com/reblog/index.php?n=ReCode


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