Back to results for “Namespaces”
C++ › Namespaces

What is argument-dependent lookup (ADL)?

Advanced

Answer

ADL (Koenig lookup) means that when calling an unqualified function, the compiler also searches the namespaces of the argument types for matching functions. This lets operators and functions like swap or begin be found in the type's own namespace without qualification, which is why 'using std::swap; swap(a,b);' enables customized swaps.
namespace lib { struct T{}; void f(T); }
lib::T t;
f(t);   // ADL finds lib::f
Real-world example ADL lets user-defined operator<< in a type's namespace be found by generic streaming code.

Common follow-ups: Why does ADL exist? | How does it enable customization points like swap?