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/mp11/utility.hpp>
19 #include <boost/core/lightweight_test_trait.hpp>
20 #include <type_traits>
21 #include <tuple>
22
23 using boost::mp11::mp_bool;
24
25 #if !BOOST_MP11_WORKAROUND( BOOST_MSVC, < 1910 )
26
27 struct Q1
28 {
29 template<class T, class U> using fn = mp_bool< T::value == U::value >;
30 };
31
32 struct Q2
33 {
34 template<class T, class U> using fn = mp_bool< sizeof(T) == sizeof(U) >;
35 };
36
37 #else
38
39 struct Q1
40 {
41 template<class T, class U> struct fn: mp_bool< T::value == U::value > {};
42 };
43
44 struct Q2
45 {
46 template<class T, class U> struct fn: mp_bool< sizeof(T) == sizeof(U) > {};
47 };
48
49 #endif
50
main()51 int main()
52 {
53 using boost::mp11::mp_list;
54 using boost::mp11::mp_unique_if_q;
55 using boost::mp11::mp_quote_trait;
56
57 {
58 using boost::mp11::mp_iota_c;
59 using boost::mp11::mp_size_t;
60
61 using L1 = mp_iota_c<32>;
62
63 using R1 = mp_unique_if_q<L1, mp_quote_trait<std::is_same>>;
64 BOOST_TEST_TRAIT_TRUE((std::is_same<R1, L1>));
65
66 using R2 = mp_unique_if_q<L1, Q1>;
67 BOOST_TEST_TRAIT_TRUE((std::is_same<R2, L1>));
68
69 using R3 = mp_unique_if_q<L1, Q2>;
70 BOOST_TEST_TRAIT_TRUE((std::is_same<R3, mp_list<mp_size_t<0>>>));
71 }
72
73 {
74 using boost::mp11::mp_list_c;
75 using boost::mp11::mp_append;
76 using boost::mp11::mp_push_back;
77 using boost::mp11::mp_int;
78
79 using L1 = mp_list_c<std::size_t, 0, 1, 2, 3>;
80 using L2 = mp_list_c<int, 1, 2, 3, 4>;
81 using L3 = mp_list_c<long, 2, 3, 4, 5>;
82
83 using R1 = mp_unique_if_q<mp_append<L1, L2, L3>, Q1>;
84 BOOST_TEST_TRAIT_TRUE((std::is_same<R1, mp_push_back<L1, mp_int<4>, std::integral_constant<long, 5>>>));
85 }
86
87 {
88 BOOST_TEST_TRAIT_TRUE((std::is_same<mp_unique_if_q<std::tuple<char[1], char[2], char[1], char[2], char[2], char[1], char[2], char[2], char[2]>, Q2>, std::tuple<char[1], char[2]>>));
89 BOOST_TEST_TRAIT_TRUE((std::is_same<mp_unique_if_q<std::tuple<char[1], char[2], char[3], char[1], char[2], char[3], char[1], char[2], char[3]>, Q2>, std::tuple<char[1], char[2], char[3]>>));
90 }
91
92 return boost::report_errors();
93 }
94