| 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/at_key.hpp> |
| 7 | #include <boost/hana/equal.hpp> |
| 8 | #include <boost/hana/map.hpp> |
| 9 | |
| 10 | #include <laws/base.hpp> |
| 11 | #include <support/minimal_product.hpp> |
| 12 | |
| 13 | #include <utility> |
| 14 | namespace hana = boost::hana; |
| 15 | |
| 16 | |
| 17 | template <int i> |
| 18 | auto key() { return hana::test::ct_eq<i>{}; } |
| 19 | |
| 20 | template <int i> |
| 21 | auto val() { return hana::test::ct_eq<-i>{}; } |
| 22 | |
| 23 | template <int i, int j> |
| 24 | auto p() { return ::minimal_product(key<i>(), val<j>()); } |
| 25 | |
| 26 | int main() { |
| 27 | BOOST_HANA_CONSTANT_CHECK(hana::equal( |
| 28 | hana::at_key(hana::make_map(p<0, 0>()), key<0>()), |
| 29 | val<0>() |
| 30 | )); |
| 31 | |
| 32 | BOOST_HANA_CONSTANT_CHECK(hana::equal( |
| 33 | hana::at_key(hana::make_map(p<0, 0>(), p<1,1>()), key<0>()), |
| 34 | val<0>() |
| 35 | )); |
| 36 | BOOST_HANA_CONSTANT_CHECK(hana::equal( |
| 37 | hana::at_key(hana::make_map(p<0, 0>(), p<1,1>()), key<1>()), |
| 38 | val<1>() |
| 39 | )); |
| 40 | |
| 41 | BOOST_HANA_CONSTANT_CHECK(hana::equal( |
| 42 | hana::at_key(hana::make_map(p<0, 0>(), p<1,1>(), p<2,2>()), key<0>()), |
| 43 | val<0>() |
| 44 | )); |
| 45 | BOOST_HANA_CONSTANT_CHECK(hana::equal( |
| 46 | hana::at_key(hana::make_map(p<0, 0>(), p<1,1>(), p<2,2>()), key<1>()), |
| 47 | val<1>() |
| 48 | )); |
| 49 | BOOST_HANA_CONSTANT_CHECK(hana::equal( |
| 50 | hana::at_key(hana::make_map(p<0, 0>(), p<1,1>(), p<2,2>()), key<2>()), |
| 51 | val<2>() |
| 52 | )); |
| 53 | |
| 54 | // check operators |
| 55 | auto m = hana::make_map(p<2, 2>(), p<1, 1>()); |
| 56 | auto const const_m = hana::make_map(p<2, 2>(), p<1, 1>()); |
| 57 | BOOST_HANA_CONSTANT_CHECK(hana::equal(m[key<1>()], val<1>())); |
| 58 | BOOST_HANA_CONSTANT_CHECK(hana::equal(const_m[key<1>()], val<1>())); |
| 59 | BOOST_HANA_CONSTANT_CHECK(hana::equal(std::move(m)[key<1>()], val<1>())); |
| 60 | } |
| 61 | |