Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2005-03-10 06:18:55


David Abrahams wrote:
> "Peter Dimov" <pdimov_at_[hidden]> writes:
>
>> I should have been more clear. You shouldn't attempt to fix the
>> output of a std::string in optional<>'s operator<<. The proper way
>> to make a std::string bi-directional is by defining appropriate
>> operator<< and operator>> overloads for std::string. As these
>> operators are already defined and are not bi-directional in the
>> general case, optional<std::string> should not attempt to provide
>> extra bi-directionality.
>
> Okay, I don't neccessarily disagree, but I don't agree yet either.
> Why?

When a type's operator<< is "broken", you can't fix it from the outside.

struct X
{
    std::string data;
};

ostream& operator<< ( ostream& os, X const & x )
{
    return os << x.data;
}

It is not reasonable to expect all types that rely on string::<< to fix it
to match your (arbitrary, I might add) convention.


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