Last active
August 29, 2015 14:07
-
-
Save dirvine/b1dcb711455fda3a4274 to your computer and use it in GitHub Desktop.
c++11_regular
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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