Change HashCompatible trait to a variable template

This commit is contained in:
Maxime Coste 2017-08-14 11:54:38 +07:00
parent 9329fc99d2
commit b58f72315c
3 changed files with 6 additions and 8 deletions

View File

@ -61,12 +61,10 @@ struct Hash
// Traits specifying if two types have compatible hashing, that is,
// if lhs == rhs => hash_value(lhs) == hash_value(rhs)
template<typename Lhs, typename Rhs>
struct HashCompatible : std::false_type {};
constexpr bool HashCompatible = false;
template<typename T> struct HashCompatible<T, T> : std::true_type {};
template<typename Lhs, typename Rhs>
constexpr bool IsHashCompatible = HashCompatible<Lhs, Rhs>::value;
template<typename T>
constexpr bool HashCompatible<T, T> = true;
}

View File

@ -156,7 +156,7 @@ struct HashMap
template<typename KeyType>
using EnableIfHashCompatible = std::enable_if_t<
IsHashCompatible<Key, std::decay_t<KeyType>>
HashCompatible<Key, std::decay_t<KeyType>>
>;
template<typename KeyType, typename = EnableIfHashCompatible<KeyType>>

View File

@ -256,8 +256,8 @@ private:
static_assert(std::is_trivial<StringView>::value, "");
template<> struct HashCompatible<String, StringView> : std::true_type {};
template<> struct HashCompatible<StringView, String> : std::true_type {};
template<> constexpr bool HashCompatible<String, StringView> = true;
template<> constexpr bool HashCompatible<StringView, String> = true;
inline String::String(StringView str) : String{str.begin(), str.length()} {}