From 80485fb9631f3c0f9c18c64a78e3fad032d525fc Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 3 Jul 2022 20:29:28 +0300 Subject: [PATCH] Use the underlying type for hashing enums --- include/boost/container_hash/hash.hpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/include/boost/container_hash/hash.hpp b/include/boost/container_hash/hash.hpp index b4066b1..1e415a4 100644 --- a/include/boost/container_hash/hash.hpp +++ b/include/boost/container_hash/hash.hpp @@ -26,7 +26,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -38,6 +40,10 @@ #include #include +#if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS) +# include +#endif + #if !defined(BOOST_NO_CXX11_SMART_PTR) # include #endif @@ -163,7 +169,17 @@ namespace boost typename boost::enable_if_::value, std::size_t>::type hash_value( T v ) { - return static_cast( v ); +#if !defined(BOOST_NO_CXX11_HDR_TYPE_TRAITS) + + typedef typename std::underlying_type::type U; + +#else + + typedef typename boost::conditional< boost::is_signed::value, boost::make_signed, boost::make_unsigned >::type::type U; + +#endif + + return boost::hash_value( static_cast( v ) ); } // floating point types