Boost logo

Boost Users :

Subject: Re: [Boost-users] RES: How do I print a standard pair?
From: Nathan Ridge (zeratul976_at_[hidden])
Date: 2011-09-26 14:31:10


> > It's up to the
> > developer implement how all other types will print to the output. See full
> > rationale and details in Stroustrup, Bjarne TCPPPL 3rd Edition - 21.2.2
> > Output of Built In Types.
> >
> > In short, you'll have to define a global operator<< for type std::pair<T,
> > U>:
> >
> > template<typename CharType, typename T, typename U>
> > std::basic_ostream<CharType>& operator<< (std::basic_ostream<CharType>& o,
> > std::pair<T, U> mypair)
> > {
> > return o << "This is my way of printing a pair: first: " <<
> > mypair.first << " and second: " << mypair.second;
> > }
>
> This is strictly forbidden by the standard AFAIK.
>
> Chris

It's forbidden if the overload is placed inside namespace std. Placing it in
a different namespace (including the global namespace) is perfectly OK,
AFAIK.

Nate
                                               


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net