samedi 24 janvier 2015

How does "using std::swap" enable ADL?

In What is the copy-and-swap idiom this example is shown:



friend void swap(dumb_array& first, dumb_array& second) // nothrow
{
// enable ADL (not necessary in our case, but good practice)
using std::swap;

// by swapping the members of two classes,
// the two classes are effectively swapped
swap(first.mSize, second.mSize);
swap(first.mArray, second.mArray);
}


How exactly does using std::swap enable ADL? ADL only requires an unqualified name. The only benefits I see for using std::swap is that since std::swap is a function template you can use a template argument list in the call (swap<int, int>(..)).


If that is not the case then what is using std::swap for?


Aucun commentaire:

Enregistrer un commentaire