• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 //  Copyright 2015 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 struct X4 {};
21 
22 template<class T1, class T2> struct F {};
23 
24 using boost::mp11::mp_plus;
25 
main()26 int main()
27 {
28     using boost::mp11::mp_list;
29     using boost::mp11::mp_fold;
30 
31     {
32         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_fold<mp_list<>, void, F>, void>));
33         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_fold<mp_list<X1>, void, F>, F<void, X1>>));
34         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_fold<mp_list<X1, X2>, void, F>, F<F<void, X1>, X2>>));
35         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_fold<mp_list<X1, X2, X3>, void, F>, F<F<F<void, X1>, X2>, X3>>));
36         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_fold<mp_list<X1, X2, X3, X4>, void, F>, F<F<F<F<void, X1>, X2>, X3>, X4>>));
37     }
38 
39     {
40         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_fold<std::tuple<>, void, F>, void>));
41         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_fold<std::tuple<X1>, void, F>, F<void, X1>>));
42         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_fold<std::tuple<X1, X2>, void, F>, F<F<void, X1>, X2>>));
43         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_fold<std::tuple<X1, X2, X3>, void, F>, F<F<F<void, X1>, X2>, X3>>));
44         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_fold<std::tuple<X1, X2, X3, X4>, void, F>, F<F<F<F<void, X1>, X2>, X3>, X4>>));
45     }
46 
47     using boost::mp11::mp_push_back;
48 
49     {
50         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_fold<std::tuple<X1, X2, X3, X4>, mp_list<>, mp_push_back>, mp_list<X1, X2, X3, X4>>));
51     }
52 
53     using boost::mp11::mp_push_front;
54 
55     {
56         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_fold<std::tuple<X1, X2, X3, X4>, mp_list<>, mp_push_front>, mp_list<X4, X3, X2, X1>>));
57     }
58 
59     using boost::mp11::mp_iota_c;
60     using boost::mp11::mp_reverse;
61     using boost::mp11::mp_size_t;
62 
63     {
64         int const N = 37;
65 
66         using L = mp_iota_c<N>;
67 
68         using R1 = mp_fold<L, mp_list<>, mp_push_back>;
69         BOOST_TEST_TRAIT_TRUE((std::is_same<R1, L>));
70 
71         using R2 = mp_fold<L, mp_list<>, mp_push_front>;
72         BOOST_TEST_TRAIT_TRUE((std::is_same<R2, mp_reverse<L>>));
73 
74         using R3 = mp_fold<L, mp_size_t<0>, mp_plus>;
75         BOOST_TEST_TRAIT_TRUE((std::is_same<R3, mp_size_t<N*(N-1)/2>>));
76     }
77 
78     return boost::report_errors();
79 }
80