| 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/ext/std/array.hpp> |
| 6 | |
| 7 | #include <boost/hana/assert.hpp> |
| 8 | #include <boost/hana/drop_front_exactly.hpp> |
| 9 | #include <boost/hana/equal.hpp> |
| 10 | #include <boost/hana/front.hpp> |
| 11 | #include <boost/hana/integral_constant.hpp> |
| 12 | #include <boost/hana/is_empty.hpp> |
| 13 | #include <boost/hana/not.hpp> |
| 14 | #include <boost/hana/tuple.hpp> |
| 15 | |
| 16 | #include <laws/base.hpp> |
| 17 | #include <laws/iterable.hpp> |
| 18 | |
| 19 | #include <array> |
| 20 | namespace hana = boost::hana; |
| 21 | |
| 22 | |
| 23 | template <int ...i> |
| 24 | constexpr auto array() { return std::array<int, sizeof...(i)>{{i...}}; } |
| 25 | |
| 26 | int main() { |
| 27 | // is_empty |
| 28 | { |
| 29 | BOOST_HANA_CONSTANT_CHECK(hana::is_empty(array<>())); |
| 30 | BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::is_empty(array<0>()))); |
| 31 | BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::is_empty(array<0, 1>()))); |
| 32 | } |
| 33 | |
| 34 | // front |
| 35 | { |
| 36 | BOOST_HANA_CONSTEXPR_CHECK(hana::front(array<0>()) == 0); |
| 37 | BOOST_HANA_CONSTEXPR_CHECK(hana::front(array<0, 1>()) == 0); |
| 38 | BOOST_HANA_CONSTEXPR_CHECK(hana::front(array<0, 1, 2>()) == 0); |
| 39 | } |
| 40 | |
| 41 | // drop_front_exactly |
| 42 | { |
| 43 | BOOST_HANA_CONSTANT_CHECK(hana::equal( |
| 44 | hana::drop_front_exactly(array<0>()), |
| 45 | array<>() |
| 46 | )); |
| 47 | BOOST_HANA_CONSTEXPR_CHECK(hana::equal( |
| 48 | hana::drop_front_exactly(array<0, 1>()), |
| 49 | array<1>() |
| 50 | )); |
| 51 | BOOST_HANA_CONSTEXPR_CHECK(hana::equal( |
| 52 | hana::drop_front_exactly(array<0, 1, 2>()), |
| 53 | array<1, 2>() |
| 54 | )); |
| 55 | BOOST_HANA_CONSTEXPR_CHECK(hana::equal( |
| 56 | hana::drop_front_exactly(array<0, 1, 2, 3>()), |
| 57 | array<1, 2, 3>() |
| 58 | )); |
| 59 | |
| 60 | |
| 61 | BOOST_HANA_CONSTEXPR_CHECK(hana::equal( |
| 62 | hana::drop_front_exactly(array<0, 1, 2, 3>(), hana::size_c<2>), |
| 63 | array<2, 3>() |
| 64 | )); |
| 65 | |
| 66 | BOOST_HANA_CONSTEXPR_CHECK(hana::equal( |
| 67 | hana::drop_front_exactly(array<0, 1, 2, 3>(), hana::size_c<3>), |
| 68 | array<3>() |
| 69 | )); |
| 70 | } |
| 71 | |
| 72 | // laws |
| 73 | auto int_arrays = hana::make_tuple( |
| 74 | array<>() |
| 75 | , array<0>() |
| 76 | , array<0, 1>() |
| 77 | , array<0, 1, 2>() |
| 78 | , array<0, 1, 2, 3>() |
| 79 | , array<0, 1, 2, 3, 4>() |
| 80 | ); |
| 81 | |
| 82 | hana::test::TestIterable<hana::ext::std::array_tag>{int_arrays}; |
| 83 | } |
| 84 | |