Advertisement
Advanced C++, Namespaces

What is argument-dependent lookup (ADL)?

Short answer

ADL (Koenig lookup) means that when calling an unqualified function, the compiler also searches the namespaces of the argument types for matching functions.

Save C++ mock interview
Advertisement
AModel 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.
Likely follow-ups
  • Why does ADL exist? | How does it enable customization points like swap?
Related topics