1 // Copyright 2020 Peter Dimov.
2 // Distributed under the Boost Software License, Version 1.0.
3 // https://www.boost.org/LICENSE_1_0.txt
4
5 #include <boost/mp11/algorithm.hpp>
6 #include <boost/mp11/list.hpp>
7 #include <boost/core/lightweight_test_trait.hpp>
8 #include <type_traits>
9 #include <tuple>
10 #include <cstddef>
11
12 struct X1 {};
13 struct X2 { using first_type = double; using next_type = X1; };
14 struct X3 { using first_type = float; using next_type = X2; };
15 struct X4 { using first_type = int; using next_type = X3; };
16
17 template<class T> using first_type = typename T::first_type;
18 template<class T> using next_type = typename T::next_type;
19
20 template<class T1, class T2> struct cons {};
21
22 template<class T1, class T2> struct cons2
23 {
24 using first_type = T1;
25 using next_type = T2;
26 };
27
28 using boost::mp11::mp_reverse_fold;
29 using boost::mp11::mp_iterate;
30 using boost::mp11::mp_first;
31 using boost::mp11::mp_second;
32 using boost::mp11::mp_rest;
33
test()34 template<class L1> void test()
35 {
36 using R1 = mp_iterate<L1, mp_first, mp_rest>;
37 BOOST_TEST_TRAIT_TRUE((std::is_same<L1, R1>));
38
39 using V2 = mp_reverse_fold<L1, void, cons>;
40 using R2 = mp_iterate<V2, mp_first, mp_second>;
41 BOOST_TEST_TRAIT_TRUE((std::is_same<L1, R2>));
42
43 #if !BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, < 1900 )
44
45 using V3 = mp_reverse_fold<L1, void, cons2>;
46 using R3 = mp_iterate<V3, first_type, next_type>;
47 BOOST_TEST_TRAIT_TRUE((std::is_same<L1, R3>));
48
49 #endif
50 }
51
main()52 int main()
53 {
54 using boost::mp11::mp_list;
55
56 test< mp_list<> >();
57 test< mp_list<int> >();
58 test< mp_list<int, void> >();
59 test< mp_list<int, void, float> >();
60 test< mp_list<int, void, float, double> >();
61
62 using boost::mp11::mp_identity_t;
63
64 BOOST_TEST_TRAIT_TRUE((std::is_same<mp_iterate<X4, mp_identity_t, next_type>, mp_list<X4, X3, X2, X1>>));
65 BOOST_TEST_TRAIT_TRUE((std::is_same<mp_iterate<X4, first_type, next_type>, mp_list<int, float, double>>));
66
67 return boost::report_errors();
68 }
69