From a3b20b248e2e26e41bd03edb8cf2e024bcf35ec8 Mon Sep 17 00:00:00 2001 From: Rochet2 Date: Mon, 1 Feb 2016 21:37:25 +0200 Subject: [PATCH] Hash enums with underlying type instead of int Thanks to jameyboor --- BindingMap.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/BindingMap.h b/BindingMap.h index de0a1bf..1bc0ce7 100644 --- a/BindingMap.h +++ b/BindingMap.h @@ -274,18 +274,23 @@ public: return seed; } - template + template ::value>::type* = nullptr> static inline result_type hash(T const & t) { - // Possibly convert int to std::underlying_type or find another way - using Hasher = typename std::conditional< std::is_enum::value, std::hash, std::hash >::type; - return Hasher()(t); + return std::hash::type>()(t); + } + + template ::value>::type* = nullptr> + static inline result_type hash(T const & t) + { + return std::hash()(t); } private: template static inline void _hash_combine(result_type& seed, T const & v) { + // from http://www.boost.org/doc/libs/1_40_0/boost/functional/hash/hash.hpp seed ^= hash(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2); }