• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 // Copyright 2019 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/core/lightweight_test_trait.hpp>
13 #include <type_traits>
14 #include <tuple>
15 
main()16 int main()
17 {
18     using boost::mp11::mp_list;
19     using boost::mp11::mp_flatten;
20     using boost::mp11::mp_transform;
21 
22     {
23         using L1 = mp_list<>;
24         using L2 = mp_list<void>;
25         using L3 = mp_list<void, void>;
26 
27         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_flatten<L1>, L1>));
28         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_flatten<L2>, L2>));
29         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_flatten<L3>, L3>));
30 
31         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_flatten<L1, L1>, L1>));
32         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_flatten<L2, L2>, L2>));
33         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_flatten<L3, L3>, L3>));
34 
35         using L4 = mp_transform<mp_list, L3>;
36 
37         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_flatten<L4>, L3>));
38         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_flatten<L4, mp_list<>>, L3>));
39         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_flatten<L4, std::tuple<>>, L4>));
40 
41         using L5 = mp_transform<std::tuple, L3>;
42 
43         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_flatten<L5>, L5>));
44         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_flatten<L5, mp_list<>>, L5>));
45         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_flatten<L5, std::tuple<>>, L3>));
46     }
47 
48     {
49         using L1 = std::tuple<>;
50         using L2 = std::tuple<void>;
51         using L3 = std::tuple<void, void>;
52 
53         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_flatten<L1>, L1>));
54         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_flatten<L2>, L2>));
55         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_flatten<L3>, L3>));
56 
57         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_flatten<L1, L1>, L1>));
58         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_flatten<L2, L2>, L2>));
59         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_flatten<L3, L3>, L3>));
60 
61         using L4 = mp_transform<mp_list, L3>;
62 
63         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_flatten<L4>, L4>));
64         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_flatten<L4, mp_list<>>, L3>));
65         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_flatten<L4, std::tuple<>>, L4>));
66 
67         using L5 = mp_transform<std::tuple, L3>;
68 
69         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_flatten<L5>, L3>));
70         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_flatten<L5, mp_list<>>, L5>));
71         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_flatten<L5, std::tuple<>>, L3>));
72     }
73 
74     {
75         using L1 = mp_list<std::tuple<>, int, mp_list<>, void, mp_list<char, double>, std::pair<int, void>>;
76 
77         using R1 = mp_flatten<L1>;
78         BOOST_TEST_TRAIT_TRUE((std::is_same<R1, mp_list<std::tuple<>, int, void, char, double, std::pair<int, void>>>));
79 
80         using R2 = mp_flatten<L1, std::pair<void, void>>;
81         BOOST_TEST_TRAIT_TRUE((std::is_same<R2, mp_list<std::tuple<>, int, mp_list<>, void, mp_list<char, double>, int, void>>));
82 
83         using R3 = mp_flatten<L1, std::tuple<>>;
84         BOOST_TEST_TRAIT_TRUE((std::is_same<R3, mp_list<int, mp_list<>, void, mp_list<char, double>, std::pair<int, void>>>));
85     }
86 
87     {
88         using L1 = std::tuple<std::tuple<>, int, mp_list<>, void, mp_list<char, double>, std::pair<int, void>>;
89 
90         using R1 = mp_flatten<L1, mp_list<void, void, void, void>>;
91         BOOST_TEST_TRAIT_TRUE((std::is_same<R1, std::tuple<std::tuple<>, int, void, char, double, std::pair<int, void>>>));
92 
93         using R2 = mp_flatten<L1, std::pair<void, void>>;
94         BOOST_TEST_TRAIT_TRUE((std::is_same<R2, std::tuple<std::tuple<>, int, mp_list<>, void, mp_list<char, double>, int, void>>));
95 
96         using R3 = mp_flatten<L1>;
97         BOOST_TEST_TRAIT_TRUE((std::is_same<R3, std::tuple<int, mp_list<>, void, mp_list<char, double>, std::pair<int, void>>>));
98     }
99 
100     return boost::report_errors();
101 }
102