Argument-dependent name lookup

A common pattern in the C++ Standard Library is to declare overloaded operators that will be found in this manner.

For example, this simple Hello World program would not compile if it weren't for ADL: Using << is equivalent to calling operator<< without the std:: qualifier.

However, in this case, the overload of operator<< that works for string is in the std namespace, so ADL is required for it to be used.

However, consider that e.g. the const char * overloaded operator<< is a non-member function in the std namespace and, thus, requires ADL for a correct lookup: The std namespace overloaded non-member operator<< function to handle strings is another example: As Koenig points out in a personal note,[2] without ADL the compiler would indicate an error stating it could not find operator<< as the statement doesn't explicitly specify that it is found in the std namespace.

For example, the C++ standard library makes extensive use of unqualified calls to std::swap to swap two values.