1
2 // Copyright 2015-2017 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
17 struct X1 {};
18 struct X2 {};
19 struct X3 {};
20
21 using boost::mp11::mp_bool;
22
23 template<class N> using is_even = mp_bool<N::value % 2 == 0>;
24
main()25 int main()
26 {
27 using boost::mp11::mp_list;
28 using boost::mp11::mp_copy_if;
29
30 {
31 using L1 = mp_list<>;
32
33 BOOST_TEST_TRAIT_TRUE((std::is_same<mp_copy_if<L1, std::is_const>, L1>));
34
35 using L2 = mp_list<X1, X1 const, X1*, X2 const, X2*, X3*>;
36
37 BOOST_TEST_TRAIT_TRUE((std::is_same<mp_copy_if<L2, std::is_volatile>, L1>));
38 BOOST_TEST_TRAIT_TRUE((std::is_same<mp_copy_if<L2, std::is_const>, mp_list<X1 const, X2 const>>));
39 BOOST_TEST_TRAIT_TRUE((std::is_same<mp_copy_if<L2, std::is_pointer>, mp_list<X1*, X2*, X3*>>));
40 }
41
42 {
43 using L1 = std::tuple<>;
44
45 BOOST_TEST_TRAIT_TRUE((std::is_same<mp_copy_if<L1, std::is_const>, L1>));
46
47 using L2 = std::tuple<X1, X1 const, X1*, X2 const, X2*, X3*>;
48
49 BOOST_TEST_TRAIT_TRUE((std::is_same<mp_copy_if<L2, std::is_volatile>, L1>));
50 BOOST_TEST_TRAIT_TRUE((std::is_same<mp_copy_if<L2, std::is_const>, std::tuple<X1 const, X2 const>>));
51 BOOST_TEST_TRAIT_TRUE((std::is_same<mp_copy_if<L2, std::is_pointer>, std::tuple<X1*, X2*, X3*>>));
52 }
53
54 using boost::mp11::mp_iota_c;
55 using boost::mp11::mp_size_t;
56
57 {
58 int const N = 12;
59 using L1 = mp_iota_c<N>;
60
61 using R1 = mp_copy_if<L1, is_even>;
62
63 BOOST_TEST_TRAIT_TRUE((std::is_same<R1, mp_list<mp_size_t<0>, mp_size_t<2>, mp_size_t<4>, mp_size_t<6>, mp_size_t<8>, mp_size_t<10>>>));
64 }
65
66 return boost::report_errors();
67 }
68