2 // Copyright 2018 Daniel James
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #include "./config.hpp"
8 #ifndef BOOST_HASH_TEST_STD_INCLUDES
9 # include <boost/container_hash/hash.hpp>
11 #include <boost/config.hpp>
12 #include <boost/core/lightweight_test.hpp>
14 #if BOOST_HASH_HAS_VARIANT
24 boost::hash
<std::monostate
> hasher
;
26 BOOST_TEST(hasher(x1
) == hasher(x2
));
29 void test_variant_int()
31 std::variant
<std::monostate
, int> x1a
;
32 std::variant
<std::monostate
, int> x1b
;
33 std::variant
<std::monostate
, int> x2a(10);
34 std::variant
<std::monostate
, int> x2b(x2a
);
35 std::variant
<std::monostate
, int> x3(20);
37 boost::hash
<std::variant
<std::monostate
, int> > hasher
;
39 BOOST_TEST(hasher(x1a
) == hasher(x1a
));
40 BOOST_TEST(hasher(x1a
) == hasher(x1b
));
41 BOOST_TEST(hasher(x1a
) != hasher(x2a
));
42 BOOST_TEST(hasher(x1a
) != hasher(x3
));
43 BOOST_TEST(hasher(x2a
) == hasher(x2a
));
44 BOOST_TEST(hasher(x2b
) == hasher(x2b
));
45 BOOST_TEST(hasher(x2a
) != hasher(x3
));
46 BOOST_TEST(hasher(x3
) == hasher(x3
));
51 friend std::size_t hash_value(custom1 v
) { return boost::hash_value(v
.value
); }
56 friend std::size_t hash_value(custom2 v
) { return boost::hash_value(v
.value
); }
59 void test_variant_unique_types()
66 boost::hash
<custom1
> hasher1
;
67 boost::hash
<custom2
> hasher2
;
69 BOOST_TEST(hasher1(x11
) == hasher2(x21
));
70 BOOST_TEST(hasher1(x11
) != hasher2(x22
));
71 BOOST_TEST(hasher1(x12
) != hasher2(x21
));
72 BOOST_TEST(hasher1(x12
) == hasher2(x22
));
74 typedef std::variant
<custom1
, custom2
> variant_type
;
76 variant_type
y11(x11
);
77 variant_type
y12(x12
);
78 variant_type
y21(x21
);
79 variant_type
y22(x22
);
81 boost::hash
<variant_type
> hasher
;
83 BOOST_TEST(hasher(y11
) != hasher(y21
));
84 BOOST_TEST(hasher(y11
) != hasher(y22
));
85 BOOST_TEST(hasher(y12
) != hasher(y21
));
86 BOOST_TEST(hasher(y12
) != hasher(y22
));
93 #if BOOST_HASH_HAS_VARIANT
95 test_variant_unique_types();
97 BOOST_LIGHTWEIGHT_TEST_OSTREAM
<< "<variant> not available." << std::endl
;
99 return boost::report_errors();