#include <iostream>
namespace implementation
{
namespace win
{
class A{};
}
namespace posix
{
class A{};
}
}
namespace ns
{
#ifdef _WIN32
using A = implementation::win::A;
#else
using A = implementation::posix::A;
#endif
// dump ns::A to any stream
template<class OStream>
OStream& operator << (OStream& os, const A& a)
{
os << "A"; // fake
return os;
}
}
int main()
{
ns::A a;
std::cout << a;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKbmFtZXNwYWNlIGltcGxlbWVudGF0aW9uCnsKCW5hbWVzcGFjZSB3aW4KCXsKCQljbGFzcyBBe307Cgl9CgluYW1lc3BhY2UgcG9zaXgKCXsKCQljbGFzcyBBe307Cgl9Cn0KCm5hbWVzcGFjZSBucwp7CgkjaWZkZWYgX1dJTjMyCgkJdXNpbmcgQSA9IGltcGxlbWVudGF0aW9uOjp3aW46OkE7CgkjZWxzZQoJCXVzaW5nIEEgPSBpbXBsZW1lbnRhdGlvbjo6cG9zaXg6OkE7CgkjZW5kaWYKCQoJLy8gZHVtcCBuczo6QSB0byBhbnkgc3RyZWFtCgl0ZW1wbGF0ZTxjbGFzcyBPU3RyZWFtPgoJT1N0cmVhbSYgb3BlcmF0b3IgPDwgKE9TdHJlYW0mIG9zLCBjb25zdCBBJiBhKQoJewoJCW9zIDw8ICJBIjsJLy8gZmFrZQoJCXJldHVybiBvczsKCX0KfQoKaW50IG1haW4oKSAKewoJbnM6OkEgYTsKCXN0ZDo6Y291dCA8PCBhOwoJcmV0dXJuIDA7Cn0=
prog.cpp: In function 'int main()':
prog.cpp:35:15: error: cannot bind 'std::ostream {aka std::basic_ostream<char>}' lvalue to 'std::basic_ostream<char>&&'
std::cout << a;
^
In file included from /usr/include/c++/4.9/iostream:39:0,
from prog.cpp:1:
/usr/include/c++/4.9/ostream:602:5: note: initializing argument 1 of 'std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&&, const _Tp&) [with _CharT = char; _Traits = std::char_traits<char>; _Tp = implementation::posix::A]'
operator<<(basic_ostream<_CharT, _Traits>&& __os, const _Tp& __x)
^