• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 // Copyright 2012 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)
5 
6 #include "./config.hpp"
7 
8 #ifdef BOOST_HASH_TEST_STD_INCLUDES
9 #  include <functional>
10 #else
11 #  include <boost/container_hash/hash.hpp>
12 #endif
13 
14 #include <boost/core/lightweight_test.hpp>
15 #include "./compile_time.hpp"
16 
17 namespace test {
18     enum enum_override { enum_override1, enum_override2 };
hash_value(enum_override)19     std::size_t hash_value(enum_override) { return 896532; }
20 
21     enum enum1 { enum1a };
22     enum enum2 { enum2a, enum2b };
23     enum enum3 { enum3a = 574, enum3b };
24     enum enum4 { enum4a = -12574, enum4b };
25 }
26 
main()27 int main() {
28     compile_time_tests((test::enum1*) 0);
29     compile_time_tests((test::enum2*) 0);
30     compile_time_tests((test::enum3*) 0);
31     compile_time_tests((test::enum4*) 0);
32     compile_time_tests((test::enum_override*) 0);
33 
34     BOOST_HASH_TEST_NAMESPACE::hash<test::enum1> hash1;
35     BOOST_HASH_TEST_NAMESPACE::hash<test::enum2> hash2;
36     BOOST_HASH_TEST_NAMESPACE::hash<test::enum3> hash3;
37     BOOST_HASH_TEST_NAMESPACE::hash<test::enum4> hash4;
38 
39     BOOST_TEST(hash1(test::enum1a) == hash1(test::enum1a));
40 
41     BOOST_TEST(hash2(test::enum2a) == hash2(test::enum2a));
42     BOOST_TEST(hash2(test::enum2a) != hash2(test::enum2b));
43     BOOST_TEST(hash2(test::enum2b) == hash2(test::enum2b));
44 
45     BOOST_TEST(hash3(test::enum3a) == hash3(test::enum3a));
46     BOOST_TEST(hash3(test::enum3a) != hash3(test::enum3b));
47     BOOST_TEST(hash3(test::enum3b) == hash3(test::enum3b));
48 
49     BOOST_TEST(hash4(test::enum4a) == hash4(test::enum4a));
50     BOOST_TEST(hash4(test::enum4a) != hash4(test::enum4b));
51     BOOST_TEST(hash4(test::enum4b) == hash4(test::enum4b));
52 
53     BOOST_HASH_TEST_NAMESPACE::hash<test::enum_override> hash_override;
54 
55     BOOST_TEST(hash_override(test::enum_override1) ==
56         hash_override(test::enum_override1));
57     BOOST_TEST(hash_override(test::enum_override1) ==
58         hash_override(test::enum_override2));
59     BOOST_TEST(hash_override(test::enum_override1) ==
60         hash_override(test::enum_override1));
61 
62     return boost::report_errors();
63 }
64