1 // Copyright (c) 2011-2019 Antony Polukhin
3 // Distributed under the Boost Software License, Version 1.0. (See
4 // accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
7 #include "boost/core/lightweight_test.hpp"
9 #include "boost/config.hpp"
10 #include "boost/variant.hpp"
11 #include "boost/functional/hash/hash.hpp"
13 #if !defined(BOOST_NO_CXX11_HDR_UNORDERED_SET) && !defined(BOOST_VARIANT_DO_NOT_SPECIALIZE_STD_HASH)
15 #include <unordered_set>
17 void test_std_hash() {
18 std::unordered_set
<boost::variant
<int, bool> > us
;
21 BOOST_TEST(us
.size() == 2);
25 void test_std_hash() {}
30 typedef boost::variant
<bool, int, unsigned int, char> variant_type
;
31 boost::hash
<variant_type
> hasher
;
33 variant_type bool_variant1
= true;
34 variant_type bool_variant2
= false;
35 variant_type int_variant
= 1;
36 variant_type char_variant1
= '\1';
37 variant_type char_variant2
= '\2';
38 variant_type uint_variant
= static_cast<unsigned int>(1);
40 BOOST_TEST(hasher(bool_variant1
) != hasher(bool_variant2
));
41 BOOST_TEST(hasher(bool_variant1
) == hasher(bool_variant1
));
42 BOOST_TEST(hasher(int_variant
) != hasher(uint_variant
));
43 BOOST_TEST(hasher(char_variant1
) != hasher(uint_variant
));
44 BOOST_TEST(hasher(char_variant1
) != hasher(char_variant2
));
45 BOOST_TEST(hasher(char_variant1
) == hasher(char_variant1
));
46 BOOST_TEST(hasher(char_variant2
) == hasher(char_variant2
));
52 return boost::report_errors();