| 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/mp11/utility.hpp> |
| 14 | #include <boost/core/lightweight_test_trait.hpp> |
| 15 | #include <type_traits> |
| 16 | #include <tuple> |
| 17 | |
| 18 | struct X1 {}; |
| 19 | struct X2 {}; |
| 20 | struct X3 {}; |
| 21 | |
| 22 | using boost::mp11::mp_bool; |
| 23 | |
| 24 | struct Q_is_odd |
| 25 | { |
| 26 | template<class N> using fn = mp_bool<N::value % 2 != 0>; |
| 27 | }; |
| 28 | |
| 29 | int main() |
| 30 | { |
| 31 | using boost::mp11::mp_list; |
| 32 | using boost::mp11::mp_remove_if_q; |
| 33 | using boost::mp11::mp_quote; |
| 34 | |
| 35 | { |
| 36 | using L1 = mp_list<>; |
| 37 | |
| 38 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_remove_if_q<L1, mp_quote<std::is_const>>, L1>)); |
| 39 | |
| 40 | using L2 = mp_list<X1, X1 const, X1*, X2 const, X2*, X3*>; |
| 41 | |
| 42 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_remove_if_q<L2, mp_quote<std::is_volatile>>, L2>)); |
| 43 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_remove_if_q<L2, mp_quote<std::is_const>>, mp_list<X1, X1*, X2*, X3*>>)); |
| 44 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_remove_if_q<L2, mp_quote<std::is_pointer>>, mp_list<X1, X1 const, X2 const>>)); |
| 45 | } |
| 46 | |
| 47 | { |
| 48 | using L1 = std::tuple<>; |
| 49 | |
| 50 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_remove_if_q<L1, mp_quote<std::is_const>>, L1>)); |
| 51 | |
| 52 | using L2 = std::tuple<X1, X1 const, X1*, X2 const, X2*, X3*>; |
| 53 | |
| 54 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_remove_if_q<L2, mp_quote<std::is_volatile>>, L2>)); |
| 55 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_remove_if_q<L2, mp_quote<std::is_const>>, std::tuple<X1, X1*, X2*, X3*>>)); |
| 56 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_remove_if_q<L2, mp_quote<std::is_pointer>>, std::tuple<X1, X1 const, X2 const>>)); |
| 57 | } |
| 58 | |
| 59 | using boost::mp11::mp_iota_c; |
| 60 | using boost::mp11::mp_size_t; |
| 61 | |
| 62 | { |
| 63 | int const N = 12; |
| 64 | using L1 = mp_iota_c<N>; |
| 65 | |
| 66 | using R1 = mp_remove_if_q<L1, Q_is_odd>; |
| 67 | |
| 68 | 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>>>)); |
| 69 | } |
| 70 | |
| 71 | return boost::report_errors(); |
| 72 | } |
| 73 | |