• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 // Copyright 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/mpl.hpp>
11 #include <boost/mp11/list.hpp>
12 
13 #include <boost/mpl/at.hpp>
14 #include <boost/mpl/int.hpp>
15 #include <boost/mpl/back.hpp>
16 #include <boost/mpl/begin.hpp>
17 #include <boost/mpl/end.hpp>
18 #include <boost/mpl/distance.hpp>
19 #include <boost/mpl/clear.hpp>
20 #include <boost/mpl/empty.hpp>
21 #include <boost/mpl/erase.hpp>
22 #include <boost/mpl/front.hpp>
23 #include <boost/mpl/insert.hpp>
24 #include <boost/mpl/insert_range.hpp>
25 #include <boost/mpl/is_sequence.hpp>
26 #include <boost/mpl/pop_front.hpp>
27 #include <boost/mpl/push_back.hpp>
28 #include <boost/mpl/push_front.hpp>
29 #include <boost/mpl/size.hpp>
30 #include <boost/mpl/vector.hpp>
31 #include <boost/mpl/transform.hpp>
32 #include <boost/mpl/reverse.hpp>
33 #include <boost/mpl/remove.hpp>
34 #include <boost/mpl/copy.hpp>
35 #include <boost/mpl/back_inserter.hpp>
36 
37 #include <boost/core/lightweight_test_trait.hpp>
38 #include <type_traits>
39 #include <tuple>
40 
41 template<class T> using add_pointer_t = typename std::add_pointer<T>::type;
42 
test()43 template<class L1> void test()
44 {
45     namespace mpl = boost::mpl;
46     using namespace boost::mp11;
47 
48     // intrinsics
49 
50     BOOST_TEST_TRAIT_TRUE((std::is_same<typename mpl::at<L1, mpl::int_<0>>::type, mp_at_c<L1, 0>>));
51     BOOST_TEST_TRAIT_TRUE((std::is_same<typename mpl::at<L1, mpl::int_<1>>::type, mp_at_c<L1, 1>>));
52     BOOST_TEST_TRAIT_TRUE((std::is_same<typename mpl::at<L1, mpl::int_<2>>::type, mp_at_c<L1, 2>>));
53 
54     BOOST_TEST_TRAIT_TRUE((std::is_same<typename mpl::at_c<L1, 0>::type, mp_at_c<L1, 0>>));
55     BOOST_TEST_TRAIT_TRUE((std::is_same<typename mpl::at_c<L1, 1>::type, mp_at_c<L1, 1>>));
56     BOOST_TEST_TRAIT_TRUE((std::is_same<typename mpl::at_c<L1, 2>::type, mp_at_c<L1, 2>>));
57 
58     BOOST_TEST_TRAIT_TRUE((std::is_same<typename mpl::back<L1>::type, float>));
59 
60     BOOST_TEST_EQ((mpl::distance<typename mpl::begin<L1>::type, typename mpl::end<L1>::type>::type::value), mp_size<L1>::value);
61 
62     BOOST_TEST_TRAIT_TRUE((std::is_same<typename mpl::clear<L1>::type, mp_clear<L1>>));
63 
64     BOOST_TEST_TRAIT_FALSE((typename mpl::empty<L1>::type));
65     BOOST_TEST_TRAIT_TRUE((typename mpl::empty<mp_clear<L1>>::type));
66 
67     BOOST_TEST_TRAIT_TRUE((std::is_same<typename mpl::erase<L1, typename mpl::begin<L1>::type>::type, mp_pop_front<L1>>));
68 
69     BOOST_TEST_TRAIT_TRUE((std::is_same<typename mpl::front<L1>::type, mp_front<L1>>));
70 
71     BOOST_TEST_TRAIT_TRUE((std::is_same<typename mpl::insert<L1, typename mpl::begin<L1>::type, void>::type, mp_push_front<L1, void>>));
72     BOOST_TEST_TRAIT_TRUE((std::is_same<typename mpl::insert<L1, typename mpl::end<L1>::type, void>::type, mp_push_back<L1, void>>));
73 
74     BOOST_TEST_TRAIT_TRUE((std::is_same<typename mpl::insert_range<L1, typename mpl::end<L1>::type, L1>::type, mp_append<L1, L1>>));
75 
76     BOOST_TEST_TRAIT_TRUE((typename mpl::is_sequence<L1>::type));
77 
78     BOOST_TEST_TRAIT_TRUE((std::is_same<typename mpl::pop_front<L1>::type, mp_pop_front<L1>>));
79 
80     BOOST_TEST_TRAIT_TRUE((std::is_same<typename mpl::push_back<L1, char>::type, mp_push_back<L1, char>>));
81 
82     BOOST_TEST_TRAIT_TRUE((std::is_same<typename mpl::push_front<L1, char>::type, mp_push_front<L1, char>>));
83 
84     BOOST_TEST_EQ((mpl::size<L1>::type::value), mp_size<L1>::value);
85 
86     // algorithms
87 
88     BOOST_TEST_TRAIT_TRUE((std::is_same<typename mpl::transform<L1, std::add_pointer<mpl::_1>>::type, mp_transform<add_pointer_t, L1>>));
89 
90     BOOST_TEST_TRAIT_TRUE((std::is_same<typename mpl::reverse<L1>::type, mp_reverse<L1>>));
91 
92     BOOST_TEST_TRAIT_TRUE((std::is_same<typename mpl::remove<L1, int>::type, mp_remove<L1, int>>));
93 
94     using L2 = typename mpl::copy<L1, mpl::back_inserter<mpl::vector<>>>::type;
95     using L3 = typename mpl::copy<L2, mpl::back_inserter<mp_clear<L1>>>::type;
96 
97     BOOST_TEST_TRAIT_TRUE((std::is_same<L1, L3>));
98 }
99 
main()100 int main()
101 {
102     using boost::mp11::mp_list;
103 
104     test<mp_list<int, void, float>>();
105     test<std::tuple<int, long, float>>(); // MPL instantiates the tuple, so no 'void'
106 
107     return boost::report_errors();
108 }
109