]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hana/test/integral_constant/hash.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / hana / test / integral_constant / hash.cpp
1 // Copyright Louis Dionne 2013-2017
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
4
5 #include <boost/hana/assert.hpp>
6 #include <boost/hana/bool.hpp>
7 #include <boost/hana/config.hpp>
8 #include <boost/hana/equal.hpp>
9 #include <boost/hana/hash.hpp>
10 #include <boost/hana/integral_constant.hpp>
11 #include <boost/hana/type.hpp>
12
13 #include <type_traits>
14 namespace hana = boost::hana;
15
16
17 int main() {
18 // Unsigned integral constants should hash to `unsigned long long`
19 {
20 BOOST_HANA_CONSTANT_ASSERT(hana::equal(
21 hana::hash(hana::integral_c<unsigned char, 10>),
22 hana::type_c<hana::integral_constant<unsigned long long, 10>>
23 ));
24 BOOST_HANA_CONSTANT_ASSERT(hana::equal(
25 hana::hash(hana::integral_c<unsigned short, 10>),
26 hana::type_c<hana::integral_constant<unsigned long long, 10>>
27 ));
28 BOOST_HANA_CONSTANT_ASSERT(hana::equal(
29 hana::hash(hana::integral_c<unsigned int, 10>),
30 hana::type_c<hana::integral_constant<unsigned long long, 10>>
31 ));
32 BOOST_HANA_CONSTANT_ASSERT(hana::equal(
33 hana::hash(hana::integral_c<unsigned long, 10>),
34 hana::type_c<hana::integral_constant<unsigned long long, 10>>
35 ));
36 BOOST_HANA_CONSTANT_ASSERT(hana::equal(
37 hana::hash(hana::integral_c<unsigned long long, 10>),
38 hana::type_c<hana::integral_constant<unsigned long long, 10>>
39 ));
40 }
41
42 // Signed integral constants should hash to `signed long long`
43 {
44 BOOST_HANA_CONSTANT_ASSERT(hana::equal(
45 hana::hash(hana::integral_c<signed char, 10>),
46 hana::type_c<hana::integral_constant<signed long long, 10>>
47 ));
48 BOOST_HANA_CONSTANT_ASSERT(hana::equal(
49 hana::hash(hana::integral_c<signed short, 10>),
50 hana::type_c<hana::integral_constant<signed long long, 10>>
51 ));
52 BOOST_HANA_CONSTANT_ASSERT(hana::equal(
53 hana::hash(hana::integral_c<signed int, 10>),
54 hana::type_c<hana::integral_constant<signed long long, 10>>
55 ));
56 BOOST_HANA_CONSTANT_ASSERT(hana::equal(
57 hana::hash(hana::integral_c<signed long, 10>),
58 hana::type_c<hana::integral_constant<signed long long, 10>>
59 ));
60 BOOST_HANA_CONSTANT_ASSERT(hana::equal(
61 hana::hash(hana::integral_c<signed long long, 10>),
62 hana::type_c<hana::integral_constant<signed long long, 10>>
63 ));
64 }
65
66 // `char` should hash to either `signed long long` or `unsigned long long`,
67 // depending on its signedness
68 {
69 using T = std::conditional_t<
70 std::is_signed<char>::value,
71 signed long long,
72 unsigned long long
73 >;
74
75 BOOST_HANA_CONSTANT_ASSERT(hana::equal(
76 hana::hash(hana::integral_c<char, 10>),
77 hana::type_c<hana::integral_constant<T, 10>>
78 ));
79 }
80
81 // Pointers to members should hash to themselves.
82 // This test is disabled in pre-C++17, because pointers to non-static
83 // data members can't be used as non-type template arguments before that.
84 // See http://stackoverflow.com/q/35398848/627587.
85 {
86 #if __cplusplus > 201402L
87
88 struct Foo { int bar; };
89 constexpr auto x = hana::integral_constant<int Foo::*, &Foo::bar>{};
90 BOOST_HANA_CONSTANT_ASSERT(hana::equal(
91 hana::hash(x),
92 hana::type_c<hana::integral_constant<int Foo::*, &Foo::bar>>
93 ));
94
95 #endif
96 }
97
98 // Booleans should hash to themselves
99 {
100 BOOST_HANA_CONSTANT_ASSERT(hana::equal(
101 hana::hash(hana::true_c),
102 hana::type_c<hana::true_>
103 ));
104
105 BOOST_HANA_CONSTANT_ASSERT(hana::equal(
106 hana::hash(hana::false_c),
107 hana::type_c<hana::false_>
108 ));
109 }
110 }