Imported Upstream version 1.64.0
[platform/upstream/boost.git] / libs / hana / test / detail / variadic / foldr1.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/detail/variadic/foldr1.hpp>
6
7 #include <boost/hana/assert.hpp>
8 #include <boost/hana/equal.hpp>
9 #include <boost/hana/value.hpp>
10
11 #include <laws/base.hpp>
12 namespace hana = boost::hana;
13
14
15 struct undefined { };
16
17 template <int i>
18 using x = hana::test::ct_eq<i>;
19
20 // We do not use test::_injection here because comparing the result would
21 // blow away the template recursion limit.
22 struct f_t {
23     template <typename X, typename Y>
24     constexpr auto operator()(X const&, Y const&) {
25         return x<hana::value<X>() - hana::value<Y>()>{};
26     }
27 };
28
29 int main() {
30     using hana::detail::variadic::foldr1;
31     f_t f{};
32
33     BOOST_HANA_CONSTANT_CHECK(hana::equal(
34         foldr1(undefined{}, x<0>{}),
35         x<0>{}
36     ));
37
38     BOOST_HANA_CONSTANT_CHECK(hana::equal(
39         foldr1(f, x<0>{}, x<1>{}),
40         f(x<0>{}, x<1>{})
41     ));
42
43     BOOST_HANA_CONSTANT_CHECK(hana::equal(
44         foldr1(f, x<0>{}, x<1>{}, x<2>{}),
45         f(x<0>{}, f(x<1>{}, x<2>{}))
46     ));
47
48     BOOST_HANA_CONSTANT_CHECK(hana::equal(
49         foldr1(f, x<0>{}, x<1>{}, x<2>{}, x<3>{}),
50         f(x<0>{}, f(x<1>{}, f(x<2>{}, x<3>{})))
51     ));
52
53     BOOST_HANA_CONSTANT_CHECK(hana::equal(
54         foldr1(f, x<0>{}, x<1>{}, x<2>{}, x<3>{}, x<4>{}),
55         f(x<0>{}, f(x<1>{}, f(x<2>{}, f(x<3>{}, x<4>{}))))
56     ));
57
58     BOOST_HANA_CONSTANT_CHECK(hana::equal(
59         foldr1(f, x<0>{}, x<1>{}, x<2>{}, x<3>{}, x<4>{}, x<5>{}),
60         f(x<0>{}, f(x<1>{}, f(x<2>{}, f(x<3>{}, f(x<4>{}, x<5>{})))))
61     ));
62
63     BOOST_HANA_CONSTANT_CHECK(hana::equal(
64         foldr1(f, x<0>{}, x<1>{}, x<2>{}, x<3>{}, x<4>{}, x<5>{}, x<6>{}),
65         f(x<0>{}, f(x<1>{}, f(x<2>{}, f(x<3>{}, f(x<4>{}, f(x<5>{}, x<6>{}))))))
66     ));
67
68     BOOST_HANA_CONSTANT_CHECK(hana::equal(
69         foldr1(f, x<0>{}, x<1>{}, x<2>{}, x<3>{}, x<4>{}, x<5>{}, x<6>{}, x<7>{}),
70         f(x<0>{}, f(x<1>{}, f(x<2>{}, f(x<3>{}, f(x<4>{}, f(x<5>{}, f(x<6>{}, x<7>{}
71         )))))))
72     ));
73
74     BOOST_HANA_CONSTANT_CHECK(hana::equal(
75         foldr1(f, x<0>{}, x<1>{}, x<2>{}, x<3>{}, x<4>{}, x<5>{}, x<6>{}, x<7>{}, x<8>{}),
76         f(x<0>{}, f(x<1>{}, f(x<2>{}, f(x<3>{}, f(x<4>{}, f(x<5>{}, f(x<6>{}, f(x<7>{}, x<8>{}
77         ))))))))
78     ));
79
80
81     BOOST_HANA_CONSTANT_CHECK(hana::equal(
82         foldr1(f, x<1>{}, x<2>{}, x<3>{},  x<4>{},  x<5>{},  x<6>{}, x<7>{},
83                   x<8>{}, x<9>{}, x<10>{}, x<11>{}, x<12>{}, x<13>{}),
84         f(x<1>{}, f(x<2>{}, f(x<3>{}, f(x<4>{}, f(x<5>{}, f(x<6>{}, f(x<7>{},
85         f(x<8>{}, f(x<9>{}, f(x<10>{}, f(x<11>{}, f(x<12>{}, x<13>{}
86         ))))))))))))
87     ));
88
89     BOOST_HANA_CONSTANT_CHECK(hana::equal(
90         foldr1(f, x<1>{}, x<2>{}, x<3>{},  x<4>{},  x<5>{},  x<6>{}, x<7>{},
91                   x<8>{}, x<9>{}, x<10>{}, x<11>{}, x<12>{}, x<13>{}, x<14>{}),
92         f(x<1>{}, f(x<2>{}, f(x<3>{}, f(x<4>{}, f(x<5>{}, f(x<6>{}, f(x<7>{},
93         f(x<8>{}, f(x<9>{}, f(x<10>{}, f(x<11>{}, f(x<12>{}, f(x<13>{}, x<14>{}
94         )))))))))))))
95     ));
96
97     BOOST_HANA_CONSTANT_CHECK(hana::equal(
98         foldr1(f, x<1>{}, x<2>{}, x<3>{},  x<4>{},  x<5>{},  x<6>{}, x<7>{},
99                   x<8>{}, x<9>{}, x<10>{}, x<11>{}, x<12>{}, x<13>{}, x<14>{},
100                   x<15>{}),
101         f(x<1>{}, f(x<2>{}, f(x<3>{}, f(x<4>{}, f(x<5>{}, f(x<6>{}, f(x<7>{},
102         f(x<8>{}, f(x<9>{}, f(x<10>{}, f(x<11>{}, f(x<12>{}, f(x<13>{}, f(x<14>{}, x<15>{}
103         ))))))))))))))
104     ));
105
106
107     BOOST_HANA_CONSTANT_CHECK(hana::equal(
108         foldr1(f, x<1>{},  x<2>{},  x<3>{},  x<4>{},  x<5>{},  x<6>{},  x<7>{},
109                   x<8>{},  x<9>{},  x<10>{}, x<11>{}, x<12>{}, x<13>{}, x<14>{},
110                   x<15>{}, x<16>{}, x<17>{}, x<18>{}, x<19>{}, x<20>{}, x<21>{},
111                   x<22>{}, x<23>{}, x<24>{}, x<25>{}, x<26>{}, x<27>{}),
112         f(x<1>{},  f(x<2>{},  f(x<3>{},  f(x<4>{},  f(x<5>{},  f(x<6>{},  f(x<7>{},
113         f(x<8>{},  f(x<9>{},  f(x<10>{}, f(x<11>{}, f(x<12>{}, f(x<13>{}, f(x<14>{},
114         f(x<15>{}, f(x<16>{}, f(x<17>{}, f(x<18>{}, f(x<19>{}, f(x<20>{}, f(x<21>{},
115         f(x<22>{}, f(x<23>{}, f(x<24>{}, f(x<25>{}, f(x<26>{}, x<27>{}
116         ))))))))))))))))))))))))))
117     ));
118
119     BOOST_HANA_CONSTANT_CHECK(hana::equal(
120         foldr1(f, x<1>{},  x<2>{},  x<3>{},  x<4>{},  x<5>{},  x<6>{},  x<7>{},
121                   x<8>{},  x<9>{},  x<10>{}, x<11>{}, x<12>{}, x<13>{}, x<14>{},
122                   x<15>{}, x<16>{}, x<17>{}, x<18>{}, x<19>{}, x<20>{}, x<21>{},
123                   x<22>{}, x<23>{}, x<24>{}, x<25>{}, x<26>{}, x<27>{}, x<28>{}),
124         f(x<1>{},  f(x<2>{},  f(x<3>{},  f(x<4>{},  f(x<5>{},  f(x<6>{},  f(x<7>{},
125         f(x<8>{},  f(x<9>{},  f(x<10>{}, f(x<11>{}, f(x<12>{}, f(x<13>{}, f(x<14>{},
126         f(x<15>{}, f(x<16>{}, f(x<17>{}, f(x<18>{}, f(x<19>{}, f(x<20>{}, f(x<21>{},
127         f(x<22>{}, f(x<23>{}, f(x<24>{}, f(x<25>{}, f(x<26>{}, f(x<27>{},   x<28>{}
128         )))))))))))))))))))))))))))
129     ));
130
131     BOOST_HANA_CONSTANT_CHECK(hana::equal(
132         foldr1(f, x<1>{},  x<2>{},  x<3>{},  x<4>{},  x<5>{},  x<6>{},  x<7>{},
133                   x<8>{},  x<9>{},  x<10>{}, x<11>{}, x<12>{}, x<13>{}, x<14>{},
134                   x<15>{}, x<16>{}, x<17>{}, x<18>{}, x<19>{}, x<20>{}, x<21>{},
135                   x<22>{}, x<23>{}, x<24>{}, x<25>{}, x<26>{}, x<27>{}, x<28>{},
136                   x<29>{}),
137         f(x<1>{},  f(x<2>{},  f(x<3>{},  f(x<4>{},  f(x<5>{},  f(x<6>{},  f(x<7>{},
138         f(x<8>{},  f(x<9>{},  f(x<10>{}, f(x<11>{}, f(x<12>{}, f(x<13>{}, f(x<14>{},
139         f(x<15>{}, f(x<16>{}, f(x<17>{}, f(x<18>{}, f(x<19>{}, f(x<20>{}, f(x<21>{},
140         f(x<22>{}, f(x<23>{}, f(x<24>{}, f(x<25>{}, f(x<26>{}, f(x<27>{}, f(x<28>{},
141           x<29>{}
142         ))))))))))))))))))))))))))))
143     ));
144
145
146     BOOST_HANA_CONSTANT_CHECK(hana::equal(
147         foldr1(f, x<1>{},  x<2>{},  x<3>{},  x<4>{},  x<5>{},  x<6>{},  x<7>{},
148                   x<8>{},  x<9>{},  x<10>{}, x<11>{}, x<12>{}, x<13>{}, x<14>{},
149                   x<15>{}, x<16>{}, x<17>{}, x<18>{}, x<19>{}, x<20>{}, x<21>{},
150                   x<22>{}, x<23>{}, x<24>{}, x<25>{}, x<26>{}, x<27>{}, x<28>{},
151                   x<29>{}, x<30>{}, x<31>{}, x<32>{}, x<33>{}, x<34>{}, x<35>{},
152                   x<36>{}, x<37>{}, x<38>{}, x<39>{}, x<40>{}, x<41>{}, x<42>{},
153                   x<43>{}, x<44>{}, x<45>{}, x<46>{}, x<47>{}, x<48>{}, x<49>{},
154                   x<50>{}, x<51>{}, x<52>{}, x<53>{}, x<54>{}, x<55>{}),
155         f(x<1>{},  f(x<2>{},  f(x<3>{},  f(x<4>{},  f(x<5>{},  f(x<6>{},  f(x<7>{},
156         f(x<8>{},  f(x<9>{},  f(x<10>{}, f(x<11>{}, f(x<12>{}, f(x<13>{}, f(x<14>{},
157         f(x<15>{}, f(x<16>{}, f(x<17>{}, f(x<18>{}, f(x<19>{}, f(x<20>{}, f(x<21>{},
158         f(x<22>{}, f(x<23>{}, f(x<24>{}, f(x<25>{}, f(x<26>{}, f(x<27>{}, f(x<28>{},
159         f(x<29>{}, f(x<30>{}, f(x<31>{}, f(x<32>{}, f(x<33>{}, f(x<34>{}, f(x<35>{},
160         f(x<36>{}, f(x<37>{}, f(x<38>{}, f(x<39>{}, f(x<40>{}, f(x<41>{}, f(x<42>{},
161         f(x<43>{}, f(x<44>{}, f(x<45>{}, f(x<46>{}, f(x<47>{}, f(x<48>{}, f(x<49>{},
162         f(x<50>{}, f(x<51>{}, f(x<52>{}, f(x<53>{}, f(x<54>{}, x<55>{}
163         ))))))))))))))))))))))))))))))))))))))))))))))))))))))
164     ));
165
166     BOOST_HANA_CONSTANT_CHECK(hana::equal(
167         foldr1(f, x<1>{},  x<2>{},  x<3>{},  x<4>{},  x<5>{},  x<6>{},  x<7>{},
168                   x<8>{},  x<9>{},  x<10>{}, x<11>{}, x<12>{}, x<13>{}, x<14>{},
169                   x<15>{}, x<16>{}, x<17>{}, x<18>{}, x<19>{}, x<20>{}, x<21>{},
170                   x<22>{}, x<23>{}, x<24>{}, x<25>{}, x<26>{}, x<27>{}, x<28>{},
171                   x<29>{}, x<30>{}, x<31>{}, x<32>{}, x<33>{}, x<34>{}, x<35>{},
172                   x<36>{}, x<37>{}, x<38>{}, x<39>{}, x<40>{}, x<41>{}, x<42>{},
173                   x<43>{}, x<44>{}, x<45>{}, x<46>{}, x<47>{}, x<48>{}, x<49>{},
174                   x<50>{}, x<51>{}, x<52>{}, x<53>{}, x<54>{}, x<55>{}, x<56>{}),
175         f(x<1>{},  f(x<2>{},  f(x<3>{},  f(x<4>{},  f(x<5>{},  f(x<6>{},  f(x<7>{},
176         f(x<8>{},  f(x<9>{},  f(x<10>{}, f(x<11>{}, f(x<12>{}, f(x<13>{}, f(x<14>{},
177         f(x<15>{}, f(x<16>{}, f(x<17>{}, f(x<18>{}, f(x<19>{}, f(x<20>{}, f(x<21>{},
178         f(x<22>{}, f(x<23>{}, f(x<24>{}, f(x<25>{}, f(x<26>{}, f(x<27>{}, f(x<28>{},
179         f(x<29>{}, f(x<30>{}, f(x<31>{}, f(x<32>{}, f(x<33>{}, f(x<34>{}, f(x<35>{},
180         f(x<36>{}, f(x<37>{}, f(x<38>{}, f(x<39>{}, f(x<40>{}, f(x<41>{}, f(x<42>{},
181         f(x<43>{}, f(x<44>{}, f(x<45>{}, f(x<46>{}, f(x<47>{}, f(x<48>{}, f(x<49>{},
182         f(x<50>{}, f(x<51>{}, f(x<52>{}, f(x<53>{}, f(x<54>{}, f(x<55>{},   x<56>{}
183         )))))))))))))))))))))))))))))))))))))))))))))))))))))))
184     ));
185
186     BOOST_HANA_CONSTANT_CHECK(hana::equal(
187         foldr1(f, x<1>{},  x<2>{},  x<3>{},  x<4>{},  x<5>{},  x<6>{},  x<7>{},
188                   x<8>{},  x<9>{},  x<10>{}, x<11>{}, x<12>{}, x<13>{}, x<14>{},
189                   x<15>{}, x<16>{}, x<17>{}, x<18>{}, x<19>{}, x<20>{}, x<21>{},
190                   x<22>{}, x<23>{}, x<24>{}, x<25>{}, x<26>{}, x<27>{}, x<28>{},
191                   x<29>{}, x<30>{}, x<31>{}, x<32>{}, x<33>{}, x<34>{}, x<35>{},
192                   x<36>{}, x<37>{}, x<38>{}, x<39>{}, x<40>{}, x<41>{}, x<42>{},
193                   x<43>{}, x<44>{}, x<45>{}, x<46>{}, x<47>{}, x<48>{}, x<49>{},
194                   x<50>{}, x<51>{}, x<52>{}, x<53>{}, x<54>{}, x<55>{}, x<56>{},
195                   x<57>{}),
196         f(x<1>{},  f(x<2>{},  f(x<3>{},  f(x<4>{},  f(x<5>{},  f(x<6>{},  f(x<7>{},
197         f(x<8>{},  f(x<9>{},  f(x<10>{}, f(x<11>{}, f(x<12>{}, f(x<13>{}, f(x<14>{},
198         f(x<15>{}, f(x<16>{}, f(x<17>{}, f(x<18>{}, f(x<19>{}, f(x<20>{}, f(x<21>{},
199         f(x<22>{}, f(x<23>{}, f(x<24>{}, f(x<25>{}, f(x<26>{}, f(x<27>{}, f(x<28>{},
200         f(x<29>{}, f(x<30>{}, f(x<31>{}, f(x<32>{}, f(x<33>{}, f(x<34>{}, f(x<35>{},
201         f(x<36>{}, f(x<37>{}, f(x<38>{}, f(x<39>{}, f(x<40>{}, f(x<41>{}, f(x<42>{},
202         f(x<43>{}, f(x<44>{}, f(x<45>{}, f(x<46>{}, f(x<47>{}, f(x<48>{}, f(x<49>{},
203         f(x<50>{}, f(x<51>{}, f(x<52>{}, f(x<53>{}, f(x<54>{}, f(x<55>{}, f(x<56>{},
204           x<57>{}
205         ))))))))))))))))))))))))))))))))))))))))))))))))))))))))
206     ));
207 }