diff --git a/include/boost/variant2/variant.hpp b/include/boost/variant2/variant.hpp index 901438d..40b90fc 100644 --- a/include/boost/variant2/variant.hpp +++ b/include/boost/variant2/variant.hpp @@ -39,6 +39,8 @@ BOOST_NORETURN void throw_exception( std::exception const & e ); // user defined #endif +template struct hash; + namespace variant2 { @@ -2229,7 +2231,7 @@ inline std::size_t hash_value_impl( std::size_t index, std::size_t value ) return hash_value_impl_( mp11::mp_bool< (SIZE_MAX > UINT32_MAX) >(), index, value ); } -template struct hash_value_L +template class H, class V> struct hash_value_L { V const & v; @@ -2238,12 +2240,17 @@ template struct hash_value_L auto const & t = unsafe_get( v ); std::size_t index = I::value; - std::size_t value = std::hash>()( t ); + std::size_t value = H>()( t ); return hash_value_impl( index, value ); } }; +template std::size_t hash_value_std( variant const & v ) +{ + return mp11::mp_with_index( v.index(), detail::hash_value_L< std::hash, variant >{ v } ); +} + } // namespace detail inline std::size_t hash_value( monostate const & ) @@ -2253,7 +2260,7 @@ inline std::size_t hash_value( monostate const & ) template std::size_t hash_value( variant const & v ) { - return mp11::mp_with_index( v.index(), detail::hash_value_L< variant >{ v } ); + return mp11::mp_with_index( v.index(), detail::hash_value_L< boost::hash, variant >{ v } ); } namespace detail @@ -2274,7 +2281,7 @@ template struct std_hash_impl { std::size_t operator()( V const & v ) const { - return hash_value( v ); + return detail::hash_value_std( v ); } };