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