]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hana/test/tuple/special.fold_left.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / hana / test / tuple / special.fold_left.cpp
1 // Copyright Louis Dionne 2013-2016
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/equal.hpp>
7 #include <boost/hana/fold_left.hpp>
8 #include <boost/hana/tuple.hpp>
9 #include <boost/hana/type.hpp>
10 namespace hana = boost::hana;
11
12
13 template <typename ...>
14 struct F { struct type; };
15
16 struct x0;
17 struct x1;
18 struct x2;
19 struct x3;
20
21 int main() {
22 // tuple_t and initial state
23 {
24 auto f = hana::metafunction<F>;
25 auto s = hana::type_c<struct initial_state>;
26 BOOST_HANA_CONSTANT_CHECK(hana::equal(
27 hana::fold_left(hana::tuple_t<>, s, f),
28 s
29 ));
30 BOOST_HANA_CONSTANT_CHECK(hana::equal(
31 hana::fold_left(hana::tuple_t<x0>, s, f),
32 f(s, hana::type_c<x0>)
33 ));
34 BOOST_HANA_CONSTANT_CHECK(hana::equal(
35 hana::fold_left(hana::tuple_t<x0, x1>, s, f),
36 f(f(s, hana::type_c<x0>), hana::type_c<x1>)
37 ));
38 BOOST_HANA_CONSTANT_CHECK(hana::equal(
39 hana::fold_left(hana::tuple_t<x0, x1, x2>, s, f),
40 f(f(f(s, hana::type_c<x0>), hana::type_c<x1>), hana::type_c<x2>)
41 ));
42 BOOST_HANA_CONSTANT_CHECK(hana::equal(
43 hana::fold_left(hana::tuple_t<x0, x1, x2, x3>, s, f),
44 f(f(f(f(s, hana::type_c<x0>), hana::type_c<x1>), hana::type_c<x2>), hana::type_c<x3>)
45 ));
46 }
47
48 // tuple_t and no initial state
49 {
50 auto f = hana::metafunction<F>;
51 BOOST_HANA_CONSTANT_CHECK(hana::equal(
52 hana::fold_left(hana::tuple_t<x0>, f),
53 hana::type_c<x0>
54 ));
55 BOOST_HANA_CONSTANT_CHECK(hana::equal(
56 hana::fold_left(hana::tuple_t<x0, x1>, f),
57 f(hana::type_c<x0>, hana::type_c<x1>)
58 ));
59 BOOST_HANA_CONSTANT_CHECK(hana::equal(
60 hana::fold_left(hana::tuple_t<x0, x1, x2>, f),
61 f(f(hana::type_c<x0>, hana::type_c<x1>), hana::type_c<x2>)
62 ));
63 BOOST_HANA_CONSTANT_CHECK(hana::equal(
64 hana::fold_left(hana::tuple_t<x0, x1, x2, x3>, f),
65 f(f(f(hana::type_c<x0>, hana::type_c<x1>), hana::type_c<x2>), hana::type_c<x3>)
66 ));
67 }
68 }