NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
functor.hpp
浏览该文件的文档.
1#ifndef NEFORCE_CORE_FUNCTIONAL_FUNCTOR_HPP__
2#define NEFORCE_CORE_FUNCTIONAL_FUNCTOR_HPP__
3
10
12NEFORCE_BEGIN_NAMESPACE__
13
19
25
34template <typename Arg, typename Result>
36 using argument_type = Arg;
37 using result_type = Result;
38};
39
49template <typename Arg1, typename Arg2, typename Result>
51 using first_argument_type = Arg1;
52 using second_argument_type = Arg2;
53 using result_type = Result;
54};
55 // LegacyFunctionAdapters
57
63
73template <typename T = void>
74struct plus {
75 NEFORCE_NODISCARD constexpr T operator()(const T& x, const T& y) const
76 noexcept(noexcept(_NEFORCE declcopy<T>(x + y))) {
77 return x + y;
78 }
79};
80
84template <>
85struct plus<void> {
86 using is_transparent = void;
87
88 template <typename T1, typename T2>
89 NEFORCE_NODISCARD constexpr auto operator()(T1&& x, T2&& y) const
90 noexcept(noexcept(static_cast<T1&&>(x) + static_cast<T2&&>(y)))
91 -> decltype(static_cast<T1&&>(x) + static_cast<T2&&>(y)) {
92 return static_cast<T1&&>(x) + static_cast<T2&&>(y);
93 }
94};
95
96
104template <typename T = void>
105struct minus {
106 NEFORCE_NODISCARD constexpr T operator()(const T& x, const T& y) const
107 noexcept(noexcept(_NEFORCE declcopy<T>(x - y))) {
108 return x - y;
109 }
110};
111
115template <>
116struct minus<void> {
117 using is_transparent = void;
118
119 template <typename T1, typename T2>
120 NEFORCE_NODISCARD constexpr auto operator()(T1&& x, T2&& y) const
121 noexcept(noexcept(static_cast<T1&&>(x) - static_cast<T2&&>(y)))
122 -> decltype(static_cast<T1&&>(x) - static_cast<T2&&>(y)) {
123 return static_cast<T1&&>(x) - static_cast<T2&&>(y);
124 }
125};
126
134template <typename T = void>
136 NEFORCE_NODISCARD constexpr T operator()(const T& x, const T& y) const
137 noexcept(noexcept(_NEFORCE declcopy<T>(x * y))) {
138 return x * y;
139 }
140};
141
145template <>
146struct multiplies<void> {
147 using is_transparent = void;
148
149 template <typename T1, typename T2>
150 NEFORCE_NODISCARD constexpr auto operator()(T1&& x, T2&& y) const
151 noexcept(noexcept(static_cast<T1&&>(x) * static_cast<T2&&>(y)))
152 -> decltype(static_cast<T1&&>(x) * static_cast<T2&&>(y)) {
153 return static_cast<T1&&>(x) * static_cast<T2&&>(y);
154 }
155};
156
164template <typename T = void>
165struct divides {
166 NEFORCE_NODISCARD constexpr T operator()(const T& x, const T& y) const
167 noexcept(noexcept(_NEFORCE declcopy<T>(x / y))) {
168 return x / y;
169 }
170};
171
175template <>
176struct divides<void> {
177 using is_transparent = void;
178
179 template <typename T1, typename T2>
180 NEFORCE_NODISCARD constexpr auto operator()(T1&& x, T2&& y) const
181 noexcept(noexcept(static_cast<T1&&>(x) / static_cast<T2&&>(y)))
182 -> decltype(static_cast<T1&&>(x) / static_cast<T2&&>(y)) {
183 return static_cast<T1&&>(x) / static_cast<T2&&>(y);
184 }
185};
186
194template <typename T = void>
195struct modulus {
196 NEFORCE_NODISCARD constexpr T operator()(const T& x, const T& y) const
197 noexcept(noexcept(_NEFORCE declcopy<T>(x % y))) {
198 return x % y;
199 }
200};
201
205template <>
206struct modulus<void> {
207 using is_transparent = void;
208
209 template <typename T1, typename T2>
210 NEFORCE_NODISCARD constexpr auto operator()(T1&& x, T2&& y) const
211 noexcept(noexcept(static_cast<T1&&>(x) % static_cast<T2&&>(y)))
212 -> decltype(static_cast<T1&&>(x) % static_cast<T2&&>(y)) {
213 return static_cast<T1&&>(x) % static_cast<T2&&>(y);
214 }
215};
216
224template <typename T = void>
225struct negate {
226 NEFORCE_NODISCARD constexpr T operator()(const T& x) const noexcept(noexcept(_NEFORCE declcopy<T>(-x))) {
227 return -x;
228 }
229};
230
234template <>
235struct negate<void> {
236 using is_transparent = void;
237
238 template <typename T1>
239 NEFORCE_NODISCARD constexpr auto operator()(T1&& x) const noexcept(noexcept(-static_cast<T1&&>(x)))
240 -> decltype(-static_cast<T1&&>(x)) {
241 return -static_cast<T1&&>(x);
242 }
243};
244 // ArithmeticFunctors
246
252
260template <typename T = void>
261struct equal_to {
262 NEFORCE_NODISCARD constexpr bool operator()(const T& x, const T& y) const
263 noexcept(noexcept(_NEFORCE declcopy<bool>(x == y))) {
264 return x == y;
265 }
266};
267
271template <>
272struct equal_to<void> {
273 using is_transparent = void;
274
275 template <typename T1, typename T2>
276 NEFORCE_NODISCARD constexpr auto operator()(T1&& x, T2&& y) const
277 noexcept(noexcept(static_cast<T1&&>(x) == static_cast<T2&&>(y)))
278 -> decltype(static_cast<T1&&>(x) == static_cast<T2&&>(y)) {
279 return static_cast<T1&&>(x) == static_cast<T2&&>(y);
280 }
281};
282
290template <typename T = void>
292 NEFORCE_NODISCARD constexpr bool operator()(const T& x, const T& y) const
293 noexcept(noexcept(_NEFORCE declcopy<bool>(x != y))) {
294 return x != y;
295 }
296};
297
301template <>
302struct not_equal_to<void> {
303 using is_transparent = void;
304
305 template <typename T1, typename T2>
306 NEFORCE_NODISCARD constexpr auto operator()(T1&& x, T2&& y) const
307 noexcept(noexcept(static_cast<T1&&>(x) != static_cast<T2&&>(y)))
308 -> decltype(static_cast<T1&&>(x) != static_cast<T2&&>(y)) {
309 return static_cast<T1&&>(x) != static_cast<T2&&>(y);
310 }
311};
312
320template <typename T = void>
321struct greater {
322 NEFORCE_NODISCARD constexpr bool operator()(const T& x, const T& y) const
323 noexcept(noexcept(_NEFORCE declcopy<bool>(x > y))) {
324 return x > y;
325 }
326};
327
331template <>
332struct greater<void> {
333 using is_transparent = void;
334
335 template <typename T1, typename T2>
336 NEFORCE_NODISCARD constexpr auto operator()(T1&& x, T2&& y) const
337 noexcept(noexcept(static_cast<T1&&>(x) > static_cast<T2&&>(y)))
338 -> decltype(static_cast<T1&&>(x) > static_cast<T2&&>(y)) {
339 return static_cast<T1&&>(x) > static_cast<T2&&>(y);
340 }
341};
342
350template <typename T = void>
351struct less {
352 NEFORCE_NODISCARD constexpr bool operator()(const T& x, const T& y) const
353 noexcept(noexcept(_NEFORCE declcopy<bool>(x < y))) {
354 return x < y;
355 }
356};
357
361template <>
362struct less<void> {
363 using is_transparent = void;
364
365 template <typename T1, typename T2>
366 NEFORCE_NODISCARD constexpr auto operator()(T1&& x, T2&& y) const
367 noexcept(noexcept(static_cast<T1&&>(x) < static_cast<T2&&>(y)))
368 -> decltype(static_cast<T1&&>(x) < static_cast<T2&&>(y)) {
369 return static_cast<T1&&>(x) < static_cast<T2&&>(y);
370 }
371};
372
380template <typename T = void>
382 NEFORCE_NODISCARD constexpr bool operator()(const T& x, const T& y) const
383 noexcept(noexcept(_NEFORCE declcopy<bool>(x >= y))) {
384 return x >= y;
385 }
386};
387
391template <>
392struct greater_equal<void> {
393 using is_transparent = void;
394
395 template <typename T1, typename T2>
396 NEFORCE_NODISCARD constexpr auto operator()(T1&& x, T2&& y) const
397 noexcept(noexcept(static_cast<T1&&>(x) >= static_cast<T2&&>(y)))
398 -> decltype(static_cast<T1&&>(x) >= static_cast<T2&&>(y)) {
399 return static_cast<T1&&>(x) >= static_cast<T2&&>(y);
400 }
401};
402
410template <typename T = void>
412 NEFORCE_NODISCARD constexpr bool operator()(const T& x, const T& y) const
413 noexcept(noexcept(_NEFORCE declcopy<bool>(x <= y))) {
414 return x <= y;
415 }
416};
417
421template <>
422struct less_equal<void> {
423 using is_transparent = void;
424
425 template <typename T1, typename T2>
426 NEFORCE_NODISCARD constexpr auto operator()(T1&& x, T2&& y) const
427 noexcept(noexcept(static_cast<T1&&>(x) <= static_cast<T2&&>(y)))
428 -> decltype(static_cast<T1&&>(x) <= static_cast<T2&&>(y)) {
429 return static_cast<T1&&>(x) <= static_cast<T2&&>(y);
430 }
431};
432 // ComparisonFunctors
434
440
448template <typename T>
449struct identity {
450 template <typename U = T>
451 NEFORCE_NODISCARD constexpr U&& operator()(U&& x) const noexcept {
452 return _NEFORCE forward<U>(x);
453 }
454};
455
456
464template <typename Pair>
465struct select1st {
466#ifdef NEFORCE_STANDARD_20
467 static_assert(is_pair_v<Pair>, "select1st requires pair type.");
468#endif // NEFORCE_STANDARD_20
469
470 NEFORCE_NODISCARD constexpr const typename Pair::first_type& operator()(const Pair& x) const noexcept {
471 return x.first;
472 }
473};
474
482template <typename Pair>
483struct select2nd {
484#ifdef NEFORCE_STANDARD_20
485 static_assert(is_pair_v<Pair>, "select2nd requires pair type.");
486#endif // NEFORCE_STANDARD_20
487
488 NEFORCE_NODISCARD constexpr const typename Pair::second_type& operator()(const Pair& x) const noexcept {
489 return x.second;
490 }
491};
492 // SelectionFunctors
494 // Functor
496
497NEFORCE_END_NAMESPACE__
498#endif // NEFORCE_CORE_FUNCTIONAL_FUNCTOR_HPP__
检查类型是否具有类似pair的结构
NEFORCE_NODISCARD constexpr T && forward(remove_reference_t< T > &x) noexcept
完美转发左值
type_identity_t< T > declcopy(type_identity_t< T >) noexcept
获取类型的副本,仅用于非求值上下文
二元函数适配器基类
Arg1 first_argument_type
第一个参数类型
Arg2 second_argument_type
第二个参数类型
Result result_type
返回值类型
除法运算仿函数
相等比较仿函数
大于等于比较仿函数
大于比较仿函数
恒等仿函数
小于等于比较仿函数
小于比较仿函数
减法运算仿函数
取模运算仿函数
乘法运算仿函数
取负运算仿函数
不等比较仿函数
加法运算仿函数
选择pair的第一个元素
选择pair的第二个元素
一元函数适配器基类
Arg argument_type
参数类型
Result result_type
返回值类型
类型萃取