Why can't a function in a namespace see my operator<< defined globally?

Unqualified lookup goes up one level at a time and stops as soon as it finds something. It finds an operator<< within the anonymous namespace - the very one you are calling from - and stops dead right there.

Consider wrapping an element of the pair or the pair itself into a wrapper in your own namespace. Then you can define an operator<< to do whatever you want and have it picked up by ADL.


Is there a way to make this work without modifying the Container class?

Yes. You have to put the operator<< inside the namespace.

DEMO here.

Search for operator << is only happening within the namespace container.value is defined in. Related Post.