Boost logo

Boost :

From: Martin Bonner (martin.bonner_at_[hidden])
Date: 2005-03-07 04:42:30


----Original Message----
From: Gennadiy Rozental [mailto:gennadiy.rozental_at_[hidden]]
Sent: 07 March 2005 07:18
To: boost_at_[hidden]
Subject: [boost] [optional]output

> Hi,
>
> Maybe it's something that I missed, but why optional doesn't define
> output operator something like this:
>
> template<typename T>
> inline std::ostream&
> operator<<( std::ostream& ostr, optional<T> const& v )
> {
> if( v )
> ostr << *v;
> return ostr;
> }

I don't think optional should define an output operator at all. There are
too many possibly useful definitions. For example:

template<typename T>
inline std::ostream&
operator<<( std::ostream& ostr, optional<T> const& v )
{
    if( v )
    {
        ostr << true << ' ' << *v;
    }
    else
    {
        ostr << false;
    }
    return ostr;
}

-- 
Martin Bonner
Martin.Bonner_at_[hidden]
Pi Technology, Milton Hall, Ely Road, Milton, Cambridge, CB4 6WZ,
ENGLAND Tel: +44 (0)1223 441434

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