What is argument-dependent lookup (ADL) in C++?
Last updated
ADL (Koenig lookup): for an unqualified call, the compiler also searches the namespaces of the argument types.
It lets
std::cout << xfindoperator<<instd, and powers theusing std::swap; swap(a,b);idiom.It can pull in unintended overloads. Qualifying the call (
ns::f(x)) disables ADL.
- https://en.cppreference.com/cpp/language/adl
- https://tcs.rwth-aachen.de/docs/cpp/reference/en.cppreference.com/w/cpp/language/adl.html
- https://learn.microsoft.com/en-us/cpp/cpp/argument-dependent-name-koenig-lookup-on-functions?view=msvc-170
- https://learn.microsoft.com/et-ee/%20cpp/cpp/argument-dependent-name-koenig-lookup-on-functions?view=msvc-180
- https://quuxplusone.github.io/blog/2019/04/26/what-is-adl/
- https://www.modernescpp.com/index.php/argument-dependent-lookup-and-hidden-friends/
- https://medium.com/towardsdev/cpp-sentinels-adl-cpo-guide-8a8499c13720