From bf7a78594ee110f69b3977d8b86b46046e3ee473 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 28 Nov 2022 18:04:35 +0200 Subject: [PATCH] Add a test with a tuple-like described struct --- test/Jamfile.v2 | 3 ++ test/hash_tuple_like_test.cpp | 2 +- test/hash_tuple_like_test2.cpp | 78 ++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 test/hash_tuple_like_test2.cpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index f4ded35..4406ab4 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -121,4 +121,7 @@ run hash_integral_test2.cpp ; run hash_nullptr_test.cpp ; run is_tuple_like_test.cpp ; + run hash_tuple_like_test.cpp ; +run hash_tuple_like_test2.cpp + : : : extra ; diff --git a/test/hash_tuple_like_test.cpp b/test/hash_tuple_like_test.cpp index d9b7fa0..47fa21e 100644 --- a/test/hash_tuple_like_test.cpp +++ b/test/hash_tuple_like_test.cpp @@ -16,7 +16,7 @@ #if !defined(BOOST_NO_CXX11_HDR_TUPLE) -# include +#include namespace user { diff --git a/test/hash_tuple_like_test2.cpp b/test/hash_tuple_like_test2.cpp new file mode 100644 index 0000000..ba04558 --- /dev/null +++ b/test/hash_tuple_like_test2.cpp @@ -0,0 +1,78 @@ +// 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) + +BOOST_PRAGMA_MESSAGE( "Skipping test because BOOST_NO_CXX11_HDR_TUPLE is defined" ) +int main() {} + +#elif !defined(BOOST_DESCRIBE_CXX14) + +BOOST_PRAGMA_MESSAGE( "Skipping test because BOOST_DESCRIBE_CXX14 is not defined" ) +int main() {} + +#else + +namespace user +{ + +struct Y3 +{ + int a; + int b; +}; + +BOOST_DESCRIBE_STRUCT(Y3, (), (a, b)) + +} // namespace user + +namespace std +{ + +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 + +template std::size_t hv( T const& t ) +{ + return boost::hash()( t ); +} + +int main() +{ + { + user::Y3 tp = { 1, 2 }; + int const a[] = { 1, 2 }; + + BOOST_TEST_EQ( hv(tp), hv(a) ); + } + + return boost::report_errors(); +} + +#endif