1
2 // Copyright 2019 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
15 using boost::mp11::mp_int;
16
17 template<class N> using mod_2 = mp_int<N::value % 2>;
18 template<class N> using mod_3 = mp_int<N::value % 3>;
19 template<class N> using mod_6 = mp_int<N::value % 6>;
20
21 using boost::mp11::mp_not;
22 using boost::mp11::mp_plus;
23
24 template<class T> using P1 = mp_not<mod_6<T>>;
25 template<class T1, class... T> using P2 = mp_not<mp_plus<T...>>;
26
27 using boost::mp11::mp_bool;
28
29 template<std::size_t N> struct second_is
30 {
31 template<class T1, class T2> using fn = mp_bool< T2::value == N >;
32 };
33
34 using boost::mp11::mp_first;
35 using boost::mp11::mp_filter_q;
36 using boost::mp11::mp_iota;
37 using boost::mp11::mp_size;
38
39 template<class L, std::size_t N> using at_c = mp_first< mp_filter_q< second_is<N>, L, mp_iota<mp_size<L>> > >;
40
main()41 int main()
42 {
43 using boost::mp11::mp_iota_c;
44 using boost::mp11::mp_filter;
45 using boost::mp11::mp_list;
46 using boost::mp11::mp_size_t;
47 using boost::mp11::mp_transform;
48
49 {
50 int const N = 12;
51 using L1 = mp_iota_c<N>;
52
53 using R1 = mp_filter<P1, L1>;
54 BOOST_TEST_TRAIT_TRUE((std::is_same<R1, mp_list<mp_size_t<0>, mp_size_t<6>>>));
55
56 using L2 = mp_transform<mod_2, L1>;
57 using L3 = mp_transform<mod_3, L1>;
58 using L6 = mp_transform<mod_6, L1>;
59
60 using R2 = mp_filter<P2, L1, L6>;
61 BOOST_TEST_TRAIT_TRUE((std::is_same<R2, mp_list<mp_size_t<0>, mp_size_t<6>>>));
62
63 using R3 = mp_filter<P2, L1, L2, L3>;
64 BOOST_TEST_TRAIT_TRUE((std::is_same<R3, mp_list<mp_size_t<0>, mp_size_t<6>>>));
65 }
66
67 {
68 int const N = 64;
69 int const M = 17;
70
71 using L1 = mp_iota_c<N>;
72 using R1 = at_c<L1, M>;
73
74 BOOST_TEST_TRAIT_TRUE((std::is_same<R1, mp_size_t<M>>));
75 }
76
77 return boost::report_errors();
78 }
79