The behavior of this function template is equivalent to:
1 2 3 4
| template <class T>void swap ( T& a, T& b ){ T c(a); a=b; b=c;}
|
Notice how this function involves a copy construction and two assignment operations, which may not be the most efficient way of swapping the contents of classes that store large quantities of data, since each of these operations generally operate in linear time on their size.
Large data types can provide an overloaded version of this function optimizing its performance. Notably, all
standard containers specialize it in such a way that only a few internal pointers are swapped instead of their entire contents, making them operate in constant time.