| 1 | |
| 2 | // Copyright 2015 Peter Dimov. |
| 3 | // |
| 4 | // Distributed under the Boost Software License, Version 1.0. |
| 5 | // |
| 6 | // See accompanying file LICENSE_1_0.txt or copy at |
| 7 | // http://www.boost.org/LICENSE_1_0.txt |
| 8 | |
| 9 | |
| 10 | #include <boost/mp11/algorithm.hpp> |
| 11 | #include <boost/mp11/list.hpp> |
| 12 | #include <boost/mp11/integral.hpp> |
| 13 | #include <boost/core/lightweight_test_trait.hpp> |
| 14 | #include <type_traits> |
| 15 | #include <tuple> |
| 16 | #include <utility> |
| 17 | |
| 18 | struct X1 {}; |
| 19 | struct X2 {}; |
| 20 | struct X3 {}; |
| 21 | struct X4 {}; |
| 22 | struct X5 {}; |
| 23 | |
| 24 | int main() |
| 25 | { |
| 26 | using boost::mp11::mp_list; |
| 27 | using boost::mp11::mp_rotate_left; |
| 28 | using boost::mp11::mp_rotate_left_c; |
| 29 | using boost::mp11::mp_size_t; |
| 30 | |
| 31 | { |
| 32 | using L1 = mp_list<>; |
| 33 | |
| 34 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left_c<L1, 0>, L1>)); |
| 35 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left_c<L1, 1>, L1>)); |
| 36 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left_c<L1, 2>, L1>)); |
| 37 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left_c<L1, 3>, L1>)); |
| 38 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left_c<L1, 4>, L1>)); |
| 39 | |
| 40 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left<L1, mp_size_t<0>>, L1>)); |
| 41 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left<L1, mp_size_t<1>>, L1>)); |
| 42 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left<L1, mp_size_t<2>>, L1>)); |
| 43 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left<L1, mp_size_t<3>>, L1>)); |
| 44 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left<L1, mp_size_t<4>>, L1>)); |
| 45 | |
| 46 | using L2 = mp_list<X1, X2, X3, X4, X5>; |
| 47 | |
| 48 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left_c<L2, 0>, mp_list<X1, X2, X3, X4, X5>>)); |
| 49 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left_c<L2, 1>, mp_list<X2, X3, X4, X5, X1>>)); |
| 50 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left_c<L2, 2>, mp_list<X3, X4, X5, X1, X2>>)); |
| 51 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left_c<L2, 3>, mp_list<X4, X5, X1, X2, X3>>)); |
| 52 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left_c<L2, 4>, mp_list<X5, X1, X2, X3, X4>>)); |
| 53 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left_c<L2, 5>, mp_list<X1, X2, X3, X4, X5>>)); |
| 54 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left_c<L2, 6>, mp_list<X2, X3, X4, X5, X1>>)); |
| 55 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left_c<L2, 7>, mp_list<X3, X4, X5, X1, X2>>)); |
| 56 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left_c<L2, 8>, mp_list<X4, X5, X1, X2, X3>>)); |
| 57 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left_c<L2, 9>, mp_list<X5, X1, X2, X3, X4>>)); |
| 58 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left_c<L2, 10>, mp_list<X1, X2, X3, X4, X5>>)); |
| 59 | |
| 60 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left<L2, mp_size_t<0>>, mp_list<X1, X2, X3, X4, X5>>)); |
| 61 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left<L2, mp_size_t<1>>, mp_list<X2, X3, X4, X5, X1>>)); |
| 62 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left<L2, mp_size_t<2>>, mp_list<X3, X4, X5, X1, X2>>)); |
| 63 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left<L2, mp_size_t<3>>, mp_list<X4, X5, X1, X2, X3>>)); |
| 64 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left<L2, mp_size_t<4>>, mp_list<X5, X1, X2, X3, X4>>)); |
| 65 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left<L2, mp_size_t<5>>, mp_list<X1, X2, X3, X4, X5>>)); |
| 66 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left<L2, mp_size_t<6>>, mp_list<X2, X3, X4, X5, X1>>)); |
| 67 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left<L2, mp_size_t<7>>, mp_list<X3, X4, X5, X1, X2>>)); |
| 68 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left<L2, mp_size_t<8>>, mp_list<X4, X5, X1, X2, X3>>)); |
| 69 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left<L2, mp_size_t<9>>, mp_list<X5, X1, X2, X3, X4>>)); |
| 70 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left<L2, mp_size_t<10>>, mp_list<X1, X2, X3, X4, X5>>)); |
| 71 | } |
| 72 | |
| 73 | { |
| 74 | using L1 = std::tuple<>; |
| 75 | |
| 76 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left_c<L1, 0>, L1>)); |
| 77 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left_c<L1, 1>, L1>)); |
| 78 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left_c<L1, 2>, L1>)); |
| 79 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left_c<L1, 3>, L1>)); |
| 80 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left_c<L1, 4>, L1>)); |
| 81 | |
| 82 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left<L1, mp_size_t<0>>, L1>)); |
| 83 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left<L1, mp_size_t<1>>, L1>)); |
| 84 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left<L1, mp_size_t<2>>, L1>)); |
| 85 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left<L1, mp_size_t<3>>, L1>)); |
| 86 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left<L1, mp_size_t<4>>, L1>)); |
| 87 | |
| 88 | using L2 = std::tuple<X1, X2, X3, X4, X5>; |
| 89 | |
| 90 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left_c<L2, 0>, std::tuple<X1, X2, X3, X4, X5>>)); |
| 91 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left_c<L2, 1>, std::tuple<X2, X3, X4, X5, X1>>)); |
| 92 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left_c<L2, 2>, std::tuple<X3, X4, X5, X1, X2>>)); |
| 93 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left_c<L2, 3>, std::tuple<X4, X5, X1, X2, X3>>)); |
| 94 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left_c<L2, 4>, std::tuple<X5, X1, X2, X3, X4>>)); |
| 95 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left_c<L2, 5>, std::tuple<X1, X2, X3, X4, X5>>)); |
| 96 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left_c<L2, 6>, std::tuple<X2, X3, X4, X5, X1>>)); |
| 97 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left_c<L2, 7>, std::tuple<X3, X4, X5, X1, X2>>)); |
| 98 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left_c<L2, 8>, std::tuple<X4, X5, X1, X2, X3>>)); |
| 99 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left_c<L2, 9>, std::tuple<X5, X1, X2, X3, X4>>)); |
| 100 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left_c<L2, 10>, std::tuple<X1, X2, X3, X4, X5>>)); |
| 101 | |
| 102 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left<L2, mp_size_t<0>>, std::tuple<X1, X2, X3, X4, X5>>)); |
| 103 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left<L2, mp_size_t<1>>, std::tuple<X2, X3, X4, X5, X1>>)); |
| 104 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left<L2, mp_size_t<2>>, std::tuple<X3, X4, X5, X1, X2>>)); |
| 105 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left<L2, mp_size_t<3>>, std::tuple<X4, X5, X1, X2, X3>>)); |
| 106 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left<L2, mp_size_t<4>>, std::tuple<X5, X1, X2, X3, X4>>)); |
| 107 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left<L2, mp_size_t<5>>, std::tuple<X1, X2, X3, X4, X5>>)); |
| 108 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left<L2, mp_size_t<6>>, std::tuple<X2, X3, X4, X5, X1>>)); |
| 109 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left<L2, mp_size_t<7>>, std::tuple<X3, X4, X5, X1, X2>>)); |
| 110 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left<L2, mp_size_t<8>>, std::tuple<X4, X5, X1, X2, X3>>)); |
| 111 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left<L2, mp_size_t<9>>, std::tuple<X5, X1, X2, X3, X4>>)); |
| 112 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left<L2, mp_size_t<10>>, std::tuple<X1, X2, X3, X4, X5>>)); |
| 113 | } |
| 114 | |
| 115 | { |
| 116 | using L1 = std::pair<X1, X2>; |
| 117 | |
| 118 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left_c<L1, 0>, L1>)); |
| 119 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left_c<L1, 2>, L1>)); |
| 120 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left_c<L1, 4>, L1>)); |
| 121 | |
| 122 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left_c<L1, 1>, std::pair<X2, X1>>)); |
| 123 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left_c<L1, 3>, std::pair<X2, X1>>)); |
| 124 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left_c<L1, 5>, std::pair<X2, X1>>)); |
| 125 | |
| 126 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left<L1, mp_size_t<0>>, L1>)); |
| 127 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left<L1, mp_size_t<2>>, L1>)); |
| 128 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left<L1, mp_size_t<4>>, L1>)); |
| 129 | |
| 130 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left<L1, mp_size_t<1>>, std::pair<X2, X1>>)); |
| 131 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left<L1, mp_size_t<3>>, std::pair<X2, X1>>)); |
| 132 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_rotate_left<L1, mp_size_t<5>>, std::pair<X2, X1>>)); |
| 133 | } |
| 134 | |
| 135 | return boost::report_errors(); |
| 136 | } |
| 137 | |