The context in which swap( t, u ) and swap( u, t ) are evaluated shall ensure that a binary non-member function named “swap” is selected via overload resolution on a candidate set that includes: — the two swap function templates defined in <utility> and — the lookup set produced by argument-dependent lookup. |
any time the standard library performs a swap, it uses the equivalent of using std::swap; swap( t, u ); .Typical implementations either 1) Define a non-member swap in the enclosing namespace, which may forward to a member swap if access to non-public data members is required 2) Define a friend function in-class (this approach hides the class-specific swap from name lookup other than ADL) http://en.cppreference.com/w/cpp/concept/Swappable |
using std::swap; swap( t, u );
std::swap( t, u );
would force the compiler to consider only the swap in namespace std using std::swap;
before swap(t, u);
, why does this swap call the swap defined in the same namespace as the type? using declaration introduce std::swap to the same scope as swap(t, u), why not call the std::swap? does it mean ADL have priority over normal name lookup?
does it mean ADL have priority over normal name lookup? |