|
Boost : |
Subject: Re: [boost] Formal Review Request: Boost.String.Convert
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2009-02-18 16:03:41
Emil Dotchevski wrote:
> What I had in mind is that foo could implement to_string or to_wstring
> or both, and the library would supply generic overloads of
> to_string/to_wstring that would kick-in as needed. So, if I give you:
>
> std::string to_string( foo const & );
>
> then after you include foo.hpp and presumably boost/to_string.hpp, you can say
>
> foo x;
> std::wstring s=to_wstring(x);
>
> which would bind to boost::to_wstring (since there isn't a foo
> overload of to_wstring) which would do the conversion using the foo
> to_string overload.
Hmm... No, that doesn't look very useful either. My common practice of
operator<< definition is to define it as a template on the character
type, like this:
struct foo
{
template< typename CharT, typename TraitsT >
friend std::basic_ostream< CharT, TraitsT >&
operator<< (
std::basic_ostream< CharT, TraitsT >& strm,
foo const& x);
};
This allows to find the operator via ADL and have the common
implementation for any character type under the same name (operator<< in
this case).
I would expect the same level of flexibility from the proposed library.
Even more, I'd like it to use the operators if they are already defined
for the class.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk