MSTL 1.4.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
functor.hpp
浏览该文件的文档.
1#ifndef MSTL_CORE_FUNCTIONAL_FUNCTOR_HPP__
2#define MSTL_CORE_FUNCTIONAL_FUNCTOR_HPP__
3
10
13
20
30template <typename Arg, typename Result>
31struct MSTL_FUNC_ADAPTER_DEPRECATE unary_function {
32 using argument_type = Arg;
33 using result_type = Result;
34};
35
46template <typename Arg1, typename Arg2, typename Result>
47struct MSTL_FUNC_ADAPTER_DEPRECATE binary_function {
48 using first_argument_type = Arg1;
49 using second_argument_type = Arg2;
50 using result_type = Result;
51};
52 // LegacyFunctionAdapters
54
60
70template <typename T = void>
71struct plus {
72 MSTL_NODISCARD constexpr T operator ()(const T& x, const T& y) const
73 noexcept(noexcept(_MSTL declcopy<T>(x + y))) {
74 return x + y;
75 }
76};
77
81template <>
82struct plus<void> {
83 using is_transparent = void;
84
85 template <typename T1, typename T2>
86 MSTL_NODISCARD constexpr auto operator ()(T1&& x, T2&& y) const
87 noexcept(noexcept(static_cast<T1&&>(x) + static_cast<T2&&>(y)))
88 -> decltype(static_cast<T1&&>(x) + static_cast<T2&&>(y)) {
89 return static_cast<T1&&>(x) + static_cast<T2&&>(y);
90 }
91};
92
93
101template <typename T = void>
102struct minus {
103 MSTL_NODISCARD constexpr T operator ()(const T& x, const T& y) const
104 noexcept(noexcept(_MSTL declcopy<T>(x - y))) {
105 return x - y;
106 }
107};
108
112template <>
113struct minus<void> {
114 using is_transparent = void;
115
116 template <typename T1, typename T2>
117 MSTL_NODISCARD constexpr auto operator ()(T1&& x, T2&& y) const
118 noexcept(noexcept(static_cast<T1&&>(x) - static_cast<T2&&>(y)))
119 -> decltype(static_cast<T1&&>(x) - static_cast<T2&&>(y)) {
120 return static_cast<T1&&>(x) - static_cast<T2&&>(y);
121 }
122};
123
131template <typename T = void>
133 MSTL_NODISCARD constexpr T operator ()(const T& x, const T& y) const
134 noexcept(noexcept(_MSTL declcopy<T>(x * y))) {
135 return x * y;
136 }
137};
138
142template <>
143struct multiplies<void> {
144 using is_transparent = void;
145
146 template <typename T1, typename T2>
147 MSTL_NODISCARD constexpr auto operator ()(T1&& x, T2&& y) const
148 noexcept(noexcept(static_cast<T1&&>(x) * static_cast<T2&&>(y)))
149 -> decltype(static_cast<T1&&>(x) * static_cast<T2&&>(y)) {
150 return static_cast<T1&&>(x) * static_cast<T2&&>(y);
151 }
152};
153
161template <typename T = void>
162struct divides {
163 MSTL_NODISCARD constexpr T operator ()(const T& x, const T& y) const
164 noexcept(noexcept(_MSTL declcopy<T>(x / y))) {
165 return x / y;
166 }
167};
168
172template <>
173struct divides<void> {
174 using is_transparent = void;
175
176 template <typename T1, typename T2>
177 MSTL_NODISCARD constexpr auto operator ()(T1&& x, T2&& y) const
178 noexcept(noexcept(static_cast<T1&&>(x) / static_cast<T2&&>(y)))
179 -> decltype(static_cast<T1&&>(x) / static_cast<T2&&>(y)) {
180 return static_cast<T1&&>(x) / static_cast<T2&&>(y);
181 }
182};
183
191template <typename T = void>
192struct modulus {
193 MSTL_NODISCARD constexpr T operator ()(const T& x, const T& y) const
194 noexcept(noexcept(_MSTL declcopy<T>(x % y))) {
195 return x % y;
196 }
197};
198
202template <>
203struct modulus<void> {
204 using is_transparent = void;
205
206 template <typename T1, typename T2>
207 MSTL_NODISCARD constexpr auto operator ()(T1&& x, T2&& y) const
208 noexcept(noexcept(static_cast<T1&&>(x) % static_cast<T2&&>(y)))
209 -> decltype(static_cast<T1&&>(x) % static_cast<T2&&>(y)) {
210 return static_cast<T1&&>(x) % static_cast<T2&&>(y);
211 }
212};
213
221template <typename T = void>
222struct negate {
223 MSTL_NODISCARD constexpr T operator ()(const T& x) const
224 noexcept(noexcept(_MSTL declcopy<T>(-x))) {
225 return -x;
226 }
227};
228
232template <>
233struct negate<void> {
234 using is_transparent = void;
235
236 template <typename T1>
237 MSTL_NODISCARD constexpr auto operator ()(T1&& x) const
238 noexcept(noexcept(-static_cast<T1&&>(x)))
239 -> decltype(-static_cast<T1&&>(x)) {
240 return -static_cast<T1&&>(x);
241 }
242};
243 // ArithmeticFunctors
245
251
259template <typename T = void>
260struct equal_to {
261 MSTL_NODISCARD constexpr bool operator ()(const T& x, const T& y) const
262 noexcept(noexcept(_MSTL declcopy<bool>(x == y))) {
263 return x == y;
264 }
265};
266
270template <>
271struct equal_to<void> {
272 using is_transparent = void;
273
274 template <typename T1, typename T2>
275 MSTL_NODISCARD constexpr auto operator ()(T1&& x, T2&& y) const
276 noexcept(noexcept(static_cast<T1&&>(x) == static_cast<T2&&>(y)))
277 -> decltype(static_cast<T1&&>(x) == static_cast<T2&&>(y)) {
278 return static_cast<T1&&>(x) == static_cast<T2&&>(y);
279 }
280};
281
289template <typename T = void>
291 MSTL_NODISCARD constexpr bool operator ()(const T& x, const T& y) const
292 noexcept(noexcept(_MSTL declcopy<bool>(x != y))) {
293 return x != y;
294 }
295};
296
300template <>
301struct not_equal_to<void> {
302 using is_transparent = void;
303
304 template <typename T1, typename T2>
305 MSTL_NODISCARD constexpr auto operator ()(T1&& x, T2&& y) const
306 noexcept(noexcept(static_cast<T1&&>(x) != static_cast<T2&&>(y)))
307 -> decltype(static_cast<T1&&>(x) != static_cast<T2&&>(y)) {
308 return static_cast<T1&&>(x) != static_cast<T2&&>(y);
309 }
310};
311
319template <typename T = void>
320struct greater {
321 MSTL_NODISCARD constexpr bool operator ()(const T& x, const T& y) const
322 noexcept(noexcept(_MSTL declcopy<bool>(x > y))) {
323 return x > y;
324 }
325};
326
330template <>
331struct greater<void> {
332 using is_transparent = void;
333
334 template <typename T1, typename T2>
335 MSTL_NODISCARD constexpr auto operator ()(T1&& x, T2&& y) const
336 noexcept(noexcept(static_cast<T1&&>(x) > static_cast<T2&&>(y)))
337 -> decltype(static_cast<T1&&>(x) > static_cast<T2&&>(y)) {
338 return static_cast<T1&&>(x) > static_cast<T2&&>(y);
339 }
340};
341
349template <typename T = void>
350struct less {
351 MSTL_NODISCARD constexpr bool operator ()(const T& x, const T& y) const
352 noexcept(noexcept(_MSTL declcopy<bool>(x < y))) {
353 return x < y;
354 }
355};
356
360template <>
361struct less<void> {
362 using is_transparent = void;
363
364 template <typename T1, typename T2>
365 MSTL_NODISCARD constexpr auto operator ()(T1&& x, T2&& y) const
366 noexcept(noexcept(static_cast<T1&&>(x) < static_cast<T2&&>(y)))
367 -> decltype(static_cast<T1&&>(x) < static_cast<T2&&>(y)) {
368 return static_cast<T1&&>(x) < static_cast<T2&&>(y);
369 }
370};
371
379template <typename T = void>
381 MSTL_NODISCARD constexpr bool operator ()(const T& x, const T& y) const
382 noexcept(noexcept(_MSTL declcopy<bool>(x >= y))) {
383 return x >= y;
384 }
385};
386
390template <>
391struct greater_equal<void> {
392 using is_transparent = void;
393
394 template <typename T1, typename T2>
395 MSTL_NODISCARD constexpr auto operator ()(T1&& x, T2&& y) const
396 noexcept(noexcept(static_cast<T1&&>(x) >= static_cast<T2&&>(y)))
397 -> decltype(static_cast<T1&&>(x) >= static_cast<T2&&>(y)) {
398 return static_cast<T1&&>(x) >= static_cast<T2&&>(y);
399 }
400};
401
409template <typename T = void>
411 MSTL_NODISCARD constexpr bool operator ()(const T& x, const T& y) const
412 noexcept(noexcept(_MSTL declcopy<bool>(x <= y))) {
413 return x <= y;
414 }
415};
416
420template <>
421struct less_equal<void> {
422 using is_transparent = void;
423
424 template <typename T1, typename T2>
425 MSTL_NODISCARD constexpr auto operator ()(T1&& x, T2&& y) const
426 noexcept(noexcept(static_cast<T1&&>(x) <= static_cast<T2&&>(y)))
427 -> decltype(static_cast<T1&&>(x) <= static_cast<T2&&>(y)) {
428 return static_cast<T1&&>(x) <= static_cast<T2&&>(y);
429 }
430};
431 // ComparisonFunctors
433
439
447template <typename T>
448struct identity {
449 template <typename U = T>
450 MSTL_NODISCARD constexpr U&& operator ()(U&& x) const noexcept {
451 return _MSTL forward<U>(x);
452 }
453};
454
455
463template <typename Pair>
464struct select1st {
465#ifdef MSTL_STANDARD_20__
466 static_assert(is_pair_v<Pair>, "select1st requires pair type.");
467#endif // MSTL_STANDARD_20__
468
469 MSTL_NODISCARD constexpr const typename Pair::first_type&
470 operator ()(const Pair& x) const noexcept {
471 return x.first;
472 }
473};
474
482template <typename Pair>
483struct select2nd {
484#ifdef MSTL_STANDARD_20__
485 static_assert(is_pair_v<Pair>, "select2nd requires pair type.");
486#endif // MSTL_STANDARD_20__
487
488 MSTL_NODISCARD constexpr const typename Pair::second_type&
489 operator ()(const Pair& x) const noexcept {
490 return x.second;
491 }
492};
493 // SelectionFunctors
495
497#endif // MSTL_CORE_FUNCTIONAL_FUNCTOR_HPP__
MSTL_NODISCARD constexpr T && forward(remove_reference_t< T > &x) noexcept
完美转发左值
type_identity_t< T > declcopy(type_identity_t< T >) noexcept
获取类型的副本,仅用于非求值上下文
#define _MSTL
全局命名空间MSTL前缀
#define MSTL_END_NAMESPACE__
结束全局命名空间MSTL
#define MSTL_BEGIN_NAMESPACE__
开始全局命名空间MSTL
二元函数适配器基类
Arg1 first_argument_type
第一个参数类型
Arg2 second_argument_type
第二个参数类型
Result result_type
返回值类型
除法运算仿函数
相等比较仿函数
大于等于比较仿函数
大于比较仿函数
恒等仿函数
小于等于比较仿函数
小于比较仿函数
减法运算仿函数
取模运算仿函数
乘法运算仿函数
取负运算仿函数
不等比较仿函数
加法运算仿函数
选择pair的第一个元素
选择pair的第二个元素
一元函数适配器基类
Arg argument_type
参数类型
Result result_type
返回值类型
MSTL类型萃取