Skip to content

Instantly share code, notes, and snippets.

@meshell
Last active February 22, 2016 22:09
Show Gist options
  • Save meshell/d4ba4af7749a25a1351b to your computer and use it in GitHub Desktop.
Save meshell/d4ba4af7749a25a1351b to your computer and use it in GitHub Desktop.
#include <type_traits>
template <class T>
void swap(T& a, T& b) {
static_assert(std::is_copy_constructible<T>::value,
"Swap requires copying");
static_assert(std::is_nothrow_move_constructible<T>::value
&& std::is_nothrow_move_assignable<T>::value,
"Swap may throw");
auto c = b;
b = a;
a = c;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment