summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/hana/test/map/at_key.collisions.cpp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:45:59 +0000
commit19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch)
tree42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/boost/libs/hana/test/map/at_key.collisions.cpp
parentInitial commit. (diff)
downloadceph-upstream.tar.xz
ceph-upstream.zip
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/hana/test/map/at_key.collisions.cpp')
-rw-r--r--src/boost/libs/hana/test/map/at_key.collisions.cpp149
1 files changed, 149 insertions, 0 deletions
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 <boost/hana/assert.hpp>
+#include <boost/hana/at_key.hpp>
+#include <boost/hana/core/to.hpp>
+#include <boost/hana/equal.hpp>
+#include <boost/hana/hash.hpp>
+#include <boost/hana/integral_constant.hpp>
+#include <boost/hana/map.hpp>
+#include <boost/hana/not.hpp>
+#include <boost/hana/pair.hpp>
+#include <boost/hana/tuple.hpp>
+namespace hana = boost::hana;
+
+
+struct A { };
+struct B { };
+
+struct the_hash;
+
+namespace boost { namespace hana {
+ template <>
+ struct hash_impl<A> {
+ static constexpr auto apply(A const&) {
+ return hana::type_c<the_hash>;
+ }
+ };
+
+ template <>
+ struct hash_impl<B> {
+ static constexpr auto apply(B const&) {
+ return hana::type_c<the_hash>;
+ }
+ };
+
+ template <>
+ struct equal_impl<A, A> {
+ static constexpr auto apply(A const&, A const&) {
+ return hana::true_c;
+ }
+ };
+
+ template <>
+ struct equal_impl<B, B> {
+ 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>
+ ));
+ }
+}