From 565bac8d31926d82b482ae1a777592920f0932b4 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Thu, 12 Oct 2023 13:57:41 +0300 Subject: [PATCH] Remove C++03 workarounds --- .../boost/container_hash/detail/hash_mix.hpp | 12 +- .../container_hash/detail/hash_range.hpp | 170 +++++++++--------- .../container_hash/detail/hash_tuple_like.hpp | 104 +---------- include/boost/container_hash/detail/mulx.hpp | 40 ++--- include/boost/container_hash/hash.hpp | 71 +++----- .../container_hash/is_contiguous_range.hpp | 50 +++--- .../container_hash/is_described_class.hpp | 9 +- include/boost/container_hash/is_range.hpp | 45 +---- .../boost/container_hash/is_tuple_like.hpp | 12 +- .../container_hash/is_unordered_range.hpp | 13 +- test/is_contiguous_range_test.cpp | 6 +- 11 files changed, 189 insertions(+), 343 deletions(-) diff --git a/include/boost/container_hash/detail/hash_mix.hpp b/include/boost/container_hash/detail/hash_mix.hpp index 327da9e..088dd75 100644 --- a/include/boost/container_hash/detail/hash_mix.hpp +++ b/include/boost/container_hash/detail/hash_mix.hpp @@ -5,7 +5,7 @@ #ifndef BOOST_HASH_DETAIL_HASH_MIX_HPP #define BOOST_HASH_DETAIL_HASH_MIX_HPP -#include +#include #include #include @@ -66,9 +66,9 @@ template struct hash_mix_impl; template<> struct hash_mix_impl<64> { - inline static boost::uint64_t fn( boost::uint64_t x ) + inline static std::uint64_t fn( std::uint64_t x ) { - boost::uint64_t const m = (boost::uint64_t(0xe9846af) << 32) + 0x9b1a615d; + std::uint64_t const m = 0xe9846af9b1a615d; x ^= x >> 32; x *= m; @@ -87,10 +87,10 @@ template<> struct hash_mix_impl<64> template<> struct hash_mix_impl<32> { - inline static boost::uint32_t fn( boost::uint32_t x ) + inline static std::uint32_t fn( std::uint32_t x ) { - boost::uint32_t const m1 = 0x21f0aaad; - boost::uint32_t const m2 = 0x735a2d97; + std::uint32_t const m1 = 0x21f0aaad; + std::uint32_t const m2 = 0x735a2d97; x ^= x >> 16; x *= m1; diff --git a/include/boost/container_hash/detail/hash_range.hpp b/include/boost/container_hash/detail/hash_range.hpp index 84ec97d..74bfe38 100644 --- a/include/boost/container_hash/detail/hash_range.hpp +++ b/include/boost/container_hash/detail/hash_range.hpp @@ -7,10 +7,8 @@ #include #include -#include -#include -#include -#include +#include +#include #include #include #include @@ -22,20 +20,20 @@ namespace boost namespace hash_detail { -template struct is_char_type: public boost::false_type {}; +template struct is_char_type: public std::false_type {}; #if CHAR_BIT == 8 -template<> struct is_char_type: public boost::true_type {}; -template<> struct is_char_type: public boost::true_type {}; -template<> struct is_char_type: public boost::true_type {}; +template<> struct is_char_type: public std::true_type {}; +template<> struct is_char_type: public std::true_type {}; +template<> struct is_char_type: public std::true_type {}; #if defined(__cpp_char8_t) && __cpp_char8_t >= 201811L -template<> struct is_char_type: public boost::true_type {}; +template<> struct is_char_type: public std::true_type {}; #endif #if defined(__cpp_lib_byte) && __cpp_lib_byte >= 201603L -template<> struct is_char_type: public boost::true_type {}; +template<> struct is_char_type: public std::true_type {}; #endif #endif @@ -43,7 +41,7 @@ template<> struct is_char_type: public boost::true_type {}; // generic version template -inline typename boost::enable_if_< +inline typename std::enable_if< !is_char_type::value_type>::value, std::size_t >::type hash_range( std::size_t seed, It first, It last ) @@ -58,25 +56,25 @@ std::size_t >::type // specialized char[] version, 32 bit -template inline boost::uint32_t read32le( It p ) +template inline std::uint32_t read32le( It p ) { // clang 5+, gcc 5+ figure out this pattern and use a single mov on x86 // gcc on s390x and power BE even knows how to use load-reverse - boost::uint32_t w = - static_cast( static_cast( p[0] ) ) | - static_cast( static_cast( p[1] ) ) << 8 | - static_cast( static_cast( p[2] ) ) << 16 | - static_cast( static_cast( p[3] ) ) << 24; + std::uint32_t w = + static_cast( static_cast( p[0] ) ) | + static_cast( static_cast( p[1] ) ) << 8 | + static_cast( static_cast( p[2] ) ) << 16 | + static_cast( static_cast( p[3] ) ) << 24; return w; } #if defined(_MSC_VER) && !defined(__clang__) -template inline boost::uint32_t read32le( T* p ) +template inline std::uint32_t read32le( T* p ) { - boost::uint32_t w; + std::uint32_t w; std::memcpy( &w, p, 4 ); return w; @@ -84,15 +82,15 @@ template inline boost::uint32_t read32le( T* p ) #endif -inline boost::uint64_t mul32( boost::uint32_t x, boost::uint32_t y ) +inline std::uint64_t mul32( std::uint32_t x, std::uint32_t y ) { - return static_cast( x ) * y; + return static_cast( x ) * y; } template -inline typename boost::enable_if_< +inline typename std::enable_if< is_char_type::value_type>::value && - is_same::iterator_category, std::random_access_iterator_tag>::value && + std::is_same::iterator_category, std::random_access_iterator_tag>::value && std::numeric_limits::digits <= 32, std::size_t>::type hash_range( std::size_t seed, It first, It last ) @@ -100,17 +98,17 @@ std::size_t>::type It p = first; std::size_t n = static_cast( last - first ); - boost::uint32_t const q = 0x9e3779b9U; - boost::uint32_t const k = 0xe35e67b1U; // q * q + std::uint32_t const q = 0x9e3779b9U; + std::uint32_t const k = 0xe35e67b1U; // q * q - boost::uint64_t h = mul32( static_cast( seed ) + q, k ); - boost::uint32_t w = static_cast( h & 0xFFFFFFFF ); + std::uint64_t h = mul32( static_cast( seed ) + q, k ); + std::uint32_t w = static_cast( h & 0xFFFFFFFF ); h ^= n; while( n >= 4 ) { - boost::uint32_t v1 = read32le( p ); + std::uint32_t v1 = read32le( p ); w += q; h ^= mul32( v1 + w, k ); @@ -120,7 +118,7 @@ std::size_t>::type } { - boost::uint32_t v1 = 0; + std::uint32_t v1 = 0; if( n >= 1 ) { @@ -128,9 +126,9 @@ std::size_t>::type std::size_t const x2 = n >> 1; // 1: 0, 2: 1, 3: 1 v1 = - static_cast( static_cast( p[ static_cast( x1 ) ] ) ) << x1 * 8 | - static_cast( static_cast( p[ static_cast( x2 ) ] ) ) << x2 * 8 | - static_cast( static_cast( p[ 0 ] ) ); + static_cast( static_cast( p[ static_cast( x1 ) ] ) ) << x1 * 8 | + static_cast( static_cast( p[ static_cast( x2 ) ] ) ) << x2 * 8 | + static_cast( static_cast( p[ 0 ] ) ); } w += q; @@ -138,28 +136,28 @@ std::size_t>::type } w += q; - h ^= mul32( static_cast( h & 0xFFFFFFFF ) + w, static_cast( h >> 32 ) + w + k ); + h ^= mul32( static_cast( h & 0xFFFFFFFF ) + w, static_cast( h >> 32 ) + w + k ); - return static_cast( h & 0xFFFFFFFF ) ^ static_cast( h >> 32 ); + return static_cast( h & 0xFFFFFFFF ) ^ static_cast( h >> 32 ); } template -inline typename boost::enable_if_< +inline typename std::enable_if< is_char_type::value_type>::value && - !is_same::iterator_category, std::random_access_iterator_tag>::value && + !std::is_same::iterator_category, std::random_access_iterator_tag>::value && std::numeric_limits::digits <= 32, std::size_t>::type hash_range( std::size_t seed, It first, It last ) { std::size_t n = 0; - boost::uint32_t const q = 0x9e3779b9U; - boost::uint32_t const k = 0xe35e67b1U; // q * q + std::uint32_t const q = 0x9e3779b9U; + std::uint32_t const k = 0xe35e67b1U; // q * q - boost::uint64_t h = mul32( static_cast( seed ) + q, k ); - boost::uint32_t w = static_cast( h & 0xFFFFFFFF ); + std::uint64_t h = mul32( static_cast( seed ) + q, k ); + std::uint32_t w = static_cast( h & 0xFFFFFFFF ); - boost::uint32_t v1 = 0; + std::uint32_t v1 = 0; for( ;; ) { @@ -170,7 +168,7 @@ std::size_t>::type break; } - v1 |= static_cast( static_cast( *first ) ); + v1 |= static_cast( static_cast( *first ) ); ++first; ++n; @@ -179,7 +177,7 @@ std::size_t>::type break; } - v1 |= static_cast( static_cast( *first ) ) << 8; + v1 |= static_cast( static_cast( *first ) ) << 8; ++first; ++n; @@ -188,7 +186,7 @@ std::size_t>::type break; } - v1 |= static_cast( static_cast( *first ) ) << 16; + v1 |= static_cast( static_cast( *first ) ) << 16; ++first; ++n; @@ -197,7 +195,7 @@ std::size_t>::type break; } - v1 |= static_cast( static_cast( *first ) ) << 24; + v1 |= static_cast( static_cast( *first ) ) << 24; ++first; ++n; @@ -211,33 +209,33 @@ std::size_t>::type h ^= mul32( v1 + w, k ); w += q; - h ^= mul32( static_cast( h & 0xFFFFFFFF ) + w, static_cast( h >> 32 ) + w + k ); + h ^= mul32( static_cast( h & 0xFFFFFFFF ) + w, static_cast( h >> 32 ) + w + k ); - return static_cast( h & 0xFFFFFFFF ) ^ static_cast( h >> 32 ); + return static_cast( h & 0xFFFFFFFF ) ^ static_cast( h >> 32 ); } // specialized char[] version, 64 bit -template inline boost::uint64_t read64le( It p ) +template inline std::uint64_t read64le( It p ) { - boost::uint64_t w = - static_cast( static_cast( p[0] ) ) | - static_cast( static_cast( p[1] ) ) << 8 | - static_cast( static_cast( p[2] ) ) << 16 | - static_cast( static_cast( p[3] ) ) << 24 | - static_cast( static_cast( p[4] ) ) << 32 | - static_cast( static_cast( p[5] ) ) << 40 | - static_cast( static_cast( p[6] ) ) << 48 | - static_cast( static_cast( p[7] ) ) << 56; + std::uint64_t w = + static_cast( static_cast( p[0] ) ) | + static_cast( static_cast( p[1] ) ) << 8 | + static_cast( static_cast( p[2] ) ) << 16 | + static_cast( static_cast( p[3] ) ) << 24 | + static_cast( static_cast( p[4] ) ) << 32 | + static_cast( static_cast( p[5] ) ) << 40 | + static_cast( static_cast( p[6] ) ) << 48 | + static_cast( static_cast( p[7] ) ) << 56; return w; } #if defined(_MSC_VER) && !defined(__clang__) -template inline boost::uint64_t read64le( T* p ) +template inline std::uint64_t read64le( T* p ) { - boost::uint64_t w; + std::uint64_t w; std::memcpy( &w, p, 8 ); return w; @@ -246,9 +244,9 @@ template inline boost::uint64_t read64le( T* p ) #endif template -inline typename boost::enable_if_< +inline typename std::enable_if< is_char_type::value_type>::value && - is_same::iterator_category, std::random_access_iterator_tag>::value && + std::is_same::iterator_category, std::random_access_iterator_tag>::value && (std::numeric_limits::digits > 32), std::size_t>::type hash_range( std::size_t seed, It first, It last ) @@ -256,15 +254,15 @@ std::size_t>::type It p = first; std::size_t n = static_cast( last - first ); - boost::uint64_t const q = static_cast( 0x9e3779b9 ) << 32 | 0x7f4a7c15; - boost::uint64_t const k = static_cast( 0xdf442d22 ) << 32 | 0xce4859b9; // q * q + std::uint64_t const q = 0x9e3779b97f4a7c15; + std::uint64_t const k = 0xdf442d22ce4859b9; // q * q - boost::uint64_t w = mulx( seed + q, k ); - boost::uint64_t h = w ^ n; + std::uint64_t w = mulx( seed + q, k ); + std::uint64_t h = w ^ n; while( n >= 8 ) { - boost::uint64_t v1 = read64le( p ); + std::uint64_t v1 = read64le( p ); w += q; h ^= mulx( v1 + w, k ); @@ -274,11 +272,11 @@ std::size_t>::type } { - boost::uint64_t v1 = 0; + std::uint64_t v1 = 0; if( n >= 4 ) { - v1 = static_cast( read32le( p + static_cast( n - 4 ) ) ) << ( n - 4 ) * 8 | read32le( p ); + v1 = static_cast( read32le( p + static_cast( n - 4 ) ) ) << ( n - 4 ) * 8 | read32le( p ); } else if( n >= 1 ) { @@ -286,9 +284,9 @@ std::size_t>::type std::size_t const x2 = n >> 1; // 1: 0, 2: 1, 3: 1 v1 = - static_cast( static_cast( p[ static_cast( x1 ) ] ) ) << x1 * 8 | - static_cast( static_cast( p[ static_cast( x2 ) ] ) ) << x2 * 8 | - static_cast( static_cast( p[ 0 ] ) ); + static_cast( static_cast( p[ static_cast( x1 ) ] ) ) << x1 * 8 | + static_cast( static_cast( p[ static_cast( x2 ) ] ) ) << x2 * 8 | + static_cast( static_cast( p[ 0 ] ) ); } w += q; @@ -299,22 +297,22 @@ std::size_t>::type } template -inline typename boost::enable_if_< +inline typename std::enable_if< is_char_type::value_type>::value && - !is_same::iterator_category, std::random_access_iterator_tag>::value && + !std::is_same::iterator_category, std::random_access_iterator_tag>::value && (std::numeric_limits::digits > 32), std::size_t>::type hash_range( std::size_t seed, It first, It last ) { std::size_t n = 0; - boost::uint64_t const q = static_cast( 0x9e3779b9 ) << 32 | 0x7f4a7c15; - boost::uint64_t const k = static_cast( 0xdf442d22 ) << 32 | 0xce4859b9; // q * q + std::uint64_t const q = 0x9e3779b97f4a7c15; + std::uint64_t const k = 0xdf442d22ce4859b9; // q * q - boost::uint64_t w = mulx( seed + q, k ); - boost::uint64_t h = w; + std::uint64_t w = mulx( seed + q, k ); + std::uint64_t h = w; - boost::uint64_t v1 = 0; + std::uint64_t v1 = 0; for( ;; ) { @@ -325,7 +323,7 @@ std::size_t>::type break; } - v1 |= static_cast( static_cast( *first ) ); + v1 |= static_cast( static_cast( *first ) ); ++first; ++n; @@ -334,7 +332,7 @@ std::size_t>::type break; } - v1 |= static_cast( static_cast( *first ) ) << 8; + v1 |= static_cast( static_cast( *first ) ) << 8; ++first; ++n; @@ -343,7 +341,7 @@ std::size_t>::type break; } - v1 |= static_cast( static_cast( *first ) ) << 16; + v1 |= static_cast( static_cast( *first ) ) << 16; ++first; ++n; @@ -352,7 +350,7 @@ std::size_t>::type break; } - v1 |= static_cast( static_cast( *first ) ) << 24; + v1 |= static_cast( static_cast( *first ) ) << 24; ++first; ++n; @@ -361,7 +359,7 @@ std::size_t>::type break; } - v1 |= static_cast( static_cast( *first ) ) << 32; + v1 |= static_cast( static_cast( *first ) ) << 32; ++first; ++n; @@ -370,7 +368,7 @@ std::size_t>::type break; } - v1 |= static_cast( static_cast( *first ) ) << 40; + v1 |= static_cast( static_cast( *first ) ) << 40; ++first; ++n; @@ -379,7 +377,7 @@ std::size_t>::type break; } - v1 |= static_cast( static_cast( *first ) ) << 48; + v1 |= static_cast( static_cast( *first ) ) << 48; ++first; ++n; @@ -388,7 +386,7 @@ std::size_t>::type break; } - v1 |= static_cast( static_cast( *first ) ) << 56; + v1 |= static_cast( static_cast( *first ) ) << 56; ++first; ++n; diff --git a/include/boost/container_hash/detail/hash_tuple_like.hpp b/include/boost/container_hash/detail/hash_tuple_like.hpp index f9f5a5b..c7f881c 100644 --- a/include/boost/container_hash/detail/hash_tuple_like.hpp +++ b/include/boost/container_hash/detail/hash_tuple_like.hpp @@ -9,17 +9,8 @@ #include #include #include -#include -#include -#include - -#if defined(BOOST_NO_CXX11_HDR_TUPLE) - -// no support for tuple-likes - -#else - -#include +#include +#include namespace boost { @@ -28,14 +19,14 @@ namespace hash_detail template inline -typename boost::enable_if_<(I == std::tuple_size::value), void>::type +typename std::enable_if<(I == std::tuple_size::value), void>::type hash_combine_tuple_like( std::size_t&, T const& ) { } template inline -typename boost::enable_if_<(I < std::tuple_size::value), void>::type +typename std::enable_if<(I < std::tuple_size::value), void>::type hash_combine_tuple_like( std::size_t& seed, T const& v ) { using std::get; @@ -56,13 +47,9 @@ inline std::size_t hash_tuple_like( T const& v ) } // namespace hash_detail -#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) - -#if !BOOST_WORKAROUND(BOOST_MSVC, <= 1800) - template inline -typename boost::enable_if_< +typename std::enable_if< container_hash::is_tuple_like::value && !container_hash::is_range::value, std::size_t>::type hash_value( T const& v ) @@ -70,87 +57,6 @@ std::size_t>::type return boost::hash_detail::hash_tuple_like( v ); } -#else - -template -inline std::size_t hash_value( std::tuple const& v ) -{ - return boost::hash_detail::hash_tuple_like( v ); -} - -#endif - -#else - -inline std::size_t hash_value( std::tuple<> const& v ) -{ - return boost::hash_detail::hash_tuple_like( v ); -} - -template -inline std::size_t hash_value( std::tuple const& v ) -{ - return boost::hash_detail::hash_tuple_like( v ); -} - -template -inline std::size_t hash_value( std::tuple const& v ) -{ - return boost::hash_detail::hash_tuple_like( v ); -} - -template -inline std::size_t hash_value( std::tuple const& v ) -{ - return boost::hash_detail::hash_tuple_like( v ); -} - -template -inline std::size_t hash_value( std::tuple const& v ) -{ - return boost::hash_detail::hash_tuple_like( v ); -} - -template -inline std::size_t hash_value( std::tuple const& v ) -{ - return boost::hash_detail::hash_tuple_like( v ); -} - -template -inline std::size_t hash_value( std::tuple const& v ) -{ - return boost::hash_detail::hash_tuple_like( v ); -} - -template -inline std::size_t hash_value( std::tuple const& v ) -{ - return boost::hash_detail::hash_tuple_like( v ); -} - -template -inline std::size_t hash_value( std::tuple const& v ) -{ - return boost::hash_detail::hash_tuple_like( v ); -} - -template -inline std::size_t hash_value( std::tuple const& v ) -{ - return boost::hash_detail::hash_tuple_like( v ); -} - -template -inline std::size_t hash_value( std::tuple const& v ) -{ - return boost::hash_detail::hash_tuple_like( v ); -} - -#endif // #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) - } // namespace boost -#endif // #if defined(BOOST_NO_CXX11_HDR_TUPLE) - #endif // #ifndef BOOST_HASH_DETAIL_HASH_TUPLE_LIKE_HPP diff --git a/include/boost/container_hash/detail/mulx.hpp b/include/boost/container_hash/detail/mulx.hpp index da6f21a..a99a7dd 100644 --- a/include/boost/container_hash/detail/mulx.hpp +++ b/include/boost/container_hash/detail/mulx.hpp @@ -5,7 +5,7 @@ #ifndef BOOST_HASH_DETAIL_MULX_HPP #define BOOST_HASH_DETAIL_MULX_HPP -#include +#include #if defined(_MSC_VER) # include #endif @@ -17,55 +17,55 @@ namespace hash_detail #if defined(_MSC_VER) && defined(_M_X64) && !defined(__clang__) -__forceinline boost::uint64_t mulx( boost::uint64_t x, boost::uint64_t y ) +__forceinline std::uint64_t mulx( std::uint64_t x, std::uint64_t y ) { - boost::uint64_t r2; - boost::uint64_t r = _umul128( x, y, &r2 ); + std::uint64_t r2; + std::uint64_t r = _umul128( x, y, &r2 ); return r ^ r2; } #elif defined(_MSC_VER) && defined(_M_ARM64) && !defined(__clang__) -__forceinline boost::uint64_t mulx( boost::uint64_t x, boost::uint64_t y ) +__forceinline std::uint64_t mulx( std::uint64_t x, std::uint64_t y ) { - boost::uint64_t r = x * y; - boost::uint64_t r2 = __umulh( x, y ); + std::uint64_t r = x * y; + std::uint64_t r2 = __umulh( x, y ); return r ^ r2; } #elif defined(__SIZEOF_INT128__) -inline boost::uint64_t mulx( boost::uint64_t x, boost::uint64_t y ) +inline std::uint64_t mulx( std::uint64_t x, std::uint64_t y ) { __uint128_t r = static_cast<__uint128_t>( x ) * y; - return static_cast( r ) ^ static_cast( r >> 64 ); + return static_cast( r ) ^ static_cast( r >> 64 ); } #else -inline boost::uint64_t mulx( boost::uint64_t x, boost::uint64_t y ) +inline std::uint64_t mulx( std::uint64_t x, std::uint64_t y ) { - boost::uint64_t x1 = static_cast( x ); - boost::uint64_t x2 = x >> 32; + std::uint64_t x1 = static_cast( x ); + std::uint64_t x2 = x >> 32; - boost::uint64_t y1 = static_cast( y ); - boost::uint64_t y2 = y >> 32; + std::uint64_t y1 = static_cast( y ); + std::uint64_t y2 = y >> 32; - boost::uint64_t r3 = x2 * y2; + std::uint64_t r3 = x2 * y2; - boost::uint64_t r2a = x1 * y2; + std::uint64_t r2a = x1 * y2; r3 += r2a >> 32; - boost::uint64_t r2b = x2 * y1; + std::uint64_t r2b = x2 * y1; r3 += r2b >> 32; - boost::uint64_t r1 = x1 * y1; + std::uint64_t r1 = x1 * y1; - boost::uint64_t r2 = (r1 >> 32) + static_cast( r2a ) + static_cast( r2b ); + std::uint64_t r2 = (r1 >> 32) + static_cast( r2a ) + static_cast( r2b ); - r1 = (r2 << 32) + static_cast( r1 ); + r1 = (r2 << 32) + static_cast( r1 ); r3 += r2 >> 32; return r1 ^ r3; diff --git a/include/boost/container_hash/hash.hpp b/include/boost/container_hash/hash.hpp index 605644b..f523c96 100644 --- a/include/boost/container_hash/hash.hpp +++ b/include/boost/container_hash/hash.hpp @@ -11,7 +11,6 @@ #define BOOST_FUNCTIONAL_HASH_HASH_HPP #include -#include #include #include #include @@ -19,19 +18,10 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include #include -#include +#include +#include #if defined(BOOST_DESCRIBE_CXX14) # include @@ -82,7 +72,7 @@ namespace boost { template sizeof(std::size_t)), - bool is_unsigned = boost::is_unsigned::value, + bool is_unsigned = std::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; @@ -99,7 +89,7 @@ namespace boost { static std::size_t fn( T v ) { - typedef typename boost::make_unsigned::type U; + typedef typename std::make_unsigned::type U; if( v >= 0 ) { @@ -156,7 +146,7 @@ namespace boost } // namespace hash_detail template - typename boost::enable_if_::value, std::size_t>::type + typename std::enable_if::value, std::size_t>::type hash_value( T v ) { return hash_detail::hash_integral_impl::fn( v ); @@ -165,7 +155,7 @@ namespace boost // enumeration types template - typename boost::enable_if_::value, std::size_t>::type + typename std::enable_if::value, std::size_t>::type hash_value( T v ) { // This should in principle return the equivalent of @@ -199,7 +189,7 @@ namespace boost { static std::size_t fn( T v ) { - boost::uint32_t w; + std::uint32_t w; std::memcpy( &w, &v, sizeof( v ) ); return w; @@ -211,7 +201,7 @@ namespace boost { static std::size_t fn( T v ) { - boost::uint64_t w; + std::uint64_t w; std::memcpy( &w, &v, sizeof( v ) ); return hash_value( w ); @@ -223,7 +213,7 @@ namespace boost { static std::size_t fn( T v ) { - boost::uint64_t w[ 2 ] = {}; + std::uint64_t w[ 2 ] = {}; std::memcpy( &w, &v, 80 / CHAR_BIT ); std::size_t seed = 0; @@ -240,7 +230,7 @@ namespace boost { static std::size_t fn( T v ) { - boost::uint64_t w[ 2 ] = {}; + std::uint64_t w[ 2 ] = {}; std::memcpy( &w, &v, 80 / CHAR_BIT ); std::size_t seed = 0; @@ -257,7 +247,7 @@ namespace boost { static std::size_t fn( T v ) { - boost::uint64_t w[ 2 ]; + std::uint64_t w[ 2 ]; std::memcpy( &w, &v, sizeof( v ) ); std::size_t seed = 0; @@ -280,7 +270,7 @@ namespace boost } // namespace hash_detail template - typename boost::enable_if_::value, std::size_t>::type + typename std::enable_if::value, std::size_t>::type hash_value( T v ) { return boost::hash_detail::hash_float_impl::fn( v + 0 ); @@ -291,7 +281,7 @@ namespace boost // `x + (x >> 3)` adjustment by Alberto Barbati and Dave Harris. template std::size_t hash_value( T* const& v ) { - boost::uintptr_t x = reinterpret_cast( v ); + std::uintptr_t x = reinterpret_cast( v ); return boost::hash_value( x + (x >> 3) ); } @@ -336,7 +326,7 @@ namespace boost // ranges (list, set, deque...) template - typename boost::enable_if_::value && !container_hash::is_contiguous_range::value && !container_hash::is_unordered_range::value, std::size_t>::type + typename std::enable_if::value && !container_hash::is_contiguous_range::value && !container_hash::is_unordered_range::value, std::size_t>::type hash_value( T const& v ) { return boost::hash_range( v.begin(), v.end() ); @@ -345,7 +335,7 @@ namespace boost // contiguous ranges (string, vector, array) template - typename boost::enable_if_::value, std::size_t>::type + typename std::enable_if::value, std::size_t>::type hash_value( T const& v ) { return boost::hash_range( v.data(), v.data() + v.size() ); @@ -354,7 +344,7 @@ namespace boost // unordered ranges (unordered_set, unordered_map) template - typename boost::enable_if_::value, std::size_t>::type + typename std::enable_if::value, std::size_t>::type hash_value( T const& v ) { return boost::hash_unordered_range( v.begin(), v.end() ); @@ -367,7 +357,7 @@ namespace boost // resolve ambiguity with unconstrained stdext::hash_value in :-/ template class L, class... T> - typename boost::enable_if_>::value && !container_hash::is_contiguous_range>::value && !container_hash::is_unordered_range>::value, std::size_t>::type + typename std::enable_if>::value && !container_hash::is_contiguous_range>::value && !container_hash::is_unordered_range>::value, std::size_t>::type hash_value( L const& v ) { return boost::hash_range( v.begin(), v.end() ); @@ -376,14 +366,14 @@ namespace boost // contiguous ranges (string, vector, array) template class L, class... T> - typename boost::enable_if_>::value, std::size_t>::type + typename std::enable_if>::value, std::size_t>::type hash_value( L const& v ) { return boost::hash_range( v.data(), v.data() + v.size() ); } template class L, class T, std::size_t N> - typename boost::enable_if_>::value, std::size_t>::type + typename std::enable_if>::value, std::size_t>::type hash_value( L const& v ) { return boost::hash_range( v.data(), v.data() + v.size() ); @@ -392,7 +382,7 @@ namespace boost // unordered ranges (unordered_set, unordered_map) template class L, class... T> - typename boost::enable_if_>::value, std::size_t>::type + typename std::enable_if>::value, std::size_t>::type hash_value( L const& v ) { return boost::hash_unordered_range( v.begin(), v.end() ); @@ -410,10 +400,10 @@ namespace boost #endif template - typename boost::enable_if_::value, std::size_t>::type + typename std::enable_if::value, std::size_t>::type hash_value( T const& v ) { - static_assert( !boost::is_union::value, "described unions are not supported" ); + static_assert( !std::is_union::value, "described unions are not supported" ); std::size_t r = 0; @@ -503,7 +493,7 @@ namespace boost #if !defined(BOOST_NO_CXX11_NULLPTR) template - typename boost::enable_if_::value, std::size_t>::type + typename std::enable_if::value, std::size_t>::type hash_value( T const& /*v*/ ) { return boost::hash_value( static_cast( nullptr ) ); @@ -520,7 +510,7 @@ namespace boost { if( !v ) { - // Arbitray value for empty optional. + // Arbitrary value for empty optional. return 0x12345678; } else @@ -654,20 +644,11 @@ namespace boost namespace unordered { template struct hash_is_avalanching; - template struct hash_is_avalanching< boost::hash< std::basic_string > >: boost::is_integral {}; - - // boost::is_integral is false, but should be true (https://github.com/boostorg/type_traits/issues/175) -#if defined(__cpp_char8_t) && __cpp_char8_t >= 201811L - template<> struct hash_is_avalanching< boost::hash< std::basic_string > >: boost::true_type {}; -#endif + template struct hash_is_avalanching< boost::hash< std::basic_string > >: std::is_integral {}; #if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW) - template struct hash_is_avalanching< boost::hash< std::basic_string_view > >: boost::is_integral {}; - -#if defined(__cpp_char8_t) && __cpp_char8_t >= 201811L - template<> struct hash_is_avalanching< boost::hash< std::basic_string_view > >: boost::true_type {}; -#endif + template struct hash_is_avalanching< boost::hash< std::basic_string_view > >: std::is_integral {}; #endif } // namespace unordered diff --git a/include/boost/container_hash/is_contiguous_range.hpp b/include/boost/container_hash/is_contiguous_range.hpp index 96043cc..c18db6b 100644 --- a/include/boost/container_hash/is_contiguous_range.hpp +++ b/include/boost/container_hash/is_contiguous_range.hpp @@ -5,17 +5,13 @@ #ifndef BOOST_HASH_IS_CONTIGUOUS_RANGE_HPP_INCLUDED #define BOOST_HASH_IS_CONTIGUOUS_RANGE_HPP_INCLUDED -#include #include -#include #include #include +#include -#if !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_SFINAE_EXPR) && !BOOST_WORKAROUND(BOOST_GCC, < 40700) && !BOOST_WORKAROUND(BOOST_MSVC, < 1910) +#if !BOOST_WORKAROUND(BOOST_MSVC, < 1910) -#include -#include -#include #include namespace boost @@ -24,11 +20,11 @@ namespace hash_detail { template - integral_constant< bool, is_same::value_type, T>::value && is_integral::value > + std::integral_constant< bool, std::is_same::value_type, T>::value && std::is_integral::value > is_contiguous_range_check( It first, It last, T const*, T const*, S ); -template decltype( is_contiguous_range_check( declval().begin(), declval().end(), declval().data(), declval().data() + declval().size(), declval().size() ) ) is_contiguous_range_( int ); -template false_type is_contiguous_range_( ... ); +template decltype( is_contiguous_range_check( std::declval().begin(), std::declval().end(), std::declval().data(), std::declval().data() + std::declval().size(), std::declval().size() ) ) is_contiguous_range_( int ); +template std::false_type is_contiguous_range_( ... ); template struct is_contiguous_range: decltype( hash_detail::is_contiguous_range_( 0 ) ) { @@ -39,54 +35,64 @@ template struct is_contiguous_range: decltype( hash_detail::is_contiguo namespace container_hash { -template struct is_contiguous_range: integral_constant< bool, is_range::value && hash_detail::is_contiguous_range::value > +template struct is_contiguous_range: std::integral_constant< bool, is_range::value && hash_detail::is_contiguous_range::value > { }; } // namespace container_hash } // namespace boost -#else // !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_SFINAE_EXPR) +#else // !BOOST_WORKAROUND(BOOST_MSVC, < 1910) #include #include #include -#if !defined(BOOST_NO_CXX11_HDR_ARRAY) #include -#endif namespace boost { namespace container_hash { -template struct is_contiguous_range: false_type +template struct is_contiguous_range: std::false_type { }; -template struct is_contiguous_range< std::basic_string >: true_type +template struct is_contiguous_range< std::basic_string >: std::true_type { }; -template struct is_contiguous_range< std::basic_string const >: true_type +template struct is_contiguous_range< std::basic_string const >: std::true_type { }; -#if !defined(BOOST_NO_CXX11_HDR_ARRAY) - -template struct is_contiguous_range< std::array >: true_type +template struct is_contiguous_range< std::vector >: std::true_type { }; -template struct is_contiguous_range< std::array const >: true_type +template struct is_contiguous_range< std::vector const >: std::true_type { }; -#endif +template struct is_contiguous_range< std::vector >: std::false_type +{ +}; + +template struct is_contiguous_range< std::vector const >: std::false_type +{ +}; + +template struct is_contiguous_range< std::array >: std::true_type +{ +}; + +template struct is_contiguous_range< std::array const >: std::true_type +{ +}; } // namespace container_hash } // namespace boost -#endif // !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_SFINAE_EXPR) +#endif // !BOOST_WORKAROUND(BOOST_MSVC, < 1910) #endif // #ifndef BOOST_HASH_IS_CONTIGUOUS_RANGE_HPP_INCLUDED diff --git a/include/boost/container_hash/is_described_class.hpp b/include/boost/container_hash/is_described_class.hpp index cd2e1db..88f8ed3 100644 --- a/include/boost/container_hash/is_described_class.hpp +++ b/include/boost/container_hash/is_described_class.hpp @@ -5,10 +5,9 @@ #ifndef BOOST_HASH_IS_DESCRIBED_CLASS_HPP_INCLUDED #define BOOST_HASH_IS_DESCRIBED_CLASS_HPP_INCLUDED -#include -#include #include #include +#include namespace boost { @@ -17,16 +16,16 @@ namespace container_hash #if defined(BOOST_DESCRIBE_CXX11) -template struct is_described_class: boost::integral_constant struct is_described_class: std::integral_constant::value && describe::has_describe_members::value && - !boost::is_union::value> + !std::is_union::value> { }; #else -template struct is_described_class: boost::false_type +template struct is_described_class: std::false_type { }; diff --git a/include/boost/container_hash/is_range.hpp b/include/boost/container_hash/is_range.hpp index 2d3746c..f0b067f 100644 --- a/include/boost/container_hash/is_range.hpp +++ b/include/boost/container_hash/is_range.hpp @@ -5,29 +5,21 @@ #ifndef BOOST_HASH_IS_RANGE_HPP_INCLUDED #define BOOST_HASH_IS_RANGE_HPP_INCLUDED -#include -#include -#include -#include -#include -#include -#include -#include #include +#include namespace boost { -#if !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_SFINAE_EXPR) && !BOOST_WORKAROUND(BOOST_GCC, < 40700) namespace hash_detail { template - integral_constant< bool, !is_same::type, typename std::iterator_traits::value_type>::value > + std::integral_constant< bool, !std::is_same::type, typename std::iterator_traits::value_type>::value > is_range_check( It first, It last ); -template decltype( is_range_check( declval().begin(), declval().end() ) ) is_range_( int ); -template false_type is_range_( ... ); +template decltype( is_range_check( std::declval().begin(), std::declval().end() ) ) is_range_( int ); +template std::false_type is_range_( ... ); } // namespace hash_detail @@ -40,35 +32,6 @@ template struct is_range: decltype( hash_detail::is_range_( 0 ) ) } // namespace container_hash -#else - -namespace hash_detail -{ - -template struct is_range_: false_type -{ -}; - -template struct is_range_< T, integral_constant< bool, - is_same::value_type>::value && - is_integral::value - > >: true_type -{ -}; - -} // namespace hash_detail - -namespace container_hash -{ - -template struct is_range: hash_detail::is_range_ -{ -}; - -} // namespace container_hash - -#endif // !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_SFINAE_EXPR) - } // namespace boost #endif // #ifndef BOOST_HASH_IS_RANGE_HPP_INCLUDED diff --git a/include/boost/container_hash/is_tuple_like.hpp b/include/boost/container_hash/is_tuple_like.hpp index 8f57364..48728cd 100644 --- a/include/boost/container_hash/is_tuple_like.hpp +++ b/include/boost/container_hash/is_tuple_like.hpp @@ -5,9 +5,7 @@ // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt -#include -#include -#include +#include #include namespace boost @@ -15,18 +13,14 @@ namespace boost namespace hash_detail { -template struct is_tuple_like_: false_type +template struct is_tuple_like_: std::false_type { }; -#if !defined(BOOST_NO_CXX11_HDR_TUPLE) && !BOOST_WORKAROUND(BOOST_MSVC, <= 1800) - -template struct is_tuple_like_::value == std::tuple_size::value> >: true_type +template struct is_tuple_like_::value == std::tuple_size::value> >: std::true_type { }; -#endif - } // namespace hash_detail namespace container_hash diff --git a/include/boost/container_hash/is_unordered_range.hpp b/include/boost/container_hash/is_unordered_range.hpp index 11ee386..5a81b7d 100644 --- a/include/boost/container_hash/is_unordered_range.hpp +++ b/include/boost/container_hash/is_unordered_range.hpp @@ -6,21 +6,20 @@ #define BOOST_HASH_IS_UNORDERED_RANGE_HPP_INCLUDED #include -#include -#include +#include namespace boost { namespace hash_detail { -template struct has_hasher_: false_type +template struct has_hasher_: std::false_type { }; -template struct has_hasher_< T, integral_constant< bool, - is_same::value - > >: true_type +template struct has_hasher_< T, std::integral_constant< bool, + std::is_same::value + > >: std::true_type { }; @@ -29,7 +28,7 @@ template struct has_hasher_< T, integral_constant< bool, namespace container_hash { -template struct is_unordered_range: integral_constant< bool, is_range::value && hash_detail::has_hasher_::value > +template struct is_unordered_range: std::integral_constant< bool, is_range::value && hash_detail::has_hasher_::value > { }; diff --git a/test/is_contiguous_range_test.cpp b/test/is_contiguous_range_test.cpp index 9ce6664..9b77a9c 100644 --- a/test/is_contiguous_range_test.cpp +++ b/test/is_contiguous_range_test.cpp @@ -50,11 +50,11 @@ int main() BOOST_TEST_TRAIT_TRUE((is_contiguous_range)); BOOST_TEST_TRAIT_TRUE((is_contiguous_range)); -// std::vector doesn't have data() in C++03 -#if !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_SFINAE_EXPR) && !BOOST_WORKAROUND(BOOST_GCC, < 40700) && !BOOST_WORKAROUND(BOOST_MSVC, < 1910) BOOST_TEST_TRAIT_TRUE((is_contiguous_range< std::vector >)); BOOST_TEST_TRAIT_TRUE((is_contiguous_range< std::vector const >)); -#endif + + BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::vector >)); + BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::vector const >)); BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::deque >)); BOOST_TEST_TRAIT_FALSE((is_contiguous_range< std::deque const >));