]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/mp11/test/mp_reverse_fold.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / mp11 / test / mp_reverse_fold.cpp
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 <boost/config.hpp>
15 #include <boost/detail/workaround.hpp>
16 #include <type_traits>
17 #include <tuple>
18
19 struct X1 {};
20 struct X2 {};
21 struct X3 {};
22 struct X4 {};
23
24 template<class T1, class T2> struct F {};
25
26 using boost::mp11::mp_push_back;
27 using boost::mp11::mp_push_front;
28
29 template<class T, class L> using rev_push_back = mp_push_back<L, T>;
30 template<class T, class L> using rev_push_front = mp_push_front<L, T>;
31
32 using boost::mp11::mp_plus;
33
34 int main()
35 {
36 using boost::mp11::mp_list;
37 using boost::mp11::mp_reverse_fold;
38
39 {
40 BOOST_TEST_TRAIT_TRUE((std::is_same<mp_reverse_fold<mp_list<>, void, F>, void>));
41 BOOST_TEST_TRAIT_TRUE((std::is_same<mp_reverse_fold<mp_list<X1>, void, F>, F<X1, void>>));
42 BOOST_TEST_TRAIT_TRUE((std::is_same<mp_reverse_fold<mp_list<X1, X2>, void, F>, F<X1, F<X2, void>>>));
43 BOOST_TEST_TRAIT_TRUE((std::is_same<mp_reverse_fold<mp_list<X1, X2, X3>, void, F>, F<X1, F<X2, F<X3, void>>>>));
44 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>>>>>));
45 }
46
47 {
48 BOOST_TEST_TRAIT_TRUE((std::is_same<mp_reverse_fold<std::tuple<>, void, F>, void>));
49 BOOST_TEST_TRAIT_TRUE((std::is_same<mp_reverse_fold<std::tuple<X1>, void, F>, F<X1, void>>));
50 BOOST_TEST_TRAIT_TRUE((std::is_same<mp_reverse_fold<std::tuple<X1, X2>, void, F>, F<X1, F<X2, void>>>));
51 BOOST_TEST_TRAIT_TRUE((std::is_same<mp_reverse_fold<std::tuple<X1, X2, X3>, void, F>, F<X1, F<X2, F<X3, void>>>>));
52 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>>>>>));
53 }
54
55 {
56 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>>));
57 }
58
59 {
60 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>>));
61 }
62
63 using boost::mp11::mp_iota_c;
64 using boost::mp11::mp_reverse;
65 using boost::mp11::mp_size_t;
66
67 {
68 int const N = 37;
69
70 using L = mp_iota_c<N>;
71
72 using R1 = mp_reverse_fold<L, mp_list<>, rev_push_front>;
73 BOOST_TEST_TRAIT_TRUE((std::is_same<R1, L>));
74
75 using R2 = mp_reverse_fold<L, mp_list<>, rev_push_back>;
76 BOOST_TEST_TRAIT_TRUE((std::is_same<R2, mp_reverse<L>>));
77
78 using R3 = mp_reverse_fold<L, mp_size_t<0>, mp_plus>;
79 BOOST_TEST_TRAIT_TRUE((std::is_same<R3, mp_size_t<N*(N-1)/2>>));
80 }
81
82 return boost::report_errors();
83 }