]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/hana/test/builtin_array.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / hana / test / builtin_array.cpp
CommitLineData
b32b8144 1// Copyright Louis Dionne 2013-2017
7c673cae
FG
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/any_of.hpp>
6#include <boost/hana/assert.hpp>
7#include <boost/hana/bool.hpp>
8#include <boost/hana/concept/foldable.hpp>
9#include <boost/hana/concept/searchable.hpp>
10#include <boost/hana/equal.hpp>
11#include <boost/hana/find_if.hpp>
12#include <boost/hana/functional/always.hpp>
13#include <boost/hana/functional/placeholder.hpp>
14#include <boost/hana/not.hpp>
15#include <boost/hana/optional.hpp>
16#include <boost/hana/unpack.hpp>
17
18#include <laws/base.hpp>
19#include <laws/foldable.hpp>
20#include <laws/searchable.hpp>
21
22#include <cstddef>
23namespace hana = boost::hana;
24
25
26template <typename T, std::size_t n>
27using array = T[n];
28
29int main() {
30 // We can't check the laws because builtin arrays can't be passed
31 // to functions.
32
33 //////////////////////////////////////////////////////////////////////////
34 // Foldable
35 //////////////////////////////////////////////////////////////////////////
36 {
37 int a[] = {1};
38 int b[] = {1, 2};
39 int c[] = {1, 2, 3};
40 int d[] = {1, 2, 3, 4};
41
42 // unpack
43 {
44 hana::test::_injection<0> f{};
45
46 BOOST_HANA_RUNTIME_CHECK(hana::equal(
47 hana::unpack(a, f),
48 f(1)
49 ));
50
51 BOOST_HANA_RUNTIME_CHECK(hana::equal(
52 hana::unpack(b, f),
53 f(1, 2)
54 ));
55
56 BOOST_HANA_RUNTIME_CHECK(hana::equal(
57 hana::unpack(c, f),
58 f(1, 2, 3)
59 ));
60
61 BOOST_HANA_RUNTIME_CHECK(hana::equal(
62 hana::unpack(d, f),
63 f(1, 2, 3, 4)
64 ));
65 }
66
67 static_assert(hana::Foldable<int[3]>::value, "");
68 }
69
70 //////////////////////////////////////////////////////////////////////////
71 // Searchable
72 //////////////////////////////////////////////////////////////////////////
73 {
74 // any_of
75 {
76 static_assert(
77 hana::not_(hana::any_of(array<int, 1>{0}, hana::equal.to(1)))
78 , "");
79
80 static_assert(
81 hana::any_of(array<int, 2>{0, 1}, hana::equal.to(0))
82 , "");
83 static_assert(
84 hana::any_of(array<int, 2>{0, 1}, hana::equal.to(1))
85 , "");
86 static_assert(
87 hana::not_(hana::any_of(array<int, 2>{0, 1}, hana::equal.to(2)))
88 , "");
89
90 static_assert(
91 hana::any_of(array<int, 3>{0, 1, 2}, hana::equal.to(0))
92 , "");
93 static_assert(
94 hana::any_of(array<int, 3>{0, 1, 2}, hana::equal.to(1))
95 , "");
96 static_assert(
97 hana::any_of(array<int, 3>{0, 1, 2}, hana::equal.to(2))
98 , "");
99 static_assert(
100 hana::not_(hana::any_of(array<int, 3>{0, 1, 2}, hana::equal.to(3)))
101 , "");
102 }
103
104 // find_if
105 // Note: Because we need the predicate to return a Constant, this
106 // is incredibly not powerful.
107 {
108 static_assert(hana::equal(
109 hana::find_if(array<int, 1>{0}, hana::always(hana::true_c)),
110 hana::just(0)
111 ), "");
112
113 BOOST_HANA_CONSTANT_CHECK(hana::equal(
114 hana::find_if(array<int, 1>{0}, hana::always(hana::false_c)),
115 hana::nothing
116 ));
117 }
118
119 static_assert(hana::Searchable<int[3]>::value, "");
120 }
121}