YSTest: functional.hpp 源文件

YSTest PreAlpha_b800_20170810 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

functional.hpp
浏览该文件的文档.
1 /*
2 © 2010-2017 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
28 #ifndef YB_INC_ystdex_functional_hpp_
29 #define YB_INC_ystdex_functional_hpp_ 1
30
31 #include "type_op.hpp" // for "tuple.hpp", true_, std::tuple,
32 // is_convertible, vseq::at, bool_, index_sequence_for, member_target_type_t,
33 // false_, is_void, _t, size_t_, std::tuple_size, vseq::join_n_t, std::swap,
34 // common_nonvoid_t, is_nothrow_swappable, make_index_sequence, exclude_self_t;
35 #include "functor.hpp" // for "ref.hpp", <functional>, std::function,
36 // __cpp_lib_invoke, less, addressof_op, mem_get;
37 #include "cassert.h" // for yconstraint;
38 #include <numeric> // for std::accumulate;
39
40 namespace ystdex
41 {
42
44
45 namespace details
46 {
47
48 template<class, class, class>
49 struct tuple_element_convertible;
50
51 template<class _type1, class _type2>
52 struct tuple_element_convertible<_type1, _type2, index_sequence<>> : true_
53 {};
54
55 template<typename... _types1, typename... _types2, size_t... _vSeq,
56 size_t _vHead>
57 struct tuple_element_convertible<std::tuple<_types1...>, std::tuple<_types2...>,
58 index_sequence<_vHead, _vSeq...>>
59 {
60 static_assert(sizeof...(_types1) == sizeof...(_types2),
61 "Mismatched sizes of tuple found.");
62
63 private:
64 using t1 = std::tuple<_types1...>;
65 using t2 = std::tuple<_types2...>;
66
67 public:
68 static yconstexpr const bool value
69 = is_convertible<vseq::at<t1, _vHead>, vseq::at<t2, _vHead>>::value
70 && tuple_element_convertible<t1, t2, index_sequence<_vSeq...>>::value;
71 };
72
73 } // namespace details;
74
80
82 template<typename _tFrom, typename _tTo>
83 struct is_covariant : is_convertible<_tFrom, _tTo>
84 {};
85
86 template<typename _tFrom, typename _tTo, typename... _tFromParams,
87 typename... _tToParams>
88 struct is_covariant<_tFrom(_tFromParams...), _tTo(_tToParams...)>
89 : is_covariant<_tFrom, _tTo>
90 {};
91
92 template<typename... _tFroms, typename... _tTos>
93 struct is_covariant<std::tuple<_tFroms...>, std::tuple<_tTos...>>
94 : bool_<details::tuple_element_convertible<std::tuple<_tFroms...>,
95 std::tuple<_tTos...>, index_sequence_for<_tTos...>>::value>
96 {};
97
99 template<typename _tFrom, typename _tTo, typename... _tFromParams,
100 typename... _tToParams>
101 struct is_covariant<std::function<_tFrom(_tFromParams...)>,
102 std::function<_tTo(_tToParams...)>>
103 : is_covariant<_tFrom(_tFromParams...), _tTo(_tToParams...)>
104 {};
106
107
109
110 template<typename _tFrom, typename _tTo>
111 struct is_contravariant : is_convertible<_tTo, _tFrom>
112 {};
113
114 template<typename _tResFrom, typename _tResTo, typename... _tFromParams,
115 typename... _tToParams>
116 struct is_contravariant<_tResFrom(_tFromParams...), _tResTo(_tToParams...)>
117 : is_contravariant<std::tuple<_tFromParams...>, std::tuple<_tToParams...>>
118 {};
119
120 template<typename... _tFroms, typename... _tTos>
121 struct is_contravariant<std::tuple<_tFroms...>, std::tuple<_tTos...>>
122 : bool_<details::tuple_element_convertible<std::tuple<_tTos...>,
123 std::tuple<_tFroms...>, index_sequence_for<_tTos...>>::value>
124 {};
125
127 template<typename _tResFrom, typename _tResTo, typename... _tFromParams,
128 typename... _tToParams>
129 struct is_contravariant<std::function<_tResFrom(_tFromParams...)>,
130 std::function<_tResTo(_tToParams...)>>
131 : is_contravariant<_tResFrom(_tFromParams...), _tResTo(_tToParams...)>
132 {};
134
135
136
138
139 template<typename... _tParams>
141 yconstfn size_t
142 sizeof_params(_tParams&&...) ynothrow
143 {
144 return sizeof...(_tParams);
145 }
146
147
149
150
152 template<size_t _vN>
153 struct variadic_param
154 {
156 template<typename _type, typename... _tParams>
157 static yconstfn auto
158 get(_type&&, _tParams&&... args) ynothrow
159 -> decltype(variadic_param<_vN - 1>::get(yforward(args)...))
160 {
161 static_assert(sizeof...(args) == _vN,
162 "Wrong variadic arguments number found.");
163
164 return variadic_param<_vN - 1>::get(yforward(args)...);
165 }
166 };
167
168 template<>
169 struct variadic_param<0U>
170 {
172 template<typename _type>
173 static yconstfn auto
174 get(_type&& arg) ynothrow -> decltype(yforward(arg))
175 {
176 return yforward(arg);
177 }
178 };
180
181
186 template<size_t _vN, typename... _tParams>
187 yconstfn auto
188 varg(_tParams&&... args) ynothrow
189 -> decltype(variadic_param<_vN>::get(yforward(args)...))
190 {
191 static_assert(_vN < sizeof...(args),
192 "Out-of-range index of variadic argument found.");
193
194 return variadic_param<_vN>::get(yforward(args)...);
195 }
197
198
200
201
203 template<typename _func>
204 inline void
205 chain_apply(_func&& f) ynothrow
206 {
207 return yforward(f);
208 }
209 template<typename _func, typename _type, typename... _tParams>
210 inline void
211 chain_apply(_func&& f, _type&& arg, _tParams&&... args)
212 ynoexcept_spec(ystdex::chain_apply(
213 yforward(yforward(f)(yforward(arg))), yforward(args)...))
214 {
215 return ystdex::chain_apply(yforward(yforward(f)(yforward(arg))),
216 yforward(args)...);
217 }
219
221
222 template<typename _func>
223 inline void
224 seq_apply(_func&&) ynothrow
225 {}
227 template<typename _func, typename _type, typename... _tParams>
228 inline void
229 seq_apply(_func&& f, _type&& arg, _tParams&&... args)
230 ynoexcept_spec(yimpl(yunseq(0, (void(yforward(f)(yforward(args))), 0)...)))
231 {
232 yforward(f)(yforward(arg));
233 ystdex::seq_apply(yforward(f), yforward(args)...);
234 }
236
238 template<typename _func, typename... _tParams>
239 inline void
240 unseq_apply(_func&& f, _tParams&&... args)
241 ynoexcept_spec(yimpl(yunseq((void(yforward(f)(yforward(args))), 0)...)))
242 {
243 yunseq((void(yforward(f)(yforward(args))), 0)...);
244 }
246
247
248 // TODO: Blocked. Wait for upcoming ISO C++17 for %__cplusplus.
249 #if __cpp_lib_invoke >= 201411
250 using std::invoke;
252 #else
253 namespace details
255 {
256
257 template<typename _type, typename _tCallable>
258 struct is_callable_target
259 : is_base_of<member_target_type_t<_tCallable>, decay_t<_type>>
260 {};
261
262 template<typename _fCallable, typename _type>
263 struct is_callable_case1 : and_<is_member_function_pointer<_fCallable>,
264 is_callable_target<_type, _fCallable>>
265 {};
266
267 template<typename _fCallable, typename _type>
268 struct is_callable_case2 : and_<is_member_function_pointer<_fCallable>,
269 not_<is_callable_target<_type, _fCallable>>>
270 {};
271
272 template<typename _fCallable, typename _type>
273 struct is_callable_case3 : and_<is_member_object_pointer<_fCallable>,
274 is_callable_target<_type, _fCallable>>
275 {};
276
277 template<typename _fCallable, typename _type>
278 struct is_callable_case4 : and_<is_member_object_pointer<_fCallable>,
279 not_<is_callable_target<_type, _fCallable>>>
280 {};
281
283 template<typename _fCallable, typename _type, typename... _tParams>
284 yconstfn auto
285 invoke_impl(_fCallable&& f, _type&& obj, _tParams&&... args)
286 -> enable_if_t<is_callable_case1<decay_t<_fCallable>, _type>::value,
287 decltype((yforward(obj).*f)(yforward(args)...))>
288 {
289 return yconstraint(f), (yforward(obj).*f)(yforward(args)...);
290 }
291 template<typename _fCallable, typename _type, typename... _tParams>
292 yconstfn auto
293 invoke_impl(_fCallable&& f, _type&& obj, _tParams&&... args)
294 -> enable_if_t<is_callable_case2<decay_t<_fCallable>, _type>::value,
295 decltype(((*yforward(obj)).*f)(yforward(args)...))>
296 {
297 return yconstraint(f), ((*yforward(obj)).*f)(yforward(args)...);
298 }
300 template<typename _fCallable, typename _type>
301 yconstfn auto
302 invoke_impl(_fCallable&& f, _type&& obj)
303 -> enable_if_t<is_callable_case3<decay_t<_fCallable>, _type>::value,
304 decltype(yforward(obj).*f)>
305 {
306 return yconstraint(f), yforward(obj).*f;
307 }
308 template<typename _fCallable, typename _type>
309 yconstfn auto
310 invoke_impl(_fCallable&& f, _type&& obj)
311 -> enable_if_t<is_callable_case4<decay_t<_fCallable>, _type>::value,
312 decltype((*yforward(obj)).*f)>
313 {
314 return yconstraint(f), (*yforward(obj)).*f;
315 }
316 template<typename _func, typename... _tParams>
317 yconstfn auto
318 invoke_impl(_func&& f, _tParams&&... args)
319 -> enable_if_t<!is_member_pointer<decay_t<_func>>::value,
320 decltype(yforward(f)(yforward(args)...))>
321 {
322 return yforward(f)(yforward(args)...);
323 }
324
325 } // namespace details;
326
337 template<typename _fCallable, typename... _tParams>
338 yimpl(yconstfn) result_of_t<_fCallable&&(_tParams&&...)>
339 invoke(_fCallable&& f, _tParams&&... args)
340 {
341 return details::invoke_impl(yforward(f), yforward(args)...);
342 }
343 #endif
344
345 namespace details
346 {
347
349 template<typename _fCallable, typename... _tParams>
350 yconstfn pseudo_output
351 invoke_nonvoid_impl(true_, _fCallable&& f, _tParams&&... args)
352 {
353 return ystdex::invoke(yforward(f), yforward(args)...), pseudo_output();
354 }
356 template<typename _fCallable, typename... _tParams>
357 inline result_of_t<_fCallable&&(_tParams&&...)>
358 invoke_nonvoid_impl(false_, _fCallable&& f, _tParams&&... args)
359 {
360 return ystdex::invoke(yforward(f), yforward(args)...);
361 }
362
363 } // namespace details;
364
370 template<typename _fCallable, typename... _tParams>
371 yimpl(yconstfn) nonvoid_result_t<result_of_t<_fCallable&&(_tParams&&...)>>
372 invoke_nonvoid(_fCallable&& f, _tParams&&... args)
373 {
374 return details::invoke_nonvoid_impl(is_void<result_of_t<
375 _fCallable&&(_tParams&&...)>>(), yforward(f), yforward(args)...);
376 }
377
378
386 template<typename _type, typename _func>
387 yconstfn auto
388 invoke_value_or(_func f, _type&& p)
389 -> decay_t<decltype(ystdex::invoke(f, *yforward(p)))>
390 {
391 return p ? ystdex::invoke(f, *yforward(p))
392 : decay_t<decltype(ystdex::invoke(f, *yforward(p)))>();
393 }
394 template<typename _tOther, typename _type, typename _func>
395 yconstfn auto
396 invoke_value_or(_func f, _type&& p, _tOther&& other)
397 -> yimpl(decltype(p ? ystdex::invoke(f, *yforward(p)) : yforward(other)))
398 {
399 return p ? ystdex::invoke(f, *yforward(p)) : yforward(other);
400 }
401 template<typename _tOther, typename _type, typename _func,
402 typename _tSentinal = nullptr_t>
403 yconstfn auto
404 invoke_value_or(_func f, _type&& p, _tOther&& other, _tSentinal&& last)
405 -> yimpl(decltype(!bool(p == yforward(last))
406 ? ystdex::invoke(f, *yforward(p)) : yforward(other)))
407 {
408 return !bool(p == yforward(last)) ? ystdex::invoke(f, *yforward(p))
409 : yforward(other);
410 }
412
413
420 template<typename>
421 struct make_parameter_tuple;
422
424 template<typename _fCallable>
425 using make_parameter_tuple_t = _t<make_parameter_tuple<_fCallable>>;
426
428 template<typename _fCallable>
429 struct make_parameter_tuple<_fCallable&> : make_parameter_tuple<_fCallable>
430 {};
431
433 template<typename _fCallable>
434 struct make_parameter_tuple<_fCallable&&> : make_parameter_tuple<_fCallable>
435 {};
436
437 #define YB_Impl_Functional_ptuple_spec(_exp, _p, _q) \
438 template<typename _tRet, _exp typename... _tParams> \
439 struct make_parameter_tuple<_tRet _p (_tParams...) _q> \
440 { \
441 using type = std::tuple<_tParams...>; \
442 };
443
444 YB_Impl_Functional_ptuple_spec(, , )
445 YB_Impl_Functional_ptuple_spec(, (*), )
446
447 #define YB_Impl_Functional_ptuple_spec_mf(_q) \
448 YB_Impl_Functional_ptuple_spec(class _tClass YPP_Comma, (_tClass::*), _q)
449
450 YB_Impl_Functional_ptuple_spec_mf()
452
453 YB_Impl_Functional_ptuple_spec_mf(const)
454 YB_Impl_Functional_ptuple_spec_mf(volatile)
455 YB_Impl_Functional_ptuple_spec_mf(const volatile)
457
458 #undef YB_Impl_Functional_ptuple_spec_mf
459
460 #undef YB_Impl_Functional_ptuple_spec
461
463 template<typename _tRet, typename... _tParams>
464 struct make_parameter_tuple<std::function<_tRet(_tParams...)>>
465 {
466 using type = std::tuple<_tParams...>;
467 };
469
470
477 template<typename>
478 struct return_of;
479
481 template<typename _fCallable>
482 using return_of_t = _t<return_of<_fCallable>>;
483
485 template<typename _fCallable>
486 struct return_of<_fCallable&> : return_of<_fCallable>
487 {};
488
490 template<typename _fCallable>
491 struct return_of<_fCallable&&> : return_of<_fCallable>
492 {};
493
494 #define YB_Impl_Functional_ret_spec(_exp, _p, _e, _q) \
495 template<typename _tRet, _exp typename... _tParams> \
496 struct return_of<_tRet _p (_tParams... YPP_Args _e) _q> \
497 { \
498 using type = _tRet; \
499 };
500
501 #define YB_Impl_Functional_ret_spec_f(_e) \
502 YB_Impl_Functional_ret_spec(, , _e, ) \
503 YB_Impl_Functional_ret_spec(, (*), _e, )
504
505 YB_Impl_Functional_ret_spec_f()
507 YB_Impl_Functional_ret_spec_f((, ...))
508
509 #undef YB_Impl_Functional_ret_spec_f
510
511 #define YB_Impl_Functional_ret_spec_mf(_e, _q) \
512 YB_Impl_Functional_ret_spec(class _tClass YPP_Comma, (_tClass::*), \
513 _e, _q)
514
515 #define YB_Impl_Functional_ret_spec_mfq(_e) \
516 YB_Impl_Functional_ret_spec_mf(_e, ) \
517 YB_Impl_Functional_ret_spec_mf(_e, const) \
518 YB_Impl_Functional_ret_spec_mf(_e, volatile) \
519 YB_Impl_Functional_ret_spec_mf(_e, const volatile)
520
521
522 YB_Impl_Functional_ret_spec_mfq()
524 YB_Impl_Functional_ret_spec_mfq((, ...))
525
526 #undef YB_Impl_Functional_ret_spec_mfq
527 #undef YB_Impl_Functional_ret_spec_mf
528
529 #undef YB_Impl_Functional_ret_spec
530
532 template<typename _tRet, typename... _tParams>
533 struct return_of<std::function<_tRet(_tParams...)>>
534 {
535 using type = _tRet;
536 };
538
539
546 template<size_t _vIdx, typename _fCallable>
547 struct parameter_of
548 {
549 using type = tuple_element_t<_vIdx,
550 _t<make_parameter_tuple<_fCallable>>>;
551 };
552
554 template<size_t _vIdx, typename _fCallable>
555 using parameter_of_t = _t<parameter_of<_vIdx, _fCallable>>;
557
558
564 template<typename _fCallable>
565 struct paramlist_size : size_t_<std::tuple_size<typename
566 make_parameter_tuple<_fCallable>::type>::value>
567 {};
568
569
575
577 template<typename, class>
578 struct make_function_type;
579
580 template<typename _tRet, class _tTuple>
581 using make_function_type_t = _t<make_function_type<_tRet, _tTuple>>;
582
583 template<typename _tRet, typename... _tParams>
584 struct make_function_type<_tRet, std::tuple<_tParams...>>
585 {
586 using type = _tRet(_tParams...);
587 };
589
590
595 template<template<typename...> class _gOp, typename _func, typename... _tParams>
596 using enable_fallback_t = enable_if_t<!is_detected<_gOp, _tParams&&...>::value,
597 decltype(std::declval<_func>()(std::declval<_tParams&&>()...))>;
598
599
601 template<typename _type, size_t _vN = 1, typename _tParam = _type>
602 using id_func_t
603 = make_function_type_t<_type, vseq::join_n_t<_vN, std::tuple<_tParam>>>;
604
606 template<typename _type, size_t _vN = 1>
607 using id_func_clr_t = id_func_t<_type, _vN, const _type&>;
608
610 template<typename _type, size_t _vN = 1>
611 using id_func_rr_t = id_func_t<_type, _vN, _type&&>;
613
614
620 template<typename _func, typename... _tParams>
622 inline auto
623 bind1(_func&& f, _tParams&&... args) -> decltype(
624 std::bind(yforward(f), std::placeholders::_1, yforward(args)...))
625 {
626 return std::bind(yforward(f), std::placeholders::_1, yforward(args)...);
627 }
629 template<typename _tRes, typename _func, typename... _tParams>
630 inline auto
631 bind1(_func&& f, _tParams&&... args) -> decltype(
632 std::bind<_tRes>(yforward(f), std::placeholders::_1, yforward(args)...))
633 {
634 return std::bind<_tRes>(yforward(f), std::placeholders::_1, yforward(args)...);
635 }
637
644 template<typename _func, typename _func2, typename... _tParams>
645 inline auto
646 bind_forward(_func&& f, _func2&& f2, _tParams&&... args)
647 -> decltype(ystdex::bind1(yforward(f), std::bind(yforward(f2),
648 std::placeholders::_2, yforward(args)...)))
649 {
650 return ystdex::bind1(yforward(f), std::bind(yforward(f2),
651 std::placeholders::_2, yforward(args)...));
652 }
653
654
656
657 template<typename _func, typename _func2>
659 struct composed
660 {
661 _func f;
662 _func2 g;
663
668 template<typename... _tParams>
669 yconstfn auto
670 operator()(_tParams&&... args) const ynoexcept_spec(f(g(yforward(args)...)))
671 -> decltype(f(g(yforward(args)...)))
672 {
673 return f(g(yforward(args)...));
674 }
675 };
676
684 template<typename _func, typename _func2>
685 yconstfn composed<_func, _func2>
686 compose(_func f, _func2 g)
687 {
688 return composed<_func, _func2>{f, g};
689 }
691 template<typename _func, typename _func2, typename _func3, typename... _funcs>
692 yconstfn auto
693 compose(_func f, _func2 g, _func3 h, _funcs... args)
694 -> decltype(ystdex::compose(ystdex::compose(f, g), h, args...))
695 {
696 return ystdex::compose(ystdex::compose(f, g), h, args...);
697 }
699
700
701
703
704 template<typename _func, typename _func2>
706 struct composed_n
707 {
708 _func f;
709 _func2 g;
710
712 template<typename... _tParams>
713 yconstfn auto
714 operator()(_tParams&&... args) const ynoexcept_spec(f(g(yforward(args))...))
715 -> decltype(f(g(yforward(args))...))
716 {
717 return f(g(yforward(args))...);
718 }
719 };
720
728 template<typename _func, typename _func2>
730 yconstfn composed_n<_func, _func2>
731 compose_n(_func f, _func2 g)
732 {
733 return composed_n<_func, _func2>{f, g};
734 }
735 template<typename _func, typename _func2, typename _func3, typename... _funcs>
736 yconstfn auto
737 compose_n(_func f, _func2 g, _func3 h, _funcs... args)
738 -> decltype(ystdex::compose_n(ystdex::compose_n(f, g), h, args...))
739 {
740 return ystdex::compose_n(ystdex::compose_n(f, g), h, args...);
741 }
743
744
746 template<typename _func, typename... _funcs>
747 struct generalized_composed
748 {
749 _func f;
750 std::tuple<_funcs...> g;
751
752 template<typename... _tParams>
753 yconstfn auto
754 operator()(_tParams&&... args) const ynoexcept_spec(yimpl(call(
755 index_sequence_for<_tParams...>(), yforward(args)...))) -> decltype(
756 yimpl(call(index_sequence_for<_tParams...>(), yforward(args)...)))
757 {
758 return call(index_sequence_for<_tParams...>(), yforward(args)...);
759 }
760
761 private:
762 template<size_t... _vSeq, typename... _tParams>
763 yconstfn auto
764 call(index_sequence<_vSeq...>, _tParams&&... args) const
765 ynoexcept_spec(f(std::get<_vSeq>(g)(yforward(args))...))
766 -> decltype(f(std::get<_vSeq>(g)(yforward(args))...))
767 {
768 return f(std::get<_vSeq>(g)(yforward(args))...);
769 }
770 };
771
777 template<typename _func, typename... _funcs>
778 yconstfn generalized_composed<_func, std::tuple<_funcs...>>
779 generalized_compose(_func f, _funcs... args)
780 {
781 return generalized_composed<_func,
782 std::tuple<_funcs...>>{f, make_tuple(args...)};
783 }
785
786
796 template<typename _func, typename _tRes = void, typename _tState = bool>
797 struct one_shot
798 {
799 static_assert(is_nothrow_move_constructible<_func>(),
800 "Invalid target type found.");
801 static_assert(is_nothrow_move_constructible<_tRes>(),
802 "Invalid result type found.");
803 static_assert(is_nothrow_swappable<_tState>(),
804 "Invalid state type found.");
805
806 _func func;
807 mutable _tRes result;
808 mutable _tState fresh{};
809
810 one_shot(_func f, _tRes r = {}, _tState s = {})
811 : func(f), result(r), fresh(s)
812 {}
813 one_shot(one_shot&& f) ynothrow
814 : func(std::move(f.func)), result(std::move(f.result))
815 {
816 using std::swap;
817
818 swap(fresh, f.fresh);
819 }
820
821 template<typename... _tParams>
822 yconstfn_relaxed auto
823 operator()(_tParams&&... args) const
824 ynoexcept(noexcept(func(yforward(args)...)))
825 -> decltype(func(yforward(args)...))
826 {
827 if(fresh)
828 {
829 result = func(yforward(args)...);
830 fresh = {};
831 }
832 return std::forward<_tRes>(result);
833 }
834 };
835
836 template<typename _func, typename _tState>
837 struct one_shot<_func, void, _tState>
838 {
839 static_assert(is_nothrow_move_constructible<_func>(),
840 "Invalid target type found.");
841 static_assert(is_nothrow_swappable<_tState>(),
842 "Invalid state type found.");
843
844 _func func;
845 mutable _tState fresh{};
846
847 one_shot(_func f, _tState s = {})
848 : func(f), fresh(s)
849 {}
850 one_shot(one_shot&& f) ynothrow
851 : func(std::move(f.func))
852 {
853 using std::swap;
854
855 swap(fresh, f.fresh);
856 }
857
858 template<typename... _tParams>
859 yconstfn_relaxed void
860 operator()(_tParams&&... args) const
861 ynoexcept(noexcept(func(yforward(args)...)))
862 {
863 if(fresh)
864 {
865 func(yforward(args)...);
866 fresh = {};
867 }
868 }
869 };
870
871 template<typename _func, typename _tRes>
872 struct one_shot<_func, _tRes, void>
873 {
874 static_assert(is_nothrow_move_constructible<_func>(),
875 "Invalid target type found.");
876 static_assert(is_nothrow_move_constructible<_tRes>(),
877 "Invalid result type found.");
878
879
880 mutable _func func;
881 mutable _tRes result;
882
883 one_shot(_func f, _tRes r = {})
884 : func(f), result(r)
885 {}
886
887 template<typename... _tParams>
888 yconstfn_relaxed auto
889 operator()(_tParams&&... args) const
890 ynoexcept(noexcept(func(yforward(args)...)))
891 -> decltype(func(yforward(args)...) && noexcept(func = {}))
892 {
893 if(func)
894 {
895 result = func(yforward(args)...);
896 func = {};
897 }
898 return std::forward<_tRes>(result);
899 }
900 };
901
902 template<typename _func>
903 struct one_shot<_func, void, void>
904 {
905 static_assert(is_nothrow_move_constructible<_func>(),
906 "Invalid target type found.");
907
908 mutable _func func;
909
910 one_shot(_func f)
911 : func(f)
912 {}
913
914 template<typename... _tParams>
915 yconstfn_relaxed void
916 operator()(_tParams&&... args) const
917 ynoexcept(noexcept(func(yforward(args)...) && noexcept(func = {})))
918 {
919 if(func)
920 {
921 func(yforward(args)...);
922 func = {};
923 }
924 }
925 };
927
928
934 template<typename _type>
935 using get_less
936 = composed_n<less<_type*>, composed<addressof_op<_type>, mem_get<>>>;
937
938
940 namespace details
941 {
942
943 template<typename _type, typename _fCallable, typename... _tParams>
944 _type
945 call_for_value(true_, _type&& val, _fCallable&& f, _tParams&&... args)
946 {
947 ystdex::invoke(yforward(f), yforward(args)...);
948 return yforward(val);
949 }
950
951 template<typename _type, typename _fCallable, typename... _tParams>
952 auto
953 call_for_value(false_, _type&&, _fCallable&& f, _tParams&&... args)
954 -> result_of_t<_fCallable&&(_tParams&&...)>
955 {
956 return ystdex::invoke(yforward(f), yforward(args)...);
957 }
958
959 } // unnamed namespace;
960
965 template<typename _type, typename _fCallable, typename... _tParams>
966 auto
967 call_for_value(_type&& val, _fCallable&& f, _tParams&&... args)
968 -> common_nonvoid_t<result_of_t<_fCallable&&(_tParams&&...)>, _type>
969 {
970 return details::call_for_value(is_void<result_of_t<_fCallable&&(
971 _tParams&&...)>>(), yforward(val), yforward(f), yforward(args)...);
972 }
973
974
980 template<class, class>
981 struct call_projection;
982
983 template<typename _tRet, typename... _tParams, size_t... _vSeq>
984 struct call_projection<_tRet(_tParams...), index_sequence<_vSeq...>>
985 {
987 template<typename _func>
988 static yconstfn auto
989 call(_func&& f, std::tuple<_tParams...>&& args, yimpl(decay_t<
990 decltype(yforward(f)(std::get<_vSeq>(yforward(args))...))>* = {}))
991 -> yimpl(decltype(yforward(f)(std::get<_vSeq>(yforward(args))...)))
992 {
993 return yforward(f)(std::get<_vSeq>(yforward(args))...);
994 }
996 template<typename _func>
997 static yconstfn auto
998 call(_func&& f, _tParams&&... args)
999 -> decltype(call_projection::call(yforward(f),
1000 std::forward_as_tuple(yforward(args)...)))
1001 {
1002 return call_projection::call(yforward(f),
1003 std::forward_as_tuple(yforward(args)...));
1004 }
1005
1007 template<typename _fCallable>
1008 static yconstfn auto
1009 invoke(_fCallable&& f, std::tuple<_tParams...>&& args,
1010 yimpl(decay_t<decltype(ystdex::invoke(yforward(f),
1011 std::get<_vSeq>(yforward(args))...))>* = {})) -> yimpl(decltype(
1012 ystdex::invoke(yforward(f), std::get<_vSeq>(yforward(args))...)))
1013 {
1014 return ystdex::invoke(yforward(f), std::get<_vSeq>(yforward(args))...);
1015 }
1017 template<typename _func>
1018 static yconstfn auto
1019 invoke(_func&& f, _tParams&&... args)
1020 -> decltype(call_projection::invoke(yforward(f),
1021 std::forward_as_tuple(yforward(args)...)))
1022 {
1023 return call_projection::invoke(yforward(f),
1024 std::forward_as_tuple(yforward(args)...));
1025 }
1026 };
1027
1029 template<typename _tRet, typename... _tParams, size_t... _vSeq>
1030 struct call_projection<std::function<_tRet(_tParams...)>,
1031 index_sequence<_vSeq...>> : private
1032 call_projection<_tRet(_tParams...), index_sequence<_vSeq...>>
1033 {
1035 using call_projection<_tRet(_tParams...), index_sequence<_vSeq...>>::call;
1037 using
1038 call_projection<_tRet(_tParams...), index_sequence<_vSeq...>>::invoke;
1039 };
1040
1045 template<typename... _tParams, size_t... _vSeq>
1046 struct call_projection<std::tuple<_tParams...>, index_sequence<_vSeq...>>
1047 {
1049 template<typename _func>
1050 static yconstfn auto
1051 call(_func&& f, std::tuple<_tParams...>&& args)
1052 -> yimpl(decltype(yforward(f)(std::get<_vSeq>(yforward(args))...)))
1053 {
1054 return yforward(f)(std::get<_vSeq>(yforward(args))...);
1055 }
1056
1058 template<typename _func>
1059 static yconstfn auto
1060 call(_func&& f, _tParams&&... args)
1061 -> decltype(call_projection::call(yforward(f),
1062 std::forward_as_tuple(yforward(yforward(args))...)))
1063 {
1064 return call_projection::call(yforward(f),
1065 std::forward_as_tuple(yforward(yforward(args))...));
1066 }
1067
1069 template<typename _fCallable>
1070 static yconstfn auto
1071 invoke(_fCallable&& f, std::tuple<_tParams...>&& args) -> yimpl(
1072 decltype(ystdex::invoke(yforward(f), std::get<_vSeq>(args)...)))
1073 {
1074 return ystdex::invoke(yforward(f), std::get<_vSeq>(args)...);
1075 }
1076 template<typename _func>
1077 static yconstfn auto
1078 invoke(_func&& f, _tParams&&... args) -> decltype(call_projection::invoke(
1079 yforward(f), std::forward_as_tuple(yforward(args)...)))
1080 {
1081 return call_projection::invoke(yforward(f),
1082 std::forward_as_tuple(yforward(args)...));
1083 }
1084 };
1086
1087
1096 template<typename _func, class _tTuple>
1097 yconstfn auto
1098 apply(_func&& f, _tTuple&& args)
1099 -> yimpl(decltype(call_projection<_tTuple, make_index_sequence<
1100 std::tuple_size<decay_t<_tTuple>>::value>>::call(yforward(f),
1101 yforward(args))))
1102 {
1103 return call_projection<_tTuple, make_index_sequence<std::tuple_size<
1104 decay_t<_tTuple>>::value>>::call(yforward(f), yforward(args));
1105 }
1106
1107
1109
1110 template<typename _fCallable, size_t _vLen = paramlist_size<_fCallable>::value>
1111 struct expand_proxy : private call_projection<_fCallable,
1112 make_index_sequence<_vLen>>, private expand_proxy<_fCallable, _vLen - 1>
1113 {
1118 using call_projection<_fCallable, make_index_sequence<_vLen>>::call;
1123 template<typename... _tParams>
1124 static auto
1125 call(_tParams&&... args) -> decltype(
1126 expand_proxy<_fCallable, _vLen - 1>::call(yforward(args)...))
1127 {
1128 return expand_proxy<_fCallable, _vLen - 1>::call(yforward(args)...);
1129 }
1130 };
1131
1132 template<typename _fCallable>
1133 struct expand_proxy<_fCallable, 0>
1134 : private call_projection<_fCallable, index_sequence<>>
1135 {
1136 using call_projection<_fCallable, index_sequence<>>::call;
1137 };
1139
1140
1150 template<typename _fCond, typename _fCallable, typename... _tParams>
1151 result_of_t<_fCallable&&(_tParams&&...)>
1152 retry_on_cond(_fCond cond, _fCallable&& f, _tParams&&... args)
1153 {
1154 using res_t = result_of_t<_fCallable&&(_tParams&&...)>;
1155 using obj_t = object_result_t<res_t>;
1156 obj_t res;
1157
1158 do
1159 res = ystdex::invoke_nonvoid(yforward(f), yforward(args)...);
1160 while(expand_proxy<bool(obj_t&)>::call(cond, res));
1161 return res_t(res);
1162 }
1163
1164
1170 template<typename _fHandler, typename _fCallable>
1171 struct expanded_caller
1172 {
1174 static_assert(is_object<_fCallable>(), "Callable object type is needed.");
1175
1177 _fCallable caller;
1178
1180 template<typename _fCaller,
1181 yimpl(typename = exclude_self_t<expanded_caller, _fCaller>)>
1182 expanded_caller(_fCaller&& f)
1183 : caller(yforward(f))
1184 {}
1185
1187 template<typename... _tParams>
1188 auto
1189 operator()(_tParams&&... args) const -> decltype(
1190 expand_proxy<_fHandler>::call(caller, yforward(args)...))
1191 {
1192 return expand_proxy<_fHandler>::call(caller, yforward(args)...);
1193 }
1194 };
1195
1202 template<typename _fHandler, typename _fCallable>
1203 yconstfn expanded_caller<_fHandler, decay_t<_fCallable>>
1204 make_expanded(_fCallable&& f)
1205 {
1206 return expanded_caller<_fHandler, decay_t<_fCallable>>(yforward(f));
1207 }
1208
1209
1216 template<typename _type>
1217 struct default_last_value
1218 {
1219 template<typename _tIn>
1220 _type
1221 operator()(_tIn first, _tIn last, const _type& val = {}) const
1222 {
1223 return std::accumulate(first, last, val,
1224 [](_type&, decltype(*first) v){
1225 return yforward(v);
1226 });
1227 }
1228 };
1229
1230 template<>
1231 struct default_last_value<void>
1232 {
1233 template<typename _tIn>
1234 void
1235 operator()(_tIn first, _tIn last) const
1236 {
1237 for(; first != last; ++first)
1238 *first;
1239 }
1240 };
1242
1243 } // namespace ystdex;
1244
1245 #endif
1246
ystdex::expanded_caller::caller
_fCallable caller
Definition: functional.hpp:1174
ystdex::call_projection< _tRet(_tParams...), index_sequence< _vSeq... > >::invoke
static auto invoke(_fCallable &&f, std::tuple< _tParams... > &&args, decay_t< decltype(ystdex::invoke(std::forward< decltype(f)>(f), std::get< _vSeq >(std::forward< decltype(args)>(args))...))> *={}) -> decltype(ystdex::invoke(std::forward< decltype(f)>(f), std::get< _vSeq >(std::forward< decltype(args)>(args))...))
Definition: functional.hpp:1009
ystdex::bind1
auto bind1(_func &&f, _tParams &&...args) -> decltype(std::bind(std::forward< decltype(f)>(f), std::placeholders::_1, std::forward< decltype(args)>(args)...))
复合调用 std::bind 和 std::placeholders::_1 。
Definition: functional.hpp:623
ystdex::details::invoke_impl
auto invoke_impl(_fCallable &&f, _type &&obj, _tParams &&...args) -> enable_if_t< is_callable_case1< decay_t< _fCallable >, _type >::value, decltype((std::forward< decltype(obj)>(obj).*f)(std::forward< decltype(args)>(args)...))>
Definition: functional.hpp:285
ystdex::one_shot< _func, void, void >::operator()
void operator()(_tParams &&...args) const
Definition: functional.hpp:916
ystdex::expanded_caller
接受冗余参数的可调用对象。
Definition: functional.hpp:1171
ystdex::cpp2014::result_of_t
typename result_of< _type >::type result_of_t
Definition: type_traits.hpp:355
ystdex::true_
bool_< true > true_
Definition: type_traits.hpp:391
ystdex::parameter_of::type
tuple_element_t< _vIdx, _t< make_parameter_tuple< _fCallable >>> type
Definition: functional.hpp:550
ystdex::cpp2014::index_sequence_for
make_index_sequence< sizeof...(_types)> index_sequence_for
Definition: integer_sequence.hpp:306
ystdex::composed_n::f
_func f
Definition: functional.hpp:708
yconstfn
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:680
ystdex::vseq::at
取指定位置的元素。
Definition: variadic.hpp:531
ystdex::one_shot< _func, void, _tState >::func
_func func
Definition: functional.hpp:840
ystdex::generalized_composed::f
_func f
Definition: functional.hpp:749
v
byte v
Definition: CharRenderer.cpp:75
ystdex::one_shot< _func, void, void >::one_shot
one_shot(_func f)
Definition: functional.hpp:910
ystdex::parameter_of_t
_t< parameter_of< _vIdx, _fCallable >> parameter_of_t
Definition: functional.hpp:555
ystdex::details::tuple_element_convertible< std::tuple< _types1... >, std::tuple< _types2... >, index_sequence< _vHead, _vSeq... > >::t1
std::tuple< _types1... > t1
Definition: functional.hpp:64
ystdex::cpp2014::index_sequence
integer_sequence< size_t, _vSeq... > index_sequence
Definition: integer_sequence.hpp:63
ystdex::expand_proxy
Definition: functional.hpp:1111
ystdex::composed
复合函数。
Definition: functional.hpp:659
ystdex::composed::g
_func2 g
Definition: functional.hpp:662
ystdex::call_projection< std::tuple< _tParams... >, index_sequence< _vSeq... > >::call
static auto call(_func &&f, std::tuple< _tParams... > &&args) -> decltype(std::forward< decltype(f)>(f)(std::get< _vSeq >(std::forward< decltype(args)>(args))...))
Definition: functional.hpp:1051
ystdex::one_shot::one_shot
one_shot(one_shot &&f)
Definition: functional.hpp:813
YSLib::Drawing::r
The boundary is out of the const Graphics const Rect const Point const Point Color c const Rect const Rect & r
Definition: YDraw.h:174
ystdex::false_
bool_< false > false_
Definition: type_traits.hpp:392
ystdex::call_projection< _tRet(_tParams...), index_sequence< _vSeq... > >::call
static auto call(_func &&f, _tParams &&...args) -> decltype(call_projection::call(std::forward< decltype(f)>(f), std::forward_as_tuple(std::forward< decltype(args)>(args)...)))
Definition: functional.hpp:998
ystdex::one_shot< _func, void, _tState >::one_shot
one_shot(one_shot &&f)
Definition: functional.hpp:850
ystdex::expanded_caller::make_expanded
expanded_caller< _fHandler, decay_t< _fCallable > > make_expanded(_fCallable &&f)
构造接受冗余参数的可调用对象。
Definition: functional.hpp:1204
CHRLib::f
f(d, s)
ystdex::default_last_value::operator()
_type operator()(_tIn first, _tIn last, const _type &val={}) const
Definition: functional.hpp:1221
ynoexcept_spec
#define ynoexcept_spec(...)
表达式 noexcept 异常规范。
Definition: ydef.h:794
ystdex::details::is_callable_case1
Definition: functional.hpp:263
platform::bool
std::FILE *fp bool
Definition: FileIO.h:1280
yimpl
#define yimpl(...)
实现标签。
Definition: ydef.h:262
ystdex::nonvoid_result_t
cond_t< not_< is_void< _type >>, _type, pseudo_output > nonvoid_result_t
若类型不是空类型则取后备结果类型（默认为 pseudo_output ）。
Definition: ref.hpp:341
ystdex::compose
composed< _func, _func2 > compose(_func f, _func2 g)
函数复合。
Definition: functional.hpp:686
yconstfn_relaxed
#define yconstfn_relaxed
指定编译时没有 C++11 限制和隐式成员 const 的常量函数。
Definition: ydef.h:692
ystdex::cpp2014::enable_if_t
typename enable_if< _bCond, _type >::type enable_if_t
Definition: type_traits.hpp:343
ystdex::generalized_composed::generalized_compose
generalized_composed< _func, std::tuple< _funcs... > > generalized_compose(_func f, _funcs...args)
多元函数复合。
Definition: functional.hpp:779
ystdex::one_shot::one_shot
one_shot(_func f, _tRes r={}, _tState s={})
Definition: functional.hpp:810
CHRLib::args
_tParams && args
Definition: CharacterProcessing.h:538
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:679
ystdex::one_shot
调用一次的函数包装模板。
Definition: functional.hpp:797
ystdex::compose_n
composed_n< _func, _func2 > compose_n(_func f, _func2 g)
单一分派的多元函数复合。
Definition: functional.hpp:731
ystdex::call_projection< std::tuple< _tParams... >, index_sequence< _vSeq... > >::invoke
static auto invoke(_func &&f, _tParams &&...args) -> decltype(call_projection::invoke(std::forward< decltype(f)>(f), std::forward_as_tuple(std::forward< decltype(args)>(args)...)))
Definition: functional.hpp:1078
ystdex::bind_forward
auto bind_forward(_func &&f, _func2 &&f2, _tParams &&...args) -> decltype(ystdex::bind1(std::forward< decltype(f)>(f), std::bind(std::forward< decltype(f2)>(f2), std::placeholders::_2, std::forward< decltype(args)>(args)...)))
复合调用 ystdex::bind1 和 std::placeholders::_2 以实现值的设置。
Definition: functional.hpp:646
yunseq
#define yunseq
无序列依赖表达式组求值。
Definition: ydef.h:1022
ystdex::invoke_nonvoid
nonvoid_result_t< result_of_t< _fCallable &&(_tParams &&...)> > invoke_nonvoid(_fCallable &&f, _tParams &&...args)
调用可调用对象，保证返回值非空。
Definition: functional.hpp:372
YB_Impl_Functional_ptuple_spec_mf
#define YB_Impl_Functional_ptuple_spec_mf(_q)
Definition: functional.hpp:447
ystdex::expanded_caller::expanded_caller
expanded_caller(_fCaller &&f)
Definition: functional.hpp:1182
ystdex::call_projection< std::tuple< _tParams... >, index_sequence< _vSeq... > >::call
static auto call(_func &&f, _tParams &&...args) -> decltype(call_projection::call(std::forward< decltype(f)>(f), std::forward_as_tuple(std::forward< decltype(std::forward< decltype(args)>(args))>(std::forward< decltype(args)>(args))...)))
Definition: functional.hpp:1060
ystdex::one_shot::fresh
_tState fresh
Definition: functional.hpp:808
ystdex::generalized_composed::operator()
auto operator()(_tParams &&...args) const -> decltype(call(index_sequence_for< _tParams... >(), std::forward< decltype(args)>(args)...))
Definition: functional.hpp:754
ystdex::details::tuple_element_convertible< std::tuple< _types1... >, std::tuple< _types2... >, index_sequence< _vHead, _vSeq... > >::t2
std::tuple< _types2... > t2
Definition: functional.hpp:65
ystdex::return_of_t
_t< return_of< _fCallable >> return_of_t
Definition: functional.hpp:482
ystdex::one_shot< _func, _tRes, void >::func
_func func
Definition: functional.hpp:875
ystdex::composed::operator()
auto operator()(_tParams &&...args) const -> decltype(f(g(std::forward< decltype(args)>(args)...)))
Definition: functional.hpp:670
YB_Impl_Functional_ret_spec_f
#define YB_Impl_Functional_ret_spec_f(_e)
Definition: functional.hpp:501
ystdex::chain_apply
void chain_apply(_func &&f)
顺序链式调用。
Definition: functional.hpp:205
ystdex::one_shot< _func, _tRes, void >::result
_tRes result
Definition: functional.hpp:881
ystdex::default_last_value< void >::operator()
void operator()(_tIn first, _tIn last) const
Definition: functional.hpp:1235
YSLib::Drawing::g
The boundary is out of the const Graphics & g
Definition: YDraw.h:161
ystdex::details::invoke_nonvoid_impl
pseudo_output invoke_nonvoid_impl(true_, _fCallable &&f, _tParams &&...args)
Definition: functional.hpp:351
ystdex::invoke_value_or
auto invoke_value_or(_func f, _type &&p) -> decay_t< decltype(ystdex::invoke(f,*std::forward< decltype(p)>(p)))>
使用 invoke 调用非空值或取默认值。
Definition: functional.hpp:388
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:766
ystdex::cpp2014::decay_t
typename decay< _type >::type decay_t
Definition: type_traits.hpp:340
YB_Impl_Functional_ptuple_spec
#define YB_Impl_Functional_ptuple_spec(_exp, _p, _q)
Definition: functional.hpp:437
CHRLib::s
_tDst const _tSrc * s
Definition: CharacterProcessing.h:140
ystdex::cpp2014::tuple_element_t
_t< std::tuple_element< _vIdx, _type >> tuple_element_t
Definition: tuple.hpp:50
ystdex
特性测试宏。
Definition: ydef.h:822
ystdex::make_parameter_tuple_t
_t< make_parameter_tuple< _fCallable >> make_parameter_tuple_t
Definition: functional.hpp:425
ystdex::call_projection< _tRet(_tParams...), index_sequence< _vSeq... > >::call
static auto call(_func &&f, std::tuple< _tParams... > &&args, decay_t< decltype(std::forward< decltype(f)>(f)(std::get< _vSeq >(std::forward< decltype(args)>(args))...))> *={}) -> decltype(std::forward< decltype(f)>(f)(std::get< _vSeq >(std::forward< decltype(args)>(args))...))
Definition: functional.hpp:989
ystdex::return_of< std::function< _tRet(_tParams...)> >::type
_tRet type
Definition: functional.hpp:535
ystdex::call_projection< std::tuple< _tParams... >, index_sequence< _vSeq... > >::invoke
static auto invoke(_fCallable &&f, std::tuple< _tParams... > &&args) -> decltype(ystdex::invoke(std::forward< decltype(f)>(f), std::get< _vSeq >(args)...))
Definition: functional.hpp:1071
ystdex::size_t_
std::integral_constant< size_t, _vInt > size_t_
Definition: type_traits.hpp:385
type_op.hpp
C++ 类型操作。
ystdex::one_shot< _func, _tRes, void >::operator()
auto operator()(_tParams &&...args) const -> decltype(func(std::forward< decltype(args)>(args)...)&&noexcept(func=
Definition: functional.hpp:889
ystdex::generalized_composed::g
std::tuple< _funcs... > g
Definition: functional.hpp:750
ystdex::variadic_param
变长参数操作模板。
Definition: functional.hpp:153
cassert.h
ISO C 断言/调试跟踪扩展。
ystdex::id_func_t
make_function_type_t< _type, vseq::join_n_t< _vN, std::tuple< _tParam >>> id_func_t
取指定维数和指定参数类型的多元映射扩展恒等函数类型。
Definition: functional.hpp:603
ystdex::_t
typename _type::type _t
嵌套类型别名。
Definition: type_traits.hpp:97
ystdex::default_last_value
合并值序列。
Definition: functional.hpp:1217
ystdex::one_shot< _func, void, _tState >::one_shot
one_shot(_func f, _tState s={})
Definition: functional.hpp:847
ystdex::expanded_caller::operator()
auto operator()(_tParams &&...args) const -> decltype(expand_proxy< _fHandler >::call(caller, std::forward< decltype(args)>(args)...))
Definition: functional.hpp:1189
ystdex::call_for_value
auto call_for_value(_type &&val, _fCallable &&f, _tParams &&...args) -> common_nonvoid_t< result_of_t< _fCallable &&(_tParams &&...)>, _type >
调用第二个参数起指定的函数对象，若返回空类型则使用第一个参数的值为返回值。
Definition: functional.hpp:967
ystdex::is_contravariant
判断指定类型之间是否逆变。
Definition: functional.hpp:111
ystdex::is_nothrow_swappable
Definition: type_traits.hpp:555
ystdex::one_shot< _func, _tRes, void >::one_shot
one_shot(_func f, _tRes r={})
Definition: functional.hpp:883
ystdex::paramlist_size
取参数列表大小。
Definition: functional.hpp:565
ystdex::make_parameter_tuple
取参数列表元组。
Definition: functional.hpp:421
ystdex::details::call_for_value
_type call_for_value(true_, _type &&val, _fCallable &&f, _tParams &&...args)
Definition: functional.hpp:945
ystdex::enable_fallback_t
enable_if_t<!is_detected< _gOp, _tParams &&... >::value, decltype(std::declval< _func >()(std::declval< _tParams && >()...))> enable_fallback_t
启用备用重载。
Definition: functional.hpp:597
CHRLib::CharSet::other
Definition: Encoding.h:65
ystdex::make_parameter_tuple< std::function< _tRet(_tParams...)> >::type
std::tuple< _tParams... > type
Definition: functional.hpp:466
ystdex::swap
void swap(container_adaptor< _tSeqCon > &x, container_adaptor< _tSeqCon > &y)
Definition: container.hpp:179
ystdex::exclude_self_t
enable_if_t<!is_same< _tClass &, decay_t< _tParam > & >::value, _type > exclude_self_t
移除选择类类型的特定重载避免构造模板和复制/转移特殊成员函数冲突。
Definition: type_traits.hpp:748
ystdex::call_projection< _tRet(_tParams...), index_sequence< _vSeq... > >::invoke
static auto invoke(_func &&f, _tParams &&...args) -> decltype(call_projection::invoke(std::forward< decltype(f)>(f), std::forward_as_tuple(std::forward< decltype(args)>(args)...)))
Definition: functional.hpp:1019
ystdex::pseudo_output
伪输出对象。
Definition: ref.hpp:307
ystdex::call_projection
调用投影：向原调用传递序列指定的位置的参数。
Definition: functional.hpp:981
ystdex::return_of
取返回类型。
Definition: functional.hpp:478
std
Definition: memory.hpp:1183
ystdex::composed_n
多元分发的复合函数。
Definition: functional.hpp:706
ystdex::is_covariant
判断指定类型之间是否协变。
Definition: functional.hpp:83
ystdex::details::is_callable_case4
Definition: functional.hpp:278
ystdex::object_result_t
cond_t< is_object< _type >, _type, pseudo_output > object_result_t
若类型不是对象类型则取后备结果类型（默认为 pseudo_output ）。
Definition: ref.hpp:345
functor.hpp
通用仿函数。
ystdex::one_shot::operator()
auto operator()(_tParams &&...args) const -> decltype(func(std::forward< decltype(args)>(args)...))
Definition: functional.hpp:823
ystdex::get_less
composed_n< less< _type * >, composed< addressof_op< _type >, mem_get<>>> get_less
get 成员小于仿函数。
Definition: functional.hpp:936
ystdex::parameter_of
取指定索引的参数类型。
Definition: functional.hpp:547
ystdex::make_function_type
取指定返回类型和元组指定参数类型的函数类型。
Definition: functional.hpp:578
YB_Impl_Functional_ret_spec_mfq
#define YB_Impl_Functional_ret_spec_mfq(_e)
Definition: functional.hpp:515
ystdex::composed::f
_func f
Definition: functional.hpp:661
ystdex::expand_proxy::call
static auto call(_tParams &&...args) -> decltype(expand_proxy< _fCallable, _vLen-1 >::call(std::forward< decltype(args)>(args)...))
Definition: functional.hpp:1125
ystdex::details::is_callable_case2
Definition: functional.hpp:268
yforward
#define yforward(_expr)
根据参数类型使用 std::forward 传递对应参数。
Definition: ydef.h:995
ystdex::varg
auto varg(_tParams &&...args) -> decltype(variadic_param< _vN >::get(std::forward< decltype(args)>(args)...))
取指定位置的变长参数。
Definition: functional.hpp:188
ystdex::retry_on_cond
result_of_t< _fCallable &&(_tParams &&...)> retry_on_cond(_fCond cond, _fCallable &&f, _tParams &&...args)
循环重复调用：代替直接使用 do-while 语句以避免过多引入作用域外的变量。
Definition: functional.hpp:1152
ystdex::invoke
result_of_t< _fCallable &&(_tParams &&...)> invoke(_fCallable &&f, _tParams &&...args)
调用可调用对象。
Definition: functional.hpp:339
ystdex::one_shot< _func, void, void >::func
_func func
Definition: functional.hpp:906
ystdex::details::is_callable_target
Definition: functional.hpp:258
ystdex::is_detected
typename details::detector< nonesuch, void, _gOp, _tParams... >::value_t is_detected
Definition: type_traits.hpp:708
ystdex::sizeof_params
size_t sizeof_params(_tParams &&...)
统计函数参数列表中的参数个数。
Definition: functional.hpp:142
ystdex::one_shot::result
_tRes result
Definition: functional.hpp:807
ystdex::one_shot::func
_func func
Definition: functional.hpp:800
ystdex::unseq_apply
void unseq_apply(_func &&f, _tParams &&...args)
无序调用。
Definition: functional.hpp:240
ystdex::cpp2014::make_index_sequence
make_integer_sequence< size_t, _vN > make_index_sequence
Definition: integer_sequence.hpp:302
ystdex::id_func_clr_t
id_func_t< _type, _vN, const _type & > id_func_clr_t
取指定维数和 const 左值引用参数类型的多元映射扩展恒等函数类型。
Definition: functional.hpp:607
ystdex::generalized_composed
多元复合函数。
Definition: functional.hpp:747
yconstraint
#define yconstraint(_expr)
约束：接口语义。
Definition: cassert.h:88
ystdex::apply
auto apply(_func &&f, _tTuple &&args) -> decltype(call_projection< _tTuple, make_index_sequence< std::tuple_size< decay_t< _tTuple >>::value >>::call(std::forward< decltype(f)>(f), std::forward< decltype(args)>(args)))
应用函数对象和参数元组。
Definition: functional.hpp:1098
ystdex::details::tuple_element_convertible
Definition: functional.hpp:49
ystdex::and_
逻辑操作元函数。
Definition: type_traits.hpp:420
ystdex::id_func_rr_t
id_func_t< _type, _vN, _type && > id_func_rr_t
取指定维数和 const 右值引用参数类型的多元映射扩展恒等函数类型。
Definition: functional.hpp:611
ystdex::variadic_param::get
static auto get(_type &&, _tParams &&...args) -> decltype(variadic_param< _vN-1 >::get(std::forward< decltype(args)>(args)...))
Definition: functional.hpp:158
ystdex::make_function_type< _tRet, std::tuple< _tParams... > >::type
_tRet(_tParams...) type
Definition: functional.hpp:586
ystdex::details::is_callable_case3
Definition: functional.hpp:273
ystdex::mem_get
成员 get 操作。
Definition: functor.hpp:177
ystdex::composed_n::g
_func2 g
Definition: functional.hpp:709
ystdex::make_function_type_t
_t< make_function_type< _tRet, _tTuple >> make_function_type_t
Definition: functional.hpp:581
ystdex::one_shot< _func, void, _tState >::operator()
void operator()(_tParams &&...args) const
Definition: functional.hpp:860
ystdex::composed_n::operator()
auto operator()(_tParams &&...args) const -> decltype(f(g(std::forward< decltype(args)>(args))...))
Definition: functional.hpp:714
ynoexcept
#define ynoexcept(...)
YSLib 无异常抛出保证：指定特定的异常规范。
Definition: ydef.h:746
ystdex::seq_apply
void seq_apply(_func &&)
顺序递归调用。
Definition: functional.hpp:224
ystdex::bool_
std::integral_constant< bool, _vInt > bool_
Definition: type_traits.hpp:375
ystdex::generalized_composed::call
auto call(index_sequence< _vSeq... >, _tParams &&...args) const -> decltype(f(std::get< _vSeq >(g)(std::forward< decltype(args)>(args))...))
Definition: functional.hpp:764
CHRLib::p
const auto p(d)
ystdex::common_nonvoid_t
cond_or_t< is_void< _type >, _type, common_type_t, _types... > common_nonvoid_t
取公共非空类型：若第一参数为非空类型则为第一参数，否则从其余参数推断。
Definition: type_op.hpp:332
ystdex::details::get
get())
Definition: cast.hpp:102