Created
December 12, 2015 15:56
-
-
Save paosidufygthrj/9252c0281f7ea900efb1 to your computer and use it in GitHub Desktop.
hash に対応しているか判定するメタ関数
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
#include <type_traits> | |
#include <functional> | |
using namespace std; | |
template <typename T, typename Ignore = void> | |
struct has_hash { | |
static const bool value = false; | |
}; | |
template <typename T> | |
struct has_hash<T, typename enable_if<is_same<decltype(hash<T>()(T{})), std::size_t>::value>::type> { | |
static const bool value = true; | |
}; | |
enum class my_enum {}; | |
namespace std { | |
template <> struct hash<my_enum> { | |
size_t operator ()(my_enum) const { return 0; } | |
}; | |
} | |
int main() { | |
static_assert(has_hash<my_enum>::value, "need hash function."); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment