| 1 | // Copyright Louis Dionne 2013-2022 |
| 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/unpack.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/minimal_product.hpp> |
| 15 | #include <support/seq.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() { |
| 31 | auto sequence = ::seq; |
| 32 | hana::test::_injection<0> f{}; |
| 33 | |
| 34 | auto check = [=](auto ...pairs) { |
| 35 | auto possible_results = hana::transform(hana::permutations(sequence(pairs...)), |
| 36 | [=](auto xs) { return hana::unpack(xs, f); } |
| 37 | ); |
| 38 | |
| 39 | BOOST_HANA_CONSTANT_CHECK(hana::contains( |
| 40 | possible_results, |
| 41 | hana::unpack(hana::make_map(pairs...), f) |
| 42 | )); |
| 43 | }; |
| 44 | |
| 45 | check(); |
| 46 | check(p<1, 1>()); |
| 47 | check(p<1, 1>(), p<2, 2>()); |
| 48 | check(p<1, 1>(), p<2, 2>(), p<3, 3>()); |
| 49 | check(p<1, 1>(), p<2, 2>(), p<3, 3>(), p<4, 4>()); |
| 50 | } |
| 51 | |