| 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/boost/mpl/list.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/is_empty.hpp> |
| 12 | #include <boost/hana/not.hpp> |
| 13 | #include <boost/hana/tuple.hpp> |
| 14 | #include <boost/hana/type.hpp> |
| 15 | |
| 16 | #include <laws/iterable.hpp> |
| 17 | |
| 18 | #include <boost/mpl/list.hpp> |
| 19 | namespace hana = boost::hana; |
| 20 | namespace mpl = boost::mpl; |
| 21 | |
| 22 | |
| 23 | struct t1; struct t2; struct t3; struct t4; |
| 24 | |
| 25 | int main() { |
| 26 | // front |
| 27 | { |
| 28 | BOOST_HANA_CONSTANT_CHECK(hana::equal( |
| 29 | hana::front(mpl::list<t1>{}), |
| 30 | hana::type_c<t1> |
| 31 | )); |
| 32 | BOOST_HANA_CONSTANT_CHECK(hana::equal( |
| 33 | hana::front(mpl::list<t1, t2>{}), |
| 34 | hana::type_c<t1> |
| 35 | )); |
| 36 | BOOST_HANA_CONSTANT_CHECK(hana::equal( |
| 37 | hana::front(mpl::list<t1, t2, t3>{}), |
| 38 | hana::type_c<t1> |
| 39 | )); |
| 40 | } |
| 41 | |
| 42 | // drop_front_exactly |
| 43 | { |
| 44 | BOOST_HANA_CONSTANT_CHECK(hana::equal( |
| 45 | hana::drop_front_exactly(mpl::list<t1>{}), |
| 46 | mpl::list<>{} |
| 47 | )); |
| 48 | BOOST_HANA_CONSTANT_CHECK(hana::equal( |
| 49 | hana::drop_front_exactly(mpl::list<t1, t2>{}), |
| 50 | mpl::list<t2>{} |
| 51 | )); |
| 52 | BOOST_HANA_CONSTANT_CHECK(hana::equal( |
| 53 | hana::drop_front_exactly(mpl::list<t1, t2, t3>{}), |
| 54 | mpl::list<t2, t3>{} |
| 55 | )); |
| 56 | |
| 57 | |
| 58 | BOOST_HANA_CONSTANT_CHECK(hana::equal( |
| 59 | hana::drop_front_exactly(mpl::list<t1, t2, t3>{}, hana::size_c<2>), |
| 60 | mpl::list<t3>{} |
| 61 | )); |
| 62 | |
| 63 | BOOST_HANA_CONSTANT_CHECK(hana::equal( |
| 64 | hana::drop_front_exactly(mpl::list<t1, t2, t3, t4>{}, hana::size_c<2>), |
| 65 | mpl::list<t3, t4>{} |
| 66 | )); |
| 67 | |
| 68 | BOOST_HANA_CONSTANT_CHECK(hana::equal( |
| 69 | hana::drop_front_exactly(mpl::list<t1, t2, t3, t4>{}, hana::size_c<3>), |
| 70 | mpl::list<t4>{} |
| 71 | )); |
| 72 | } |
| 73 | |
| 74 | // is_empty |
| 75 | { |
| 76 | BOOST_HANA_CONSTANT_CHECK(hana::is_empty(mpl::list<>{})); |
| 77 | BOOST_HANA_CONSTANT_CHECK(hana::is_empty(mpl::list0<>{})); |
| 78 | |
| 79 | BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::is_empty(mpl::list<t1>{}))); |
| 80 | BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::is_empty(mpl::list1<t1>{}))); |
| 81 | |
| 82 | BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::is_empty(mpl::list<t1, t2>{}))); |
| 83 | BOOST_HANA_CONSTANT_CHECK(hana::not_(hana::is_empty(mpl::list2<t1, t2>{}))); |
| 84 | } |
| 85 | |
| 86 | // laws |
| 87 | auto lists = hana::make_tuple( |
| 88 | mpl::list<>{} |
| 89 | , mpl::list<t1>{} |
| 90 | , mpl::list<t1, t2>{} |
| 91 | , mpl::list<t1, t2, t3>{} |
| 92 | , mpl::list<t1, t2, t3, t4>{} |
| 93 | ); |
| 94 | hana::test::TestIterable<hana::ext::boost::mpl::list_tag>{lists}; |
| 95 | } |
| 96 | |