]>
Commit | Line | Data |
---|---|---|
b32b8144 FG |
1 | #ifndef BOOST_MP11_FUNCTION_HPP_INCLUDED |
2 | #define BOOST_MP11_FUNCTION_HPP_INCLUDED | |
3 | ||
4 | // Copyright 2015-2017 Peter Dimov. | |
5 | // | |
6 | // Distributed under the Boost Software License, Version 1.0. | |
7 | // | |
8 | // See accompanying file LICENSE_1_0.txt or copy at | |
9 | // http://www.boost.org/LICENSE_1_0.txt | |
10 | ||
11 | #include <boost/mp11/integral.hpp> | |
12 | #include <boost/mp11/utility.hpp> | |
13 | #include <boost/mp11/detail/mp_list.hpp> | |
14 | #include <boost/mp11/detail/mp_count.hpp> | |
15 | #include <boost/mp11/detail/mp_plus.hpp> | |
16 | #include <boost/mp11/detail/mp_min_element.hpp> | |
11fdf7f2 | 17 | #include <boost/mp11/detail/mp_void.hpp> |
b32b8144 FG |
18 | #include <type_traits> |
19 | ||
20 | namespace boost | |
21 | { | |
22 | namespace mp11 | |
23 | { | |
24 | ||
25 | // mp_void<T...> | |
11fdf7f2 | 26 | // in detail/mp_void.hpp |
b32b8144 FG |
27 | |
28 | // mp_and<T...> | |
29 | #if BOOST_WORKAROUND( BOOST_MSVC, < 1910 ) | |
30 | ||
31 | namespace detail | |
32 | { | |
33 | ||
34 | template<class... T> struct mp_and_impl; | |
35 | ||
36 | } // namespace detail | |
37 | ||
38 | template<class... T> using mp_and = mp_to_bool< typename detail::mp_and_impl<T...>::type >; | |
39 | ||
40 | namespace detail | |
41 | { | |
42 | ||
43 | template<> struct mp_and_impl<> | |
44 | { | |
45 | using type = mp_true; | |
46 | }; | |
47 | ||
48 | template<class T> struct mp_and_impl<T> | |
49 | { | |
50 | using type = T; | |
51 | }; | |
52 | ||
53 | template<class T1, class... T> struct mp_and_impl<T1, T...> | |
54 | { | |
55 | using type = mp_eval_if< mp_not<T1>, T1, mp_and, T... >; | |
56 | }; | |
57 | ||
58 | } // namespace detail | |
59 | ||
60 | #else | |
61 | ||
62 | namespace detail | |
63 | { | |
64 | ||
65 | template<class L, class E = void> struct mp_and_impl | |
66 | { | |
67 | using type = mp_false; | |
68 | }; | |
69 | ||
70 | template<class... T> struct mp_and_impl< mp_list<T...>, mp_void<mp_if<T, void>...> > | |
71 | { | |
72 | using type = mp_true; | |
73 | }; | |
74 | ||
75 | } // namespace detail | |
76 | ||
77 | template<class... T> using mp_and = typename detail::mp_and_impl<mp_list<T...>>::type; | |
78 | ||
79 | #endif | |
80 | ||
81 | // mp_all<T...> | |
82 | #if BOOST_WORKAROUND( BOOST_MSVC, < 1920 ) || BOOST_WORKAROUND( BOOST_GCC, < 70300 ) | |
83 | ||
84 | template<class... T> using mp_all = mp_bool< mp_count_if< mp_list<T...>, mp_not >::value == 0 >; | |
85 | ||
86 | #elif defined( BOOST_MP11_HAS_FOLD_EXPRESSIONS ) | |
87 | ||
88 | template<class... T> using mp_all = mp_bool<(static_cast<bool>(T::value) && ...)>; | |
89 | ||
90 | #else | |
91 | ||
92 | template<class... T> using mp_all = mp_and<mp_to_bool<T>...>; | |
93 | ||
94 | #endif | |
95 | ||
96 | // mp_or<T...> | |
97 | namespace detail | |
98 | { | |
99 | ||
100 | template<class... T> struct mp_or_impl; | |
101 | ||
102 | } // namespace detail | |
103 | ||
104 | template<class... T> using mp_or = mp_to_bool< typename detail::mp_or_impl<T...>::type >; | |
105 | ||
106 | namespace detail | |
107 | { | |
108 | ||
109 | template<> struct mp_or_impl<> | |
110 | { | |
111 | using type = mp_false; | |
112 | }; | |
113 | ||
114 | template<class T> struct mp_or_impl<T> | |
115 | { | |
116 | using type = T; | |
117 | }; | |
118 | ||
119 | template<class T1, class... T> struct mp_or_impl<T1, T...> | |
120 | { | |
121 | using type = mp_eval_if< T1, T1, mp_or, T... >; | |
122 | }; | |
123 | ||
124 | } // namespace detail | |
125 | ||
126 | // mp_any<T...> | |
127 | #if defined( BOOST_MP11_HAS_FOLD_EXPRESSIONS ) && !BOOST_WORKAROUND( BOOST_GCC, < 70300 ) | |
128 | ||
129 | template<class... T> using mp_any = mp_bool<(static_cast<bool>(T::value) || ...)>; | |
130 | ||
131 | #else | |
132 | ||
133 | template<class... T> using mp_any = mp_bool< mp_count_if< mp_list<T...>, mp_to_bool >::value != 0 >; | |
134 | ||
135 | #endif | |
136 | ||
137 | // mp_same<T...> | |
138 | namespace detail | |
139 | { | |
140 | ||
141 | template<class... T> struct mp_same_impl; | |
142 | ||
143 | template<> struct mp_same_impl<> | |
144 | { | |
145 | using type = mp_true; | |
146 | }; | |
147 | ||
148 | template<class T1, class... T> struct mp_same_impl<T1, T...> | |
149 | { | |
150 | using type = mp_all<std::is_same<T1, T>...>; | |
151 | }; | |
152 | ||
153 | } // namespace detail | |
154 | ||
155 | template<class... T> using mp_same = typename detail::mp_same_impl<T...>::type; | |
156 | ||
157 | // mp_less<T1, T2> | |
158 | template<class T1, class T2> using mp_less = mp_bool<(T1::value < 0 && T2::value >= 0) || ((T1::value < T2::value) && !(T1::value >= 0 && T2::value < 0))>; | |
159 | ||
160 | // mp_min<T...> | |
161 | template<class T1, class... T> using mp_min = mp_min_element<mp_list<T1, T...>, mp_less>; | |
162 | ||
163 | // mp_max<T...> | |
164 | template<class T1, class... T> using mp_max = mp_max_element<mp_list<T1, T...>, mp_less>; | |
165 | ||
166 | } // namespace mp11 | |
167 | } // namespace boost | |
168 | ||
169 | #endif // #ifndef BOOST_MP11_FUNCTION_HPP_INCLUDED |