Why was argument dependent lookup (ADL) invented? Is it just so we can write cout << stuff
instead of std::operator<<(cout, stuff)
? If that is the case, why wasn't ADL limited to operators instead of all functions?
Could the introduction of ADL have been prevented if C++ had had some other way to do generic output of both built-in and user-defined types, for example a type-safe printf
via variadic templates?
ADL was invented to allow the Interface Principle:
The Interface Principle
For a class X, all functions, including free functions, that both
are logically part of X, because they form part of the interface of X.
Check out Herb Sutter's excellent Guru of the Week on the topic.