]>
Commit | Line | Data |
---|---|---|
f51cf556 | 1 | // Copyright Louis Dionne 2013-2022 |
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/assert.hpp> | |
6 | #include <boost/hana/contains.hpp> | |
7 | #include <boost/hana/equal.hpp> | |
8 | #include <boost/hana/fold_right.hpp> | |
9 | #include <boost/hana/map.hpp> | |
10 | #include <boost/hana/permutations.hpp> | |
11 | #include <boost/hana/transform.hpp> | |
12 | ||
13 | #include <laws/base.hpp> | |
14 | #include <support/seq.hpp> | |
15 | #include <support/minimal_product.hpp> | |
16 | namespace hana = boost::hana; | |
17 | ||
18 | ||
19 | template <int i> | |
20 | auto key() { return hana::test::ct_eq<i>{}; } | |
21 | ||
22 | template <int i> | |
23 | auto val() { return hana::test::ct_eq<-i>{}; } | |
24 | ||
25 | template <int i, int j> | |
26 | auto p() { return ::minimal_product(key<i>(), val<j>()); } | |
27 | ||
28 | struct undefined { }; | |
29 | ||
30 | int main() { | |
b32b8144 | 31 | auto sequence = ::seq; |
7c673cae | 32 | |
b32b8144 | 33 | // Use pointers to work around a Clang ICE |
7c673cae FG |
34 | hana::test::_injection<0> f{}; |
35 | auto* fp = &f; | |
36 | ||
37 | hana::test::ct_eq<999> state{}; | |
38 | auto* statep = &state; | |
39 | ||
40 | auto check = [=](auto ...pairs) { | |
41 | auto possible_results = hana::transform(hana::permutations(sequence(pairs...)), | |
42 | [=](auto xs) { | |
43 | return hana::fold_right(xs, *statep, *fp); | |
44 | } | |
45 | ); | |
46 | ||
47 | BOOST_HANA_CONSTANT_CHECK(hana::contains( | |
48 | possible_results, | |
49 | hana::fold_right(hana::make_map(pairs...), state, f) | |
50 | )); | |
51 | }; | |
52 | ||
53 | check(); | |
54 | check(p<1, 1>()); | |
55 | check(p<1, 1>(), p<2, 2>()); | |
56 | check(p<1, 1>(), p<2, 2>(), p<3, 3>()); | |
57 | check(p<1, 1>(), p<2, 2>(), p<3, 3>(), p<4, 4>()); | |
58 | } |