LWG Issue 2148: Hashing Enums
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@189831 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -2399,6 +2399,22 @@ struct _LIBCPP_TYPE_VIS_ONLY hash<long double>
|
||||
}
|
||||
};
|
||||
|
||||
#if _LIBCPP_STD_VER > 11
|
||||
template <class _Tp>
|
||||
struct _LIBCPP_TYPE_VIS_ONLY hash
|
||||
: public unary_function<_Tp, size_t>
|
||||
{
|
||||
static_assert(is_enum<_Tp>::value, "This hash only works for enumeration types");
|
||||
|
||||
_LIBCPP_INLINE_VISIBILITY
|
||||
size_t operator()(_Tp __v) const _NOEXCEPT
|
||||
{
|
||||
typedef typename underlying_type<_Tp>::type type;
|
||||
return hash<type>{}(static_cast<type>(__v));
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
// struct hash<T*> in <memory>
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
Reference in New Issue
Block a user