How does “using std::swap” enable ADL?

Just wanted to add why this idiom is used at all, which seemed like the spirit of the original question. This idiom is used within many std library classes where swap is implemented. From http://www.cplusplus.com/reference/algorithm/swap/: Many components of the standard library (within std) call swap in an unqualified manner to allow custom overloads for non-fundamental … Read more

what does `using std::swap` inside the body of a class method implementation mean?

This mechanism is normally used in templated code, i.e. template <typename Value> class Foo. Now the question is which swap to use. std::swap<Value> will work, but it might not be ideal. There’s a good chance that there’s a better overload of swap for type Value, but in which namespace would that be? It’s almost certainly … Read more

What is “Argument-Dependent Lookup” (aka ADL, or “Koenig Lookup”)?

Koenig Lookup, or Argument Dependent Lookup, describes how unqualified names are looked up by the compiler in C++. The C++11 standard ยง 3.4.2/1 states: When the postfix-expression in a function call (5.2.2) is an unqualified-id, other namespaces not considered during the usual unqualified lookup (3.4.1) may be searched, and in those namespaces, namespace-scope friend function … Read more