• 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/utility.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 
23 struct Y1 {};
24 struct Y2 {};
25 struct Y3 {};
26 struct Y4 {};
27 
28 struct Z1 {};
29 struct Z2 {};
30 struct Z3 {};
31 struct Z4 {};
32 
33 struct U1 {};
34 struct U2 {};
35 
36 struct V1 {};
37 struct V2 {};
38 
39 struct W1 {};
40 struct W2 {};
41 
42 using boost::mp11::mp_quote;
43 using boost::mp11::mp_list;
44 
45 template<class T> using add_pointer = typename std::add_pointer<T>::type;
46 using Q_add_pointer = mp_quote<add_pointer>;
47 
48 template<class T, class U> using is_same = typename std::is_same<T, U>::type;
49 using Q_is_same = mp_quote<is_same>;
50 
51 using Q_mp_list = mp_quote<mp_list>;
52 using Q_std_tuple = mp_quote<std::tuple>;
53 using Q_std_pair = mp_quote<std::pair>;
54 
main()55 int main()
56 {
57     using boost::mp11::mp_transform_q;
58 
59     using L1 = mp_list<X1, X2, X3, X4>;
60 
61     BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_mp_list, L1>, mp_list<mp_list<X1>, mp_list<X2>, mp_list<X3>, mp_list<X4>>>));
62     BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_std_tuple, L1>, mp_list<std::tuple<X1>, std::tuple<X2>, std::tuple<X3>, std::tuple<X4>>>));
63     BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_add_pointer, L1>, mp_list<X1*, X2*, X3*, X4*>>));
64 
65     using L2 = std::tuple<Y1, Y2, Y3, Y4>;
66 
67     BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_mp_list, L1, L2>, mp_list<mp_list<X1, Y1>, mp_list<X2, Y2>, mp_list<X3, Y3>, mp_list<X4, Y4>>>));
68     BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_std_tuple, L1, L2>, mp_list<std::tuple<X1, Y1>, std::tuple<X2, Y2>, std::tuple<X3, Y3>, std::tuple<X4, Y4>>>));
69     BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_std_pair, L1, L2>, mp_list<std::pair<X1, Y1>, std::pair<X2, Y2>, std::pair<X3, Y3>, std::pair<X4, Y4>>>));
70 
71     using L3 = mp_list<Z1, Z2, Z3, Z4>;
72 
73     BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_mp_list, L1, L2, L3>, mp_list<mp_list<X1, Y1, Z1>, mp_list<X2, Y2, Z2>, mp_list<X3, Y3, Z3>, mp_list<X4, Y4, Z4>>>));
74     BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_std_tuple, L1, L2, L3>, mp_list<std::tuple<X1, Y1, Z1>, std::tuple<X2, Y2, Z2>, std::tuple<X3, Y3, Z3>, std::tuple<X4, Y4, Z4>>>));
75 
76     //
77 
78     using L4 = std::tuple<X1, Y2, X3, Y4>;
79 
80     BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_is_same, L1, L1>, mp_list<std::true_type, std::true_type, std::true_type, std::true_type>>));
81     BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_is_same, L1, L2>, mp_list<std::false_type, std::false_type, std::false_type, std::false_type>>));
82     BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_is_same, L1, L4>, mp_list<std::true_type, std::false_type, std::true_type, std::false_type>>));
83 
84     //
85 
86     using L5 = std::pair<X1, X2>;
87     using L6 = std::pair<Y1, Y2>;
88     using L7 = std::pair<X1, Y2>;
89 
90     BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_mp_list, L5>, std::pair<mp_list<X1>, mp_list<X2>>>));
91     BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_mp_list, L5, L6>, std::pair<mp_list<X1, Y1>, mp_list<X2, Y2>>>));
92     BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_mp_list, L5, L6, L7>, std::pair<mp_list<X1, Y1, X1>, mp_list<X2, Y2, Y2>>>));
93 
94     BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_add_pointer, L5>, std::pair<X1*, X2*>>));
95 
96     BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_is_same, L5, L5>, std::pair<std::true_type, std::true_type>>));
97     BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_is_same, L5, L6>, std::pair<std::false_type, std::false_type>>));
98     BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_is_same, L5, L7>, std::pair<std::true_type, std::false_type>>));
99 
100     //
101 
102     using L8 = std::pair<Z1, Z2>;
103     using L9 = std::pair<U1, U2>;
104     using L10 = std::pair<V1, V2>;
105     using L11 = std::pair<W1, W2>;
106 
107     BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_std_tuple, L5, L6, L8, L9>, std::pair<std::tuple<X1, Y1, Z1, U1>, std::tuple<X2, Y2, Z2, U2>>>));
108     BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_std_tuple, L5, L6, L8, L9, L10>, std::pair<std::tuple<X1, Y1, Z1, U1, V1>, std::tuple<X2, Y2, Z2, U2, V2>>>));
109     BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_q<Q_std_tuple, L5, L6, L8, L9, L10, L11>, std::pair<std::tuple<X1, Y1, Z1, U1, V1, W1>, std::tuple<X2, Y2, Z2, U2, V2, W2>>>));
110 
111     //
112 
113     return boost::report_errors();
114 }
115