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/mp11/integral.hpp>
8 #include <boost/mp11/function.hpp>
9 #include <boost/core/lightweight_test_trait.hpp>
10 #include <type_traits>
11 #include <tuple>
12 #include <cstddef>
13
14 struct X1 {};
15 struct X2 {};
16 struct X3 {};
17
18 template<class T1, class T2> struct F {};
19
20 struct Q
21 {
22 template<class T1, class T2> struct fn {};
23 };
24
main()25 int main()
26 {
27 using boost::mp11::mp_partial_sum;
28 using boost::mp11::mp_list;
29 using boost::mp11::mp_list_c;
30 using boost::mp11::mp_int;
31 using boost::mp11::mp_size_t;
32 using boost::mp11::mp_plus;
33 using boost::mp11::mp_rename;
34 using boost::mp11::mp_partial_sum_q;
35 using boost::mp11::mp_quote;
36
37 {
38 BOOST_TEST_TRAIT_TRUE((std::is_same< mp_partial_sum< mp_list<>, void, F >, mp_list<> >));
39 BOOST_TEST_TRAIT_TRUE((std::is_same< mp_partial_sum< mp_list<X1>, void, F >, mp_list< F<void, X1> > >));
40 BOOST_TEST_TRAIT_TRUE((std::is_same< mp_partial_sum< mp_list<X1, X2>, void, F >, mp_list< F<void, X1>, F<F<void, X1>, X2> > >));
41 BOOST_TEST_TRAIT_TRUE((std::is_same< mp_partial_sum< mp_list<X1, X2, X3>, void, F >, mp_list< F<void, X1>, F<F<void, X1>, X2>, F<F<F<void, X1>, X2>, X3> > >));
42
43 BOOST_TEST_TRAIT_TRUE((std::is_same< mp_partial_sum< mp_list_c<int, 7, 7, 2>, mp_int<0>, mp_plus >, mp_list< mp_int<7>, mp_int<14>, mp_int<16> > >));
44 BOOST_TEST_TRAIT_TRUE((std::is_same< mp_partial_sum< mp_list_c<std::size_t, 7, 7, 2>, mp_size_t<0>, mp_plus >, mp_list< mp_size_t<7>, mp_size_t<14>, mp_size_t<16> > >));
45 }
46
47 {
48 BOOST_TEST_TRAIT_TRUE((std::is_same< mp_partial_sum_q< mp_list<>, void, mp_quote<F> >, mp_list<> >));
49 BOOST_TEST_TRAIT_TRUE((std::is_same< mp_partial_sum_q< mp_list<X1>, void, mp_quote<F> >, mp_list< F<void, X1> > >));
50 BOOST_TEST_TRAIT_TRUE((std::is_same< mp_partial_sum_q< mp_list<X1, X2>, void, mp_quote<F> >, mp_list< F<void, X1>, F<F<void, X1>, X2> > >));
51 BOOST_TEST_TRAIT_TRUE((std::is_same< mp_partial_sum_q< mp_list<X1, X2, X3>, void, mp_quote<F> >, mp_list< F<void, X1>, F<F<void, X1>, X2>, F<F<F<void, X1>, X2>, X3> > >));
52
53 BOOST_TEST_TRAIT_TRUE((std::is_same< mp_partial_sum_q< mp_list<>, void, Q >, mp_list<> >));
54 BOOST_TEST_TRAIT_TRUE((std::is_same< mp_partial_sum_q< mp_list<X1>, void, Q >, mp_list< Q::fn<void, X1> > >));
55 BOOST_TEST_TRAIT_TRUE((std::is_same< mp_partial_sum_q< mp_list<X1, X2>, void, Q >, mp_list< Q::fn<void, X1>, Q::fn<Q::fn<void, X1>, X2> > >));
56 BOOST_TEST_TRAIT_TRUE((std::is_same< mp_partial_sum_q< mp_list<X1, X2, X3>, void, Q >, mp_list< Q::fn<void, X1>, Q::fn<Q::fn<void, X1>, X2>, Q::fn<Q::fn<Q::fn<void, X1>, X2>, X3> > >));
57
58 BOOST_TEST_TRAIT_TRUE((std::is_same< mp_partial_sum_q< mp_list_c<int, 7, 7, 2>, mp_int<0>, mp_quote<mp_plus> >, mp_list< mp_int<7>, mp_int<14>, mp_int<16> > >));
59 BOOST_TEST_TRAIT_TRUE((std::is_same< mp_partial_sum_q< mp_list_c<std::size_t, 7, 7, 2>, mp_size_t<0>, mp_quote<mp_plus> >, mp_list< mp_size_t<7>, mp_size_t<14>, mp_size_t<16> > >));
60 }
61
62 {
63 BOOST_TEST_TRAIT_TRUE((std::is_same< mp_partial_sum< std::tuple<>, void, F >, std::tuple<> >));
64 BOOST_TEST_TRAIT_TRUE((std::is_same< mp_partial_sum< std::tuple<X1>, void, F >, std::tuple< F<void, X1> > >));
65 BOOST_TEST_TRAIT_TRUE((std::is_same< mp_partial_sum< std::tuple<X1, X2>, void, F >, std::tuple< F<void, X1>, F<F<void, X1>, X2> > >));
66 BOOST_TEST_TRAIT_TRUE((std::is_same< mp_partial_sum< std::tuple<X1, X2, X3>, void, F >, std::tuple< F<void, X1>, F<F<void, X1>, X2>, F<F<F<void, X1>, X2>, X3> > >));
67
68 BOOST_TEST_TRAIT_TRUE((std::is_same< mp_partial_sum< mp_rename<mp_list_c<int, 7, 7, 2>, std::tuple>, mp_int<0>, mp_plus >, std::tuple< mp_int<7>, mp_int<14>, mp_int<16> > >));
69 BOOST_TEST_TRAIT_TRUE((std::is_same< mp_partial_sum< mp_rename<mp_list_c<std::size_t, 7, 7, 2>, std::tuple>, mp_size_t<0>, mp_plus >, std::tuple< mp_size_t<7>, mp_size_t<14>, mp_size_t<16> > >));
70 }
71
72 {
73 BOOST_TEST_TRAIT_TRUE((std::is_same< mp_partial_sum_q< std::tuple<>, void, mp_quote<F> >, std::tuple<> >));
74 BOOST_TEST_TRAIT_TRUE((std::is_same< mp_partial_sum_q< std::tuple<X1>, void, mp_quote<F> >, std::tuple< F<void, X1> > >));
75 BOOST_TEST_TRAIT_TRUE((std::is_same< mp_partial_sum_q< std::tuple<X1, X2>, void, mp_quote<F> >, std::tuple< F<void, X1>, F<F<void, X1>, X2> > >));
76 BOOST_TEST_TRAIT_TRUE((std::is_same< mp_partial_sum_q< std::tuple<X1, X2, X3>, void, mp_quote<F> >, std::tuple< F<void, X1>, F<F<void, X1>, X2>, F<F<F<void, X1>, X2>, X3> > >));
77
78 BOOST_TEST_TRAIT_TRUE((std::is_same< mp_partial_sum_q< std::tuple<>, void, Q >, std::tuple<> >));
79 BOOST_TEST_TRAIT_TRUE((std::is_same< mp_partial_sum_q< std::tuple<X1>, void, Q >, std::tuple< Q::fn<void, X1> > >));
80 BOOST_TEST_TRAIT_TRUE((std::is_same< mp_partial_sum_q< std::tuple<X1, X2>, void, Q >, std::tuple< Q::fn<void, X1>, Q::fn<Q::fn<void, X1>, X2> > >));
81 BOOST_TEST_TRAIT_TRUE((std::is_same< mp_partial_sum_q< std::tuple<X1, X2, X3>, void, Q >, std::tuple< Q::fn<void, X1>, Q::fn<Q::fn<void, X1>, X2>, Q::fn<Q::fn<Q::fn<void, X1>, X2>, X3> > >));
82
83 BOOST_TEST_TRAIT_TRUE((std::is_same< mp_partial_sum_q< mp_rename<mp_list_c<int, 7, 7, 2>, std::tuple>, mp_int<0>, mp_quote<mp_plus> >, std::tuple< mp_int<7>, mp_int<14>, mp_int<16> > >));
84 BOOST_TEST_TRAIT_TRUE((std::is_same< mp_partial_sum_q< mp_rename<mp_list_c<std::size_t, 7, 7, 2>, std::tuple>, mp_size_t<0>, mp_quote<mp_plus> >, std::tuple< mp_size_t<7>, mp_size_t<14>, mp_size_t<16> > >));
85 }
86
87 return boost::report_errors();
88 }
89