diff --git a/include/boost/container_hash/hash.hpp b/include/boost/container_hash/hash.hpp index da346a3..b4066b1 100644 --- a/include/boost/container_hash/hash.hpp +++ b/include/boost/container_hash/hash.hpp @@ -77,11 +77,12 @@ namespace boost { template sizeof(std::size_t)), + bool is_unsigned = boost::is_unsigned::value, std::size_t size_t_bits = sizeof(std::size_t) * CHAR_BIT, std::size_t type_bits = sizeof(T) * CHAR_BIT> struct hash_integral_impl; - template struct hash_integral_impl + template struct hash_integral_impl { static std::size_t fn( T v ) { @@ -89,7 +90,24 @@ namespace boost } }; - template struct hash_integral_impl + template struct hash_integral_impl + { + static std::size_t fn( T v ) + { + typedef typename boost::make_unsigned::type U; + + if( v >= 0 ) + { + return hash_integral_impl::fn( static_cast( v ) ); + } + else + { + return ~hash_integral_impl::fn( static_cast( ~static_cast( v ) ) ); + } + } + }; + + template struct hash_integral_impl { static std::size_t fn( T v ) { @@ -102,7 +120,7 @@ namespace boost } }; - template struct hash_integral_impl + template struct hash_integral_impl { static std::size_t fn( T v ) { @@ -117,7 +135,7 @@ namespace boost } }; - template struct hash_integral_impl + template struct hash_integral_impl { static std::size_t fn( T v ) { @@ -133,28 +151,12 @@ namespace boost } // namespace hash_detail template - typename boost::enable_if_, boost::is_unsigned >::value, std::size_t>::type + typename boost::enable_if_::value, std::size_t>::type hash_value( T v ) { return hash_detail::hash_integral_impl::fn( v ); } - template - typename boost::enable_if_, boost::is_signed >::value, std::size_t>::type - hash_value( T v ) - { - typedef typename boost::make_unsigned::type U; - - if( v >= 0 ) - { - return hash_value( static_cast( v ) ); - } - else - { - return ~hash_value( static_cast( ~static_cast( v ) ) ); - } - } - // enumeration types template