From c14d3a1e2b2061394dd1b8cd743358e10cb0f300 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 3 Jul 2022 21:08:14 +0300 Subject: [PATCH] Add a comment explaining why to_underlying isn't used in hash_value for enums --- include/boost/container_hash/hash.hpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/boost/container_hash/hash.hpp b/include/boost/container_hash/hash.hpp index b4066b1..f58c9c8 100644 --- a/include/boost/container_hash/hash.hpp +++ b/include/boost/container_hash/hash.hpp @@ -163,6 +163,20 @@ namespace boost typename boost::enable_if_::value, std::size_t>::type hash_value( T v ) { + // This should in principle return the equivalent of + // + // boost::hash_value( to_underlying(v) ); + // + // However, the C++03 implementation of underlying_type, + // + // conditional, make_signed, make_unsigned>::type::type + // + // generates a legitimate -Wconversion warning in is_signed, + // because -1 is not a valid enum value when all the enumerators + // are nonnegative. + // + // So the legacy implementation will have to do for now. + return static_cast( v ); }