2 ms·
`swap` uses `move` to enable swapping objects that can only be moved but not copied (e.g., std::unique_ptr<T>). Note that this swap implementation is meant to b
by pbsd 11y ago
`swap` uses `move` to enable swapping objects that can only be moved but not copied (e.g., std::unique_ptr<T>). Note that this swap implementation is meant to be generic---types may implement their own specific `swap` that performs no copies or moves whatsoever. Example:
namespace NS {
struct S {
friend void swap(S& a, S& b) {
// do something interesting here
}
};
}
// later..
template<typename T>
void f(T& a, T& b) {
using std::swap;
swap(a, b); // calls NS::swap(a, b) if T = NS::S
}