| 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 | #include <utility> |
| 17 | |
| 18 | struct X1 {}; |
| 19 | struct X2 {}; |
| 20 | struct X3 {}; |
| 21 | struct X4 {}; |
| 22 | |
| 23 | using boost::mp11::mp_not; |
| 24 | |
| 25 | template<class T> using add_pointer = T*; |
| 26 | template<class T, class...> using is_not_ref = mp_not<std::is_reference<T>>; |
| 27 | template<class T1, class T2> using second = T2; |
| 28 | template<class T1, class T2, class T3> using third = T3; |
| 29 | template<class T1, class T2, class T3, class T4> using fourth = T4; |
| 30 | template<class T1, class T2, class T3, class T4, class T5> using fifth = T5; |
| 31 | |
| 32 | int main() |
| 33 | { |
| 34 | using boost::mp11::mp_list; |
| 35 | using boost::mp11::mp_transform_if; |
| 36 | using boost::mp11::mp_size_t; |
| 37 | using boost::mp11::mp_size; |
| 38 | using boost::mp11::mp_fill; |
| 39 | using boost::mp11::mp_iota; |
| 40 | |
| 41 | using L1 = mp_list<X1, X2&, X3 const, X4 const&>; |
| 42 | |
| 43 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if<is_not_ref, add_pointer, L1>, mp_list<X1*, X2&, X3 const*, X4 const&>>)); |
| 44 | |
| 45 | using L2 = std::tuple<X1, X2&, X3 const, X4 const&>; |
| 46 | |
| 47 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if<is_not_ref, add_pointer, L2>, std::tuple<X1*, X2&, X3 const*, X4 const&>>)); |
| 48 | |
| 49 | using L3 = std::pair<X1 const, X2&>; |
| 50 | |
| 51 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if<is_not_ref, add_pointer, L3>, std::pair<X1 const*, X2&>>)); |
| 52 | |
| 53 | // |
| 54 | |
| 55 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if<is_not_ref, second, L1, mp_fill<L1, void>>, mp_list<void, X2&, void, X4 const&>>)); |
| 56 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if<is_not_ref, second, L2, mp_fill<L2, void>>, std::tuple<void, X2&, void, X4 const&>>)); |
| 57 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if<is_not_ref, second, L3, mp_fill<L3, void>>, std::pair<void, X2&>>)); |
| 58 | |
| 59 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if<is_not_ref, third, L1, L1, mp_iota<mp_size<L1>>>, mp_list<mp_size_t<0>, X2&, mp_size_t<2>, X4 const&>>)); |
| 60 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if<is_not_ref, third, L2, L2, mp_iota<mp_size<L2>>>, std::tuple<mp_size_t<0>, X2&, mp_size_t<2>, X4 const&>>)); |
| 61 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if<is_not_ref, third, L3, L3, mp_iota<mp_size<L3>>>, std::pair<mp_size_t<0>, X2&>>)); |
| 62 | |
| 63 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if<is_not_ref, fourth, L1, L1, L1, mp_iota<mp_size<L1>>>, mp_list<mp_size_t<0>, X2&, mp_size_t<2>, X4 const&>>)); |
| 64 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if<is_not_ref, fourth, L2, L2, L2, mp_iota<mp_size<L2>>>, std::tuple<mp_size_t<0>, X2&, mp_size_t<2>, X4 const&>>)); |
| 65 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if<is_not_ref, fourth, L3, L3, L3, mp_iota<mp_size<L3>>>, std::pair<mp_size_t<0>, X2&>>)); |
| 66 | |
| 67 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if<is_not_ref, fifth, L1, L1, L1, L1, mp_iota<mp_size<L1>>>, mp_list<mp_size_t<0>, X2&, mp_size_t<2>, X4 const&>>)); |
| 68 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if<is_not_ref, fifth, L2, L2, L2, L2, mp_iota<mp_size<L2>>>, std::tuple<mp_size_t<0>, X2&, mp_size_t<2>, X4 const&>>)); |
| 69 | BOOST_TEST_TRAIT_TRUE((std::is_same<mp_transform_if<is_not_ref, fifth, L3, L3, L3, L3, mp_iota<mp_size<L3>>>, std::pair<mp_size_t<0>, X2&>>)); |
| 70 | |
| 71 | // |
| 72 | |
| 73 | return boost::report_errors(); |
| 74 | } |
| 75 | |