Skip to content

Instantly share code, notes, and snippets.

@dirvine
Last active August 29, 2015 14:07
Show Gist options
  • Save dirvine/b1dcb711455fda3a4274 to your computer and use it in GitHub Desktop.
Save dirvine/b1dcb711455fda3a4274 to your computer and use it in GitHub Desktop.
c++11_regular
// from Eric Niebler's talk from C++Now 2014 https://www.youtube.com/watch?v=zgOF4NrQllo
class RegularCxx11 {
RegularCxx11();
RegularCxx11(RegularCxx11 const &);
RegularCxx11(RegularCxx11 &&) noexcept;
~RegularCxx11();
RegularCxx11 & operator=(RegularCxx11 const &);
RegularCxx11 & operator=(RegularCxx11 &&) noexcept;
friend bool operator==(RegularCxx11 const &, RegularCxx11 const &);
friend bool operator!=(RegularCxx11 const &, RegularCxx11 const &);
friend bool operator<(RegularCxx11 const &, RegularCxx11 const &);
// no swap any more as we have noexcept move types so std::swap is fine to use
};
// if using in associative containers ? danger danger - can you implement this?
namespace std {
template<> struct hash<RegularCxx11>;
}
// ###########check
template<typename T>
struct is_regular
: std::integral_constant< bool,
std::is_default_constructible<T>::value &&
std::is_copy_constructible<T>::value &&
std::is_move_constructible<T>::value &&
std::is_copy_assignable<T>::value &&
std::is_move_assignable<T>::value > {};
struct T {};
static_assert(is_regular<T>::value, "huh?");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment