LWG Issue 2148: Hashing Enums

llvm-svn: 189831
Cr-Mirrored-From: sso://chromium.googlesource.com/_direct/external/github.com/llvm/llvm-project
Cr-Mirrored-Commit: 5155a569d184fb2648000bb2a2bde843bf300961
diff --git a/include/functional b/include/functional
index 1486a8e..fdb8e0f 100644
--- a/include/functional
+++ b/include/functional
@@ -2399,6 +2399,22 @@
     }
 };
 
+#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