From 19fcec84d8d7d21e796c7624e521b60d28ee21ed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:45:59 +0200 Subject: Adding upstream version 16.2.11+ds. Signed-off-by: Daniel Baumann --- src/boost/libs/hana/test/map/at_key.collisions.cpp | 149 +++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 src/boost/libs/hana/test/map/at_key.collisions.cpp (limited to 'src/boost/libs/hana/test/map/at_key.collisions.cpp') diff --git a/src/boost/libs/hana/test/map/at_key.collisions.cpp b/src/boost/libs/hana/test/map/at_key.collisions.cpp new file mode 100644 index 000000000..3df10c4a0 --- /dev/null +++ b/src/boost/libs/hana/test/map/at_key.collisions.cpp @@ -0,0 +1,149 @@ +// Copyright Jason Rice 2016 +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +namespace hana = boost::hana; + + +struct A { }; +struct B { }; + +struct the_hash; + +namespace boost { namespace hana { + template <> + struct hash_impl { + static constexpr auto apply(A const&) { + return hana::type_c; + } + }; + + template <> + struct hash_impl { + static constexpr auto apply(B const&) { + return hana::type_c; + } + }; + + template <> + struct equal_impl { + static constexpr auto apply(A const&, A const&) { + return hana::true_c; + } + }; + + template <> + struct equal_impl { + static constexpr auto apply(B const&, B const&) { + return hana::true_c; + } + }; +}} + +int main() { + constexpr auto key1 = A{}; + constexpr auto key2 = B{}; + + BOOST_HANA_CONSTANT_CHECK(hana::equal(key1, key1)); + BOOST_HANA_CONSTANT_CHECK(hana::equal(key2, key2)); + BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::equal(key1, key2))); + + // ensure the hashes actually collide + BOOST_HANA_CONSTANT_CHECK(hana::equal(hana::hash(key1), hana::hash(key2))); + + { + auto map = hana::to_map(hana::make_tuple( + hana::make_pair(key1, key1), + hana::make_pair(key2, key2) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at_key(map, key1), + key1 + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at_key(map, key2), + key2 + )); + } + + { + auto map = hana::to_map(hana::make_tuple( + hana::make_pair(key2, key2), + hana::make_pair(key1, key1) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at_key(map, key1), + key1 + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at_key(map, key2), + key2 + )); + } + + { + auto map = hana::to_map(hana::make_tuple( + hana::make_pair(key1, key1), + hana::make_pair(hana::int_c<56>, hana::int_c<56>), + hana::make_pair(key2, key2) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at_key(map, key1), + key1 + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at_key(map, hana::int_c<56>), + hana::int_c<56> + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at_key(map, key2), + key2 + )); + } + + { + auto map = hana::to_map(hana::make_tuple( + hana::make_pair(key1, key1), + hana::make_pair(hana::int_c<56>, hana::int_c<56>), + hana::make_pair(key2, key2), + hana::make_pair(hana::int_c<42>, hana::int_c<42>) + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at_key(map, key1), + key1 + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at_key(map, hana::int_c<56>), + hana::int_c<56> + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at_key(map, key2), + key2 + )); + + BOOST_HANA_CONSTANT_CHECK(hana::equal( + hana::at_key(map, hana::int_c<42>), + hana::int_c<42> + )); + } +} -- cgit v1.2.3