Imported Upstream version 1.57.0
[platform/upstream/boost.git] / libs / variant / test / hash_variant_test.cpp
1 // Copyright (c) 2011-2014
2 // Antony Polukhin
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7
8 #include "boost/test/minimal.hpp"
9 #include "boost/variant.hpp"
10 #include "boost/functional/hash/hash.hpp"
11
12 void run()
13 {
14     typedef boost::variant<bool, int, unsigned int, char> variant_type;
15     boost::hash<variant_type> hasher;
16
17     variant_type bool_variant1 = true;
18     variant_type bool_variant2 = false;
19     variant_type int_variant = 1;
20     variant_type char_variant1 = '\1';
21     variant_type char_variant2 = '\2';
22     variant_type uint_variant = static_cast<unsigned int>(1);
23
24     BOOST_CHECK(hasher(bool_variant1) != hasher(bool_variant2));
25     BOOST_CHECK(hasher(bool_variant1) == hasher(bool_variant1));
26     BOOST_CHECK(hasher(int_variant) != hasher(uint_variant));
27     BOOST_CHECK(hasher(char_variant1) != hasher(uint_variant));
28     BOOST_CHECK(hasher(char_variant1) != hasher(char_variant2));
29     BOOST_CHECK(hasher(char_variant1) == hasher(char_variant1));
30     BOOST_CHECK(hasher(char_variant2) == hasher(char_variant2));
31 }
32
33 int test_main(int , char* [])
34 {
35    run();
36    return 0;
37 }
38