How to add std::swap for my template class? [duplicate]
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: how to provide a swap function for my class? There are some questions about this, but a lot of contradictions (person A giving solution A' with many upvotes with person B saying it's UB) or "only works if the compiler supports ADL" is answered. So, say I have the following template (container) class: template<typename T> class C { // ... void swap(C<T>& y) throw(); // C x; x.swap(y); } then what is the correct