
26 Sep
2011
26 Sep
'11
12:31 p.m.
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