From 5bef4901b98d12bb124ae09e68e16fd42cb564d6 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Fri, 9 Dec 2022 21:12:30 +0200 Subject: [PATCH] Add a pointer overload for detail::hash_range under msvc --- .../container_hash/detail/hash_range.hpp | 64 ++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/include/boost/container_hash/detail/hash_range.hpp b/include/boost/container_hash/detail/hash_range.hpp index 28fd239..4583ab4 100644 --- a/include/boost/container_hash/detail/hash_range.hpp +++ b/include/boost/container_hash/detail/hash_range.hpp @@ -10,9 +10,10 @@ #include #include #include +#include #include #include -#include +#include namespace boost { @@ -116,6 +117,67 @@ std::size_t>::type return seed; } +#if defined(_MSC_VER) && !defined(__clang__) + +template +inline typename boost::enable_if_::value, std::size_t>::type + hash_range( std::size_t seed, T const* first, T const* last ) +{ + std::size_t n = static_cast( last - first ); + + for( ; n >= 4; first += 4, n -= 4 ) + { + boost::uint32_t w; + + std::memcpy( &w, first, 4 ); + + hash_combine( seed, w ); + } + + { + // add a trailing suffix byte of 0x01 because otherwise sequences of + // trailing zeroes are indistinguishable from end of string + + boost::uint32_t w = 0x01u; + + switch( n ) + { + case 1: + + w = + static_cast( static_cast( first[0] ) ) | + 0x0100u; + + break; + + case 2: + + w = + static_cast( static_cast( first[0] ) ) | + static_cast( static_cast( first[1] ) ) << 8 | + 0x010000u; + + break; + + case 3: + + w = + static_cast( static_cast( first[0] ) ) | + static_cast( static_cast( first[1] ) ) << 8 | + static_cast( static_cast( first[2] ) ) << 16 | + 0x01000000u; + + break; + } + + hash_combine( seed, w ); + } + + return seed; +} + +#endif + template inline typename boost::enable_if_< is_char_type::value_type>::value &&