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:
Marshall Clow
2013-09-03 17:55:32 +00:00
parent 1b5f3adcef
commit 9e613ca1b3
4 changed files with 104 additions and 1 deletions

View File

@@ -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