// Copyright 2022 Peter Dimov. // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt #if defined(__clang__) # pragma clang diagnostic ignored "-Wmismatched-tags" #endif #include #include #include #include #include #include #include #if !defined(BOOST_NO_CXX11_HDR_TUPLE) #include namespace user { struct Y1 { int a; int b; }; template int& get( Y1& v ); template int const& get( Y1 const& v ); template<> int& get<0>( Y1& v ) { return v.a; } template<> int const& get<0>( Y1 const& v ) { return v.a; } template<> int& get<1>( Y1& v ) { return v.b; } template<> int const& get<1>( Y1 const& v ) { return v.b; } struct Y2 { int a; int b; template friend typename boost::enable_if_::value, std::size_t>::type hash_value( T const& v ) { std::size_t seed = 0; boost::hash_combine( seed, v.a ); boost::hash_combine( seed, v.b ); return seed; } }; } // namespace user namespace std { template<> struct tuple_size: std::integral_constant { }; template<> struct tuple_size: std::integral_constant { }; } // namespace std namespace boost { namespace container_hash { template<> struct is_tuple_like: boost::false_type {}; } // namespace container_hash } // namespace boost #endif template std::size_t hv( T const& t ) { return boost::hash()( t ); } int main() { { std::pair tp( 1, 2 ); int const a[] = { 1, 2 }; BOOST_TEST_EQ( hv(tp), hv(a) ); } #if !defined(BOOST_NO_CXX11_HDR_TUPLE) { std::tuple<> tp; BOOST_TEST_EQ( hv(tp), 0u ); } { std::tuple tp( 1 ); int const a[] = { 1 }; BOOST_TEST_EQ( hv(tp), hv(a) ); } { std::tuple tp( 1, 2 ); int const a[] = { 1, 2 }; BOOST_TEST_EQ( hv(tp), hv(a) ); } { std::tuple tp( 1, 2, 3 ); int const a[] = { 1, 2, 3 }; BOOST_TEST_EQ( hv(tp), hv(a) ); } { std::tuple tp( 1, 2, 3, 4 ); int const a[] = { 1, 2, 3, 4 }; BOOST_TEST_EQ( hv(tp), hv(a) ); } { std::tuple tp( 1, 2, 3, 4, 5 ); int const a[] = { 1, 2, 3, 4, 5 }; BOOST_TEST_EQ( hv(tp), hv(a) ); } { std::tuple tp( 1, 2, 3, 4, 5, 6 ); int const a[] = { 1, 2, 3, 4, 5, 6 }; BOOST_TEST_EQ( hv(tp), hv(a) ); } { std::tuple tp( 1, 2, 3, 4, 5, 6, 7 ); int const a[] = { 1, 2, 3, 4, 5, 6, 7 }; BOOST_TEST_EQ( hv(tp), hv(a) ); } { std::tuple tp( 1, 2, 3, 4, 5, 6, 7, 8 ); int const a[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; BOOST_TEST_EQ( hv(tp), hv(a) ); } { std::tuple tp( 1, 2, 3, 4, 5, 6, 7, 8, 9 ); int const a[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; BOOST_TEST_EQ( hv(tp), hv(a) ); } #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1800) { user::Y1 tp = { 1, 2 }; int const a[] = { 1, 2 }; BOOST_TEST_EQ( hv(tp), hv(a) ); } #endif { user::Y2 tp = { 1, 2 }; int const a[] = { 1, 2 }; BOOST_TEST_EQ( hv(tp), hv(a) ); } #endif return boost::report_errors(); }