• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2015 Peter Dimov.
2 // Copyright 2019 Kris Jusiak.
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 #include <boost/mp11/detail/config.hpp>
10 
11 #if BOOST_MP11_WORKAROUND( BOOST_MP11_GCC, < 40800 )
12 # pragma GCC diagnostic ignored "-Wsign-compare"
13 #endif
14 
15 #include <boost/mp11/algorithm.hpp>
16 #include <boost/mp11/list.hpp>
17 #include <boost/mp11/integral.hpp>
18 #include <boost/core/lightweight_test_trait.hpp>
19 #include <type_traits>
20 #include <tuple>
21 #include <cstddef>
22 
23 using boost::mp11::mp_bool;
24 
25 #if !BOOST_MP11_WORKAROUND( BOOST_MSVC, < 1910 )
26 
27 template<class T, class U> using Eq1 = mp_bool< T::value == U::value >;
28 template<class T, class U> using Eq2 = mp_bool< sizeof(T) == sizeof(U) >;
29 
30 #else
31 
32 template<class T, class U> struct Eq1: mp_bool< T::value == U::value > {};
33 template<class T, class U> struct Eq2: mp_bool< sizeof(T) == sizeof(U) > {};
34 
35 #endif
36 
main()37 int main()
38 {
39     using boost::mp11::mp_list;
40     using boost::mp11::mp_unique_if;
41 
42     {
43         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_unique_if<mp_list<>, std::is_same>, mp_list<>>));
44 
45         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_unique_if<mp_list<void>, std::is_same>, mp_list<void>>));
46         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_unique_if<mp_list<void, void>, std::is_same>, mp_list<void>>));
47         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_unique_if<mp_list<void, void, void>, std::is_same>, mp_list<void>>));
48         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_unique_if<mp_list<void, void, void, void>, std::is_same>, mp_list<void>>));
49 
50         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_unique_if<mp_list<void, int>, std::is_same>, mp_list<void, int>>));
51         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_unique_if<mp_list<void, void, void, int, int, int>, std::is_same>, mp_list<void, int>>));
52         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_unique_if<mp_list<void, int, void, int, int, void, int, int, int>, std::is_same>, mp_list<void, int>>));
53 
54         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_unique_if<mp_list<void, int, char[]>, std::is_same>, mp_list<void, int, char[]>>));
55         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_unique_if<mp_list<void, int, char[], void, int, char[], void, int, char[]>, std::is_same>, mp_list<void, int, char[]>>));
56     }
57 
58     {
59         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_unique_if<std::tuple<>, std::is_same>, std::tuple<>>));
60 
61         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_unique_if<std::tuple<void>, std::is_same>, std::tuple<void>>));
62         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_unique_if<std::tuple<void, void>, std::is_same>, std::tuple<void>>));
63         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_unique_if<std::tuple<void, void, void>, std::is_same>, std::tuple<void>>));
64         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_unique_if<std::tuple<void, void, void, void>, std::is_same>, std::tuple<void>>));
65 
66         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_unique_if<std::tuple<void, int>, std::is_same>, std::tuple<void, int>>));
67         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_unique_if<std::tuple<void, void, void, int, int, int>, std::is_same>, std::tuple<void, int>>));
68         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_unique_if<std::tuple<void, int, void, int, int, void, int, int, int>, std::is_same>, std::tuple<void, int>>));
69 
70         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_unique_if<std::tuple<void, int, char[]>, std::is_same>, std::tuple<void, int, char[]>>));
71         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_unique_if<std::tuple<void, int, char[], void, int, char[], void, int, char[]>, std::is_same>, std::tuple<void, int, char[]>>));
72     }
73 
74     {
75         using boost::mp11::mp_iota_c;
76         using boost::mp11::mp_size_t;
77 
78         using L1 = mp_iota_c<32>;
79 
80         using R1 = mp_unique_if<L1, std::is_same>;
81         BOOST_TEST_TRAIT_TRUE((std::is_same<R1, L1>));
82 
83         using R2 = mp_unique_if<L1, Eq1>;
84         BOOST_TEST_TRAIT_TRUE((std::is_same<R2, L1>));
85 
86         using R3 = mp_unique_if<L1, Eq2>;
87         BOOST_TEST_TRAIT_TRUE((std::is_same<R3, mp_list<mp_size_t<0>>>));
88     }
89 
90     {
91         using boost::mp11::mp_list_c;
92         using boost::mp11::mp_append;
93         using boost::mp11::mp_push_back;
94         using boost::mp11::mp_int;
95 
96         using L1 = mp_list_c<std::size_t, 0, 1, 2, 3>;
97         using L2 = mp_list_c<int, 1, 2, 3, 4>;
98         using L3 = mp_list_c<long, 2, 3, 4, 5>;
99 
100         using R1 = mp_unique_if<mp_append<L1, L2, L3>, Eq1>;
101         BOOST_TEST_TRAIT_TRUE((std::is_same<R1, mp_push_back<L1, mp_int<4>, std::integral_constant<long, 5>>>));
102     }
103 
104     {
105         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_unique_if<std::tuple<char[1], char[2], char[1], char[2], char[2], char[1], char[2], char[2], char[2]>, Eq2>, std::tuple<char[1], char[2]>>));
106         BOOST_TEST_TRAIT_TRUE((std::is_same<mp_unique_if<std::tuple<char[1], char[2], char[3], char[1], char[2], char[3], char[1], char[2], char[3]>, Eq2>, std::tuple<char[1], char[2], char[3]>>));
107     }
108 
109     return boost::report_errors();
110 }
111