Boost logo

Boost :

Subject: Re: [boost] Formal Review Request: Boost.String.Convert
From: Christopher Jefferson (chris_at_[hidden])
Date: 2009-02-18 17:26:13


On 18 Feb 2009, at 22:16, Andrey Semashev wrote:

> Emil Dotchevski wrote:
>
>>> And what if I write my own class outer_bar that owns bar and also
>>> want to be
>>> ostreamable? I would have to duplicate my operator<< in order to
>>> call either
>>> to_string or to_wstring, wouldn't I?
>> No.
>> You can define template operator<<
>
> How is that?
>
>> or you can define non-template
>> std::string overload of operator<< only. The user would still be able
>> to call to_wstring, which will bind to a wstring overload if it's
>> available. If not, the generic to_wstring overload will call the
>> std::string operator<< overload, and then convert the result to
>> wstring.
>
> But I will lose generic ostreamability for my class then. Sorry, I
> just don't see any advantages for differently named functions.

I find differently named functions important for readability and
correctness, particularly in templated generic code.

Wouldn't it be easy to add 'to' and 'from' functions as simple
wrappers around 'convert', for those who want them?

Chris


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