]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hana/test/_include/auto/all_of.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / hana / test / _include / auto / all_of.hpp
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 #ifndef BOOST_HANA_TEST_AUTO_ALL_OF_HPP
6 #define BOOST_HANA_TEST_AUTO_ALL_OF_HPP
7
8 #include <boost/hana/all_of.hpp>
9 #include <boost/hana/assert.hpp>
10 #include <boost/hana/bool.hpp>
11 #include <boost/hana/equal.hpp>
12 #include <boost/hana/not.hpp>
13
14 #include "test_case.hpp"
15 #include <laws/base.hpp>
16
17
18 TestCase test_all_of{[]{
19 namespace hana = boost::hana;
20 using hana::test::ct_eq;
21
22 BOOST_HANA_CONSTANT_CHECK(hana::all_of(
23 MAKE_TUPLE(),
24 [](auto) { return hana::false_c; }
25 ));
26
27 BOOST_HANA_CONSTANT_CHECK(hana::all_of(
28 MAKE_TUPLE(ct_eq<0>{}),
29 [](auto) { return hana::true_c; }
30 ));
31 BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::all_of(
32 MAKE_TUPLE(ct_eq<0>{}),
33 [](auto) { return hana::false_c; }
34 )));
35 BOOST_HANA_CONSTANT_CHECK(hana::all_of(
36 MAKE_TUPLE(ct_eq<0>{}),
37 hana::equal.to(ct_eq<0>{})
38 ));
39 BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::all_of(
40 MAKE_TUPLE(ct_eq<0>{}),
41 hana::equal.to(ct_eq<999>{})
42 )));
43
44 BOOST_HANA_CONSTANT_CHECK(hana::all_of(
45 MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}),
46 [](auto) { return hana::true_c; }
47 ));
48 BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::all_of(
49 MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}),
50 [](auto) { return hana::false_c; }
51 )));
52 BOOST_HANA_CONSTANT_CHECK(hana::all_of(
53 MAKE_TUPLE(ct_eq<0>{}, ct_eq<0>{}),
54 hana::equal.to(ct_eq<0>{})
55 ));
56 BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::all_of(
57 MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}),
58 hana::equal.to(ct_eq<0>{})
59 )));
60
61 BOOST_HANA_CONSTANT_CHECK(hana::all_of(
62 MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}),
63 [](auto) { return hana::true_c; }
64 ));
65 BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::all_of(
66 MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<2>{}),
67 [](auto) { return hana::false_c; }
68 )));
69 BOOST_HANA_CONSTANT_CHECK(hana::all_of(
70 MAKE_TUPLE(ct_eq<0>{}, ct_eq<0>{}, ct_eq<0>{}),
71 hana::equal.to(ct_eq<0>{})
72 ));
73 BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::all_of(
74 MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{}, ct_eq<0>{}),
75 hana::equal.to(ct_eq<0>{})
76 )));
77
78 BOOST_HANA_CONSTANT_CHECK(hana::all_of(
79 MAKE_TUPLE(ct_eq<0>{}, ct_eq<0>{}, ct_eq<0>{}, ct_eq<0>{}),
80 hana::equal.to(ct_eq<0>{})
81 ));
82 BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::all_of(
83 MAKE_TUPLE(ct_eq<999>{}, ct_eq<0>{}, ct_eq<0>{}, ct_eq<0>{}),
84 hana::equal.to(ct_eq<0>{})
85 )));
86 BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::all_of(
87 MAKE_TUPLE(ct_eq<0>{}, ct_eq<999>{}, ct_eq<0>{}, ct_eq<0>{}),
88 hana::equal.to(ct_eq<0>{})
89 )));
90 BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::all_of(
91 MAKE_TUPLE(ct_eq<0>{}, ct_eq<0>{}, ct_eq<999>{}, ct_eq<0>{}),
92 hana::equal.to(ct_eq<0>{})
93 )));
94 BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::all_of(
95 MAKE_TUPLE(ct_eq<0>{}, ct_eq<0>{}, ct_eq<0>{}, ct_eq<999>{}),
96 hana::equal.to(ct_eq<0>{})
97 )));
98
99 // Make sure `all_of` short-circuits with runtime predicates
100 // See http://stackoverflow.com/q/42012512/627587
101 {
102 {
103 int counter = 0;
104 auto tuple = MAKE_TUPLE(ct_eq<0>{}, ct_eq<1>{});
105 hana::all_of(tuple, [&](auto) { ++counter; return false; });
106 BOOST_HANA_RUNTIME_CHECK(counter == 1);
107 }
108 {
109 int counter = 0;
110 auto tuple = MAKE_TUPLE(ct_eq<0>{}, ct_eq<999>{}, ct_eq<0>{});
111 hana::all_of(tuple, [&](auto x) -> bool {
112 ++counter;
113 return hana::equal(x, ct_eq<0>{});
114 });
115 BOOST_HANA_RUNTIME_CHECK(counter == 2);
116 }
117 }
118 }};
119
120 #endif // !BOOST_HANA_TEST_AUTO_ALL_OF_HPP