• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
main()24 int main()
25 {
26     using boost::mp11::mp_list;
27     using boost::mp11::mp_take;
28     using boost::mp11::mp_take_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_take_c<L1, 0>, L1>));
35         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L1, mp_size_t<0>>, L1>));
36 
37         using L2 = mp_list<X1, X2, X3, X4, X5>;
38 
39         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L2, 0>, mp_list<>>));
40         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L2, 1>, mp_list<X1>>));
41         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L2, 2>, mp_list<X1, X2>>));
42         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L2, 3>, mp_list<X1, X2, X3>>));
43         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L2, 4>, mp_list<X1, X2, X3, X4>>));
44         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L2, 5>, mp_list<X1, X2, X3, X4, X5>>));
45 
46         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L2, mp_size_t<0>>, mp_list<>>));
47         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L2, mp_size_t<1>>, mp_list<X1>>));
48         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L2, mp_size_t<2>>, mp_list<X1, X2>>));
49         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L2, mp_size_t<3>>, mp_list<X1, X2, X3>>));
50         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L2, mp_size_t<4>>, mp_list<X1, X2, X3, X4>>));
51         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L2, mp_size_t<5>>, mp_list<X1, X2, X3, X4, X5>>));
52 
53         using L3 = mp_list<X1, X2, X3, X4, X5, X1, X2, X3, X4, X5, X1, X2, X3, X4, X5, X1, X2, X3, X4, X5>;
54 
55         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L3,  6>, mp_list<X1, X2, X3, X4, X5, X1>>));
56         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L3,  7>, mp_list<X1, X2, X3, X4, X5, X1, X2>>));
57         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L3,  8>, mp_list<X1, X2, X3, X4, X5, X1, X2, X3>>));
58         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L3,  9>, mp_list<X1, X2, X3, X4, X5, X1, X2, X3, X4>>));
59         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L3, 10>, mp_list<X1, X2, X3, X4, X5, X1, X2, X3, X4, X5>>));
60         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L3, 11>, mp_list<X1, X2, X3, X4, X5, X1, X2, X3, X4, X5, X1>>));
61 
62         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L3, mp_size_t< 6>>, mp_list<X1, X2, X3, X4, X5, X1>>));
63         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L3, mp_size_t< 7>>, mp_list<X1, X2, X3, X4, X5, X1, X2>>));
64         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L3, mp_size_t< 8>>, mp_list<X1, X2, X3, X4, X5, X1, X2, X3>>));
65         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L3, mp_size_t< 9>>, mp_list<X1, X2, X3, X4, X5, X1, X2, X3, X4>>));
66         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L3, mp_size_t<10>>, mp_list<X1, X2, X3, X4, X5, X1, X2, X3, X4, X5>>));
67         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L3, mp_size_t<11>>, mp_list<X1, X2, X3, X4, X5, X1, X2, X3, X4, X5, X1>>));
68     }
69 
70     {
71         using L1 = std::tuple<>;
72 
73         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L1, 0>, L1>));
74         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L1, mp_size_t<0>>, L1>));
75 
76         using L2 = std::tuple<X1, X2, X3, X4, X5>;
77 
78         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L2, 0>, std::tuple<>>));
79         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L2, 1>, std::tuple<X1>>));
80         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L2, 2>, std::tuple<X1, X2>>));
81         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L2, 3>, std::tuple<X1, X2, X3>>));
82         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L2, 4>, std::tuple<X1, X2, X3, X4>>));
83         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L2, 5>, std::tuple<X1, X2, X3, X4, X5>>));
84 
85         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L2, mp_size_t<0>>, std::tuple<>>));
86         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L2, mp_size_t<1>>, std::tuple<X1>>));
87         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L2, mp_size_t<2>>, std::tuple<X1, X2>>));
88         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L2, mp_size_t<3>>, std::tuple<X1, X2, X3>>));
89         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L2, mp_size_t<4>>, std::tuple<X1, X2, X3, X4>>));
90         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L2, mp_size_t<5>>, std::tuple<X1, X2, X3, X4, X5>>));
91 
92         using L3 = std::tuple<X1, X2, X3, X4, X5, X1, X2, X3, X4, X5, X1, X2, X3, X4, X5, X1, X2, X3, X4, X5>;
93 
94         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L3, 8>, std::tuple<X1, X2, X3, X4, X5, X1, X2, X3>>));
95         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L3, mp_size_t<9>>, std::tuple<X1, X2, X3, X4, X5, X1, X2, X3, X4>>));
96     }
97 
98     {
99         using L1 = std::pair<X1, X2>;
100 
101         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take_c<L1, 2>, L1>));
102         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_take<L1, mp_size_t<2>>, L1>));
103     }
104 
105     return boost::report_errors();
106 }
107