Is the following C ++ code code the following piece of code?
#include <sstream> class Foo; std::ostream& operator<<(std::ostream& str, Foo x); // (A) namespace test { class Message { public: std::ostringstream str; }; template<typename T> Message& operator<<(Message& m, T& t) { using ::operator<<; m.str << t; return m; } } namespace detail { class Class { public: int i; Class() : i(5) {} }; } std::ostream& operator<<(std::ostream& str, detail::Class& myClass) { // (B) return str << myClass.i; } int main() { test::Message m; detail::Class c; m << c; }
According to http://goo.gl/NkPNau, GCC compiles this remark, while Clang does not find operator<< (B).
In case you are wondering: this is the code that GTest uses with a custom operator<< for std::set to print messages with a good message. We could not figure out how to make it work with someone else besides placing operator<< (B) in the std namespace (yes, I know ...).
source share