YSTest: function.hpp 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

function.hpp
浏览该文件的文档.
1 /*
2 © 2012-2016, 2018-2020 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_function_hpp_
29 #define YB_INC_ystdex_function_hpp_ 1
30
31 #include "any.h" // for internal "type_op.hpp", index_sequence, true_,
32 // std::tuple, is_convertible, vseq::at, bool_, index_sequence_for,
33 // remove_cvref_t, _t, vseq::at_t, vseq::seq_size_t, enable_if_t,
34 // vseq::join_n_t, yconstraint, is_function, any, nullptr_t, ystdex::invoke,
35 // std::allocator_arg_t, exclude_self_t, is_invocable_r, std::allocator_arg,
36 // std::reference_wrapper;
37 #include "apply.hpp" // for call_projection;
38 #include "operators.hpp" // for operators::equality_comparable;
39
40 namespace ystdex
41 {
42
44
45 namespace details
46 {
47
49
50 template<class, class, class>
51 struct elements_convertible;
52
53 template<class _type1, class _type2>
54 struct elements_convertible<_type1, _type2, index_sequence<>> : true_
55 {};
56
57 template<typename... _types1, typename... _types2, size_t... _vSeq,
58 size_t _vHead>
59 struct elements_convertible<empty_base<_types1...>, empty_base<_types2...>,
60 index_sequence<_vHead, _vSeq...>>
61 {
62 static_assert(sizeof...(_types1) == sizeof...(_types2),
63 "Mismatched sizes of tuple found.");
64
65 private:
66 using t1 = empty_base<_types1...>;
67 using t2 = empty_base<_types2...>;
68
69 public:
70 static yconstexpr const bool value
71 = is_convertible<vseq::at<t1, _vHead>, vseq::at<t2, _vHead>>::value
72 && elements_convertible<t1, t2, index_sequence<_vSeq...>>::value;
73 };
75
76
78
79 template<typename>
81 struct mk_plist;
82
83 #define YB_Impl_Functional_ptuple_spec(_exp, _p, _e) \
84 template<typename _tRet, _exp typename... _tParams ynoexcept_param(ne)> \
85 struct mk_plist<_tRet _p (_tParams... YPP_Args _e) ynoexcept_qual(ne)> \
86 { \
87 using type = empty_base<_tParams...>; \
88 };
89
90 YB_Impl_Functional_ptuple_spec(, , )
91 YB_Impl_Functional_ptuple_spec(, (*), )
92 YB_Impl_Functional_ptuple_spec(, , (, ...))
93 YB_Impl_Functional_ptuple_spec(, (*), (, ...))
94
95 #undef YB_Impl_Functional_ptuple_spec
96
98 template<typename _fSig>
99 struct mk_plist<std::function<_fSig>> : mk_plist<_fSig>
100 {};
101
102
103 template<typename>
104 struct ret_of;
105
106 #define YB_Impl_Functional_ret_spec(_exp, _p, _e) \
107 template<typename _tRet, _exp typename... _tParams ynoexcept_param(ne)> \
108 struct ret_of<_tRet _p (_tParams... YPP_Args _e) ynoexcept_qual(ne)> \
109 { \
110 using type = _tRet; \
111 };
112
113 #define YB_Impl_Functional_ret_spec_f(_e) \
114 YB_Impl_Functional_ret_spec(, , _e) \
115 YB_Impl_Functional_ret_spec(, (*), _e)
116
117 YB_Impl_Functional_ret_spec_f()
118 YB_Impl_Functional_ret_spec_f((, ...))
119
120 #undef YB_Impl_Functional_ret_spec_f
121
122 #define YB_Impl_Functional_ret_spec_mf(_e) \
123 YB_Impl_Functional_ret_spec(class _tClass YPP_Comma, (_tClass::*), _e)
124
125 YB_Impl_Functional_ret_spec_mf()
126 YB_Impl_Functional_ret_spec_mf((, ...))
127
128 #undef YB_Impl_Functional_ret_spec_mf
129
130 #undef YB_Impl_Functional_ret_spec
131
132 template<typename _fSig>
133 struct ret_of<std::function<_fSig>> : ret_of<_fSig>
134 {};
136
137 } // namespace details;
138
140
141
143 template<typename _tFrom, typename _tTo>
144 struct is_covariant : is_convertible<_tFrom, _tTo>
145 {};
146
147 template<typename _tFrom, typename _tTo, typename... _tFromParams,
148 typename... _tToParams>
149 struct is_covariant<_tFrom(_tFromParams...), _tTo(_tToParams...)>
150 : is_covariant<_tFrom, _tTo>
151 {};
152
154 template<typename... _tFroms, typename... _tTos>
155 struct is_covariant<empty_base<_tFroms...>, empty_base<_tTos...>>
156 : bool_<details::elements_convertible<empty_base<_tFroms...>,
157 empty_base<_tTos...>, index_sequence_for<_tTos...>>::value>
158 {};
159
160 template<typename... _tFroms, typename... _tTos>
161 struct is_covariant<std::tuple<_tFroms...>, std::tuple<_tTos...>>
162 : is_covariant<empty_base<_tFroms...>, empty_base<_tTos...>>
163 {};
164
166 template<typename _tFrom, typename _tTo, typename... _tFromParams,
167 typename... _tToParams>
168 struct is_covariant<std::function<_tFrom(_tFromParams...)>,
169 std::function<_tTo(_tToParams...)>>
170 : is_covariant<_tFrom(_tFromParams...), _tTo(_tToParams...)>
171 {};
173
174
176
177 template<typename _tFrom, typename _tTo>
178 struct is_contravariant : is_convertible<_tTo, _tFrom>
179 {};
180
181 template<typename _tResFrom, typename _tResTo, typename... _tFromParams,
182 typename... _tToParams>
183 struct is_contravariant<_tResFrom(_tFromParams...), _tResTo(_tToParams...)>
184 : is_contravariant<empty_base<_tFromParams...>, empty_base<_tToParams...>>
185 {};
186
188 template<typename... _tFroms, typename... _tTos>
189 struct is_contravariant<empty_base<_tFroms...>, empty_base<_tTos...>>
190 : bool_<details::elements_convertible<empty_base<_tTos...>,
191 empty_base<_tFroms...>, index_sequence_for<_tTos...>>::value>
192 {};
193
194 template<typename... _tFroms, typename... _tTos>
195 struct is_contravariant<std::tuple<_tFroms...>, std::tuple<_tTos...>>
196 : is_contravariant<empty_base<_tFroms...>, empty_base<_tTos...>>
197 {};
198
200 template<typename _tResFrom, typename _tResTo, typename... _tFromParams,
201 typename... _tToParams>
202 struct is_contravariant<std::function<_tResFrom(_tFromParams...)>,
203 std::function<_tResTo(_tToParams...)>>
204 : is_contravariant<_tResFrom(_tFromParams...), _tResTo(_tToParams...)>
205 {};
207
208
209
210
212
213 template<typename... _tParams>
215 yconstfn size_t
216 sizeof_params(_tParams&&...) ynothrow
217 {
218 return sizeof...(_tParams);
219 }
220
221
223
224
226 template<size_t _vN>
227 struct variadic_param
228 {
230 template<typename _type, typename... _tParams>
231 static yconstfn auto
232 get(_type&&, _tParams&&... args) ynothrow
233 -> decltype(variadic_param<_vN - 1>::get(yforward(args)...))
234 {
235 static_assert(sizeof...(args) == _vN,
236 "Wrong variadic arguments number found.");
237
238 return variadic_param<_vN - 1>::get(yforward(args)...);
239 }
240 };
241
242 template<>
243 struct variadic_param<0U>
244 {
246 template<typename _type>
247 static yconstfn auto
248 get(_type&& arg) ynothrow -> decltype(yforward(arg))
249 {
250 return yforward(arg);
251 }
252 };
254
255
260 template<size_t _vN, typename... _tParams>
261 yconstfn auto
262 varg(_tParams&&... args) ynothrow
263 -> decltype(variadic_param<_vN>::get(yforward(args)...))
264 {
265 static_assert(_vN < sizeof...(args),
266 "Out-of-range index of variadic argument found.");
267
268 return variadic_param<_vN>::get(yforward(args)...);
269 }
271
272
274
275
277 template<typename _func>
278 inline void
279 chain_apply(_func&& f) ynothrow
280 {
281 return yforward(f);
282 }
283 template<typename _func, typename _type, typename... _tParams>
284 inline void
285 chain_apply(_func&& f, _type&& arg, _tParams&&... args)
286 ynoexcept_spec(ystdex::chain_apply(
287 yforward(yforward(f)(yforward(arg))), yforward(args)...))
288 {
289 return ystdex::chain_apply(yforward(yforward(f)(yforward(arg))),
290 yforward(args)...);
291 }
293
295
296 template<typename _func>
297 inline void
298 seq_apply(_func&&) ynothrow
299 {}
301 template<typename _func, typename _type, typename... _tParams>
302 inline void
303 seq_apply(_func&& f, _type&& arg, _tParams&&... args)
304 ynoexcept_spec(yimpl(yunseq(0, (void(yforward(f)(yforward(args))), 0)...)))
305 {
306 yforward(f)(yforward(arg));
307 ystdex::seq_apply(yforward(f), yforward(args)...);
308 }
310
312 template<typename _func, typename... _tParams>
313 inline void
314 unseq_apply(_func&& f, _tParams&&... args)
315 ynoexcept_spec(yimpl(yunseq((void(yforward(f)(yforward(args))), 0)...)))
316 {
317 yunseq((void(yforward(f)(yforward(args))), 0)...);
318 }
320
321
322
324
325
327
329 template<typename _fCallable>
330 struct make_parameter_list
331 : details::mk_plist<remove_cvref_t<_fCallable>>
332 {};
333
334 template<typename _fCallable>
335 using make_parameter_list_t = _t<make_parameter_list<_fCallable>>;
337
338
339
341
342 template<typename _fCallable>
344 struct return_of : details::ret_of<remove_cvref_t<_fCallable>>
345 {};
346
348 template<typename _fCallable>
349 using return_of_t = _t<return_of<_fCallable>>;
351
352
358 template<size_t _vIdx, typename _fCallable>
359 struct parameter_of
360 {
361 using type = vseq::at_t<make_parameter_list_t<_fCallable>, _vIdx>;
362 };
363
365 template<size_t _vIdx, typename _fCallable>
366 using parameter_of_t = _t<parameter_of<_vIdx, _fCallable>>;
368
369
375 template<typename _fCallable>
376 struct paramlist_size : vseq::seq_size_t<make_parameter_list_t<_fCallable>>
377 {};
378
379
381
382
387 template<typename, class>
388 struct make_function_type;
389
390 template<typename _tRet, class _tTuple>
391 using make_function_type_t = _t<make_function_type<_tRet, _tTuple>>;
392
393 template<typename _tRet, typename... _tParams>
394 struct make_function_type<_tRet, empty_base<_tParams...>>
395 {
396 using type = _tRet(_tParams...);
397 };
398
399 template<typename _tRet, typename... _tParams>
400 struct make_function_type<_tRet, std::tuple<_tParams...>>
401 : make_function_type<_tRet, empty_base<_tParams...>>
402 {};
404
405
407 template<typename _tRet, typename... _tParams, size_t... _vSeq>
408 struct call_projection<std::function<_tRet(_tParams...)>,
409 index_sequence<_vSeq...>>
410 : call_projection<_tRet(_tParams...), index_sequence<_vSeq...>>
411 {};
412
413
419 template<typename _fCallable>
420 using as_function_type_t = make_function_type_t<return_of_t<_fCallable>,
421 make_parameter_list_t<_fCallable>>;
422
423
428 template<template<typename...> class _gOp, typename _func, typename... _tParams>
429 using enable_fallback_t = enable_if_t<!is_detected<_gOp, _tParams&&...>::value,
430 decltype(std::declval<_func>()(std::declval<_tParams>()...))>;
431
432
434 template<typename _type, size_t _vN = 1, typename _tParam = _type>
435 using id_func_t
436 = make_function_type_t<_type, vseq::join_n_t<_vN, empty_base<_tParam>>>;
437
439 template<typename _type, size_t _vN = 1>
440 using id_func_clr_t = id_func_t<_type, _vN, const _type&>;
441
443 template<typename _type, size_t _vN = 1>
444 using id_func_rr_t = id_func_t<_type, _vN, _type&&>;
446
447
448
450
451
454 enum class empty_function_policy
455 {
457 no_check,
459 no_effect,
461 throwing
462 };
463
464
476 template<typename, empty_function_policy>
477 struct function_traits;
478
479 template<typename _tRet, typename... _tParams>
480 struct function_traits<_tRet(_tParams...), empty_function_policy::no_check>
481 {
482 template<class _tContent, typename _fInvoke>
483 static yconstfn_relaxed void
484 init_empty(const _tContent&, _fInvoke&) ynothrow
485 {}
486
487 template<class _tContent, typename _fInvoke>
488 static _tRet
489 call(const _tContent& content, const _fInvoke& f, _tParams&&... args)
490 {
491 yconstraint(bool(content));
492 yassume(f);
493 return f(content, yforward(args)...);
494 }
495 };
496
497 template<typename _tRet, typename... _tParams>
498 struct function_traits<_tRet(_tParams...), empty_function_policy::no_effect>
499 {
500 // NOTE: See $2020-01 @ %Documentation::Workflow.
502 template<class _tContent>
503 #if YB_IMPL_GNUCPP && defined(NDEBUG) \
504 && !(defined(YB_DLL) || defined(YB_BUILD_DLL))
505 YB_ATTR(noinline) YB_ATTR(optimize("O2"))
506 #endif
507 static _tRet
508 invoke_empty(const _tContent&, _tParams...)
509 ynoexcept(is_nothrow_constructible<_tRet>())
510 {
511 return _tRet();
512 }
513
514 template<class _tContent, typename _fInvoke>
515 static yconstfn_relaxed void
516 init_empty(const _tContent&, _fInvoke& f) ynothrow
517 {
518 static_assert(is_nothrow_copy_assignable<_fInvoke>(),
519 "Invalid invoker type found.");
520
521 // XXX: Here lambda-expression is buggy in G++ LTO.
522 f = &invoke_empty<_tContent>;
523 }
524
525 template<class _tContent, typename _fInvoke>
526 static _tRet
527 call(const _tContent& content, const _fInvoke& f, _tParams&&... args)
528 {
529 yassume(f);
530 return f(content, yforward(args)...);
531 }
532 };
533
534 template<typename _tRet, typename... _tParams>
535 struct function_traits<_tRet(_tParams...), empty_function_policy::throwing>
536 {
537 // NOTE: See $2020-01 @ %Documentation::Workflow.
539 template<class _tContent>
540 #if YB_IMPL_GNUCPP && defined(NDEBUG) \
541 && !(defined(YB_DLL) || defined(YB_BUILD_DLL))
542 YB_ATTR(noinline) YB_ATTR(optimize("O2"))
543 #endif
544 YB_NORETURN static _tRet
545 invoke_empty(const _tContent&, _tParams...)
546 {
547 // TODO: Use a function call to throw?
548 throw std::bad_function_call();
549 }
550
551 template<class _tContent, typename _fInvoke>
552 static yconstfn_relaxed void
553 init_empty(const _tContent&, _fInvoke& f)
554 {
555 // XXX: Here lambda-expression is buggy in G++ LTO.
556 f = &invoke_empty<_tContent>;
557 }
558
559 template<class _tContent, typename _fInvoke>
560 static _tRet
561 call(const _tContent& content, const _fInvoke& f, _tParams&&... args)
562 {
563 yassume(f);
564 return f(content, yforward(args)...);
565 }
566 };
568
569
570
572
573
577 template<class, typename>
578 class function_base;
579
580
588 template<typename _fSig>
589 YB_ATTR_nodiscard YB_PURE static bool
590 function_not_empty(const std::function<_fSig>& f) ynothrow
591 {
592 return bool(f);
593 }
595 template<class _tTraits, typename _fSig>
596 YB_ATTR_nodiscard YB_PURE static bool
597 function_not_empty(const function_base<_tTraits, _fSig>& f) ynothrow
598 {
599 return bool(f);
600 }
601 template<typename _func,
602 yimpl(typename = enable_if_t<is_function<_func>::value>)>
603 YB_ATTR_nodiscard YB_PURE static bool
604 function_not_empty(_func* p) ynothrow
605 {
606 return p;
607 }
608 template<typename _tRet, class _tClass>
609 YB_ATTR_nodiscard YB_PURE static bool
610 function_not_empty(_tRet _tClass::* p) ynothrow
611 {
612 return p;
613 }
614 template<typename _type>
615 YB_ATTR_nodiscard YB_PURE yconstfn static bool
616 function_not_empty(const _type&) ynothrow
617 {
618 return true;
619 }
621
622
641 template<class _tTraits, typename _tRet, typename... _tParams>
642 class function_base<_tTraits, _tRet(_tParams...)> : private equality_comparable<
643 function_base<_tTraits, _tRet(_tParams...)>, nullptr_t>
644 {
645 public:
647
648 using result_type = _tRet;
649
650 private:
651 template<class _tHandler>
652 struct invoker
653 {
654 static _tRet
655 invoke(const any& a, _tParams... args)
656 // TODO: Exception specification?
657 {
658 return static_cast<_tRet>(ystdex::invoke(_tHandler::get_reference(
659 a.get_storage()), yforward(args)...));
660 }
661 };
662
663 // XXX: The empty state is solely determined by %content, having nothing to
664 // do with %p_invoke.
665 any content{default_init};
666 // XXX: The invoker pointer outside %content would cause the %function
667 // object not fit in %any, as well as cost of copy, move and swap. This
668 // is reasonable at the cost for fast invocation in %operator().
669 _tRet(*p_invoke)(const any&, _tParams...);
670
671 public:
672 function_base() ynothrow
673 {
674 _tTraits::init_empty(content, p_invoke);
675 }
677 template<class _tAlloc>
678 inline
679 function_base(std::allocator_arg_t, const _tAlloc&) ynothrow
680 : function_base()
681 {}
682 function_base(nullptr_t) ynothrow
683 : function_base()
684 {}
686 template<class _tAlloc>
687 inline
688 function_base(std::allocator_arg_t, const _tAlloc&, nullptr_t,
689 const _tAlloc&) ynothrow
690 : function_base()
691 {}
697 template<typename _fCallable, yimpl(typename
698 = exclude_self_t<function_base, _fCallable>), yimpl(typename
699 = enable_if_t<is_invocable_r<_tRet, _fCallable&, _tParams...>::value>)>
700 function_base(_fCallable f)
701 {
702 if(ystdex::function_not_empty(f))
703 yunseq(content = any(std::move(f)),
704 // XXX: Here lambda-expression is buggy in G++ LTO.
705 p_invoke = invoker<any_ops::value_handler<_fCallable>>::invoke);
706 else
707 _tTraits::init_empty(content, p_invoke);
708 }
710 template<typename _fCallable, class _tAlloc, yimpl(typename
711 = exclude_self_t<function_base, _fCallable>), yimpl(typename
712 = enable_if_t<is_invocable_r<_tRet, _fCallable&, _tParams...>::value>)>
713 function_base(std::allocator_arg_t, const _tAlloc& a, _fCallable f)
714 {
715 if(ystdex::function_not_empty(f))
716 yunseq(content = any(std::allocator_arg, a, std::move(f)),
717 // XXX: Here lambda-expression is buggy in G++ LTO.
718 p_invoke = invoker<any::allocated_value_handler_t<_tAlloc,
719 _fCallable>>::invoke);
720 else
721 _tTraits::init_empty(content, p_invoke);
722 }
723 function_base(const function_base&) = default;
728 template<class _tAlloc>
729 function_base(std::allocator_arg_t, const _tAlloc& a,
730 const function_base& x)
731 : content(std::allocator_arg, a, x), p_invoke(x.p_invoke)
732 {}
733 // NOTE: The 'ynothrow' is presented as a conforming extension to ISO C++17,
734 // as well as a conforming extension of WG21 P0288.
735 // XXX: The moved-from value is valid but unspecified. It is empty here to
736 // simplify the implementation (as libstdc++ does), which is still not
737 // guaranteed by the interface.
738 function_base(function_base&&) ynothrow = default;
743 template<class _tAlloc>
744 function_base(std::allocator_arg_t, const _tAlloc& a, function_base&& x)
745 : content(std::allocator_arg, a, std::move(x)), p_invoke(x.p_invoke)
746 {}
747
748 function_base&
749 operator=(nullptr_t) ynothrow
750 {
751 content = any();
752 _tTraits::init_empty(content, p_invoke);
753 return *this;
754 }
756 template<typename _fCallable, yimpl(typename
757 = exclude_self_t<function_base, _fCallable>), yimpl(typename
758 = enable_if_t<is_invocable_r<_tRet, _fCallable&, _tParams...>::value>)>
759 function_base&
760 operator=(_fCallable&& f)
761 {
762 // NOTE: Efficiency consideration is simliar to %any::operator=, as
763 // construction of %p_invoke here is simple enough.
764 return *this = function_base(std::move(f));
765 }
766 template<typename _fCallable>
767 function_base&
768 operator=(std::reference_wrapper<_fCallable> f) ynothrow
769 {
770 // NOTE: Ditto.
771 return *this = function_base(f);
772 }
773 // NOTE: Ditto.
774 function_base&
775 operator=(const function_base&) yimpl(= default);
776 // NOTE: Ditto.
777 function_base&
778 operator=(function_base&& f) ynothrow yimpl(= default);
779
780 YB_ATTR_nodiscard YB_PURE friend bool
781 operator==(const function_base& f, nullptr_t) ynothrow
782 {
783 return !f;
784 }
785
790 _tRet
791 operator()(_tParams... args) const
792 {
793 return _tTraits::call(content, p_invoke, yforward(args)...);
794 }
795
796 YB_ATTR_nodiscard YB_PURE explicit
797 operator bool() const ynothrow
798 {
799 return content.has_value();
800 }
801
803 void
804 swap(function_base& f) ynothrow
805 {
806 std::swap(p_invoke, f.p_invoke),
807 content.swap(f.content);
808 }
809 friend void
810 swap(function_base& x, function_base& y) ynothrow
811 {
812 return x.swap(y);
813 }
814
815 template<typename _type>
816 YB_ATTR_nodiscard YB_PURE _type*
817 target() ynothrow
818 {
819 return content.template try_get_object_ptr<_type>();
820 }
821 template<typename _type>
822 YB_ATTR_nodiscard YB_PURE const _type*
823 target() const ynothrow
824 {
825 return content.template try_get_object_ptr<_type>();
826 }
827
828 YB_ATTR_nodiscard YB_PURE const type_info&
829 target_type() const ynothrow
830 {
831 return content.type();
832 }
834 };
835
837
838 template<class _tTraits, typename _fSig>
840 struct make_parameter_list<function_base<_tTraits, _fSig>>
841 : make_parameter_list<_fSig>
842 {};
843
844 template<class _tTraits, typename _fSig>
845 struct return_of<function_base<_tTraits, _fSig>> : return_of<_fSig>
846 {};
847
849
850 template<class _tTraits, typename _tFrom, typename _tTo,
851 typename... _tFromParams, typename... _tToParams>
852 struct is_covariant<function_base<_tTraits, _tFrom(_tFromParams...)>,
853 function_base<_tTraits, _tTo(_tToParams...)>>
854 : is_covariant<_tFrom(_tFromParams...), _tTo(_tToParams...)>
855 {};
856
857 template<class _tTraits, typename _tResFrom, typename _tResTo,
858 typename... _tFromParams, typename... _tToParams>
859 struct is_contravariant<function_base<_tTraits, _tResFrom(_tFromParams...)>,
860 function_base<_tTraits, _tResTo(_tToParams...)>>
861 : is_contravariant<_tResFrom(_tFromParams...), _tResTo(_tToParams...)>
862 {};
864
866 template<class _tTraits, typename _tRet, typename _tUnused,
867 typename... _tParams>
868 struct make_function_type<_tRet, function_base<_tTraits, _tUnused(_tParams...)>>
869 : make_function_type<_tRet, empty_base<_tParams...>>
870 {};
871
873 template<class _tTraits, typename _tRet, typename... _tParams, size_t... _vSeq>
874 struct call_projection<function_base<_tTraits, _tRet(_tParams...)>,
875 index_sequence<_vSeq...>>
876 : call_projection<_tRet(_tParams...), index_sequence<_vSeq...>>
877 {};
879
880
881
883
884 template<typename _fSig>
885 using unchecked_function = function_base<function_traits<_fSig,
886 empty_function_policy::no_check>, _fSig>;
887
888 template<typename _fSig>
889 using optional_function = function_base<function_traits<_fSig,
890 empty_function_policy::no_effect>, _fSig>;
891
898 template<typename _fSig>
899 using function = function_base<function_traits<_fSig,
900 empty_function_policy::throwing>, _fSig>;
902
903 } // namespace ystdex;
904
905 #endif
906
ystdex::function_base< _tTraits, _tRet(_tParams...)>::function_base
function_base(function_base &&)=default
ystdex::call_projection
调用投影：向原调用传递序列指定的位置的参数。
Definition: apply.hpp:70
ystdex::cpp2017::is_invocable_r
Definition: invoke.hpp:369
YB_ATTR_nodiscard
#define YB_ATTR_nodiscard
标记返回值不被忽略的属性。
Definition: ydef.h:715
x
const EncapsulationBase & x
Definition: NPLA1Forms.cpp:1536
ystdex::empty_base
空基类模板。
Definition: ydef.h:1424
ystdex::variadic_param::get
static auto get(_type &&, _tParams &&... args) -> decltype(variadic_param< _vN - 1 >::get(std::forward< decltype(args)>(args)...))
Definition: function.hpp:232
ystdex::cpp2017::swap
void swap(optional< _type > &x, optional< _type > &y)
Definition: optional.h:888
ystdex::function_base< _tTraits, _tRet(_tParams...)>::operator()
_tRet operator()(_tParams... args) const
Definition: function.hpp:791
ystdex::make_parameter_list
取参数列表。
Definition: function.hpp:332
ystdex::is_contravariant
判断指定类型之间是否逆变。
Definition: function.hpp:179
ystdex::function_base< _tTraits, _tRet(_tParams...)>::function_base
function_base()
Definition: function.hpp:672
ystdex::is_covariant
判断指定类型之间是否协变。
Definition: function.hpp:145
ystdex::invoke
invoke_result_t< _fCallable, _tParams... > invoke(_fCallable &&f, _tParams &&... args)
调用可调用对象。
Definition: invoke.hpp:538
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:1072
YB_PURE
#define YB_PURE
指示函数或函数模板实例为纯函数。
Definition: ydef.h:919
ystdex::function_base< _tTraits, _tRet(_tParams...)>::operator==
friend bool operator==(const function_base &f, nullptr_t)
Definition: function.hpp:781
ystdex::function_base< _tTraits, _tRet(_tParams...)>::function_base
function_base(std::allocator_arg_t, const _tAlloc &a, const function_base &x)
Definition: function.hpp:729
ystdex::make_function_type_t
_t< make_function_type< _tRet, _tTuple > > make_function_type_t
Definition: function.hpp:391
ystdex::function_base< _tTraits, _tRet(_tParams...)>::swap
void swap(function_base &f)
Definition: function.hpp:804
ystdex::unseq_apply
void unseq_apply(_func &&f, _tParams &&... args)
无序调用。
Definition: function.hpp:314
ystdex::chain_apply
void chain_apply(_func &&f)
顺序链式调用。
Definition: function.hpp:279
ystdex::parameter_of
取指定索引的参数类型。
Definition: function.hpp:360
ystdex::function_traits< _tRet(_tParams...), empty_function_policy::no_effect >::invoke_empty
static _tRet invoke_empty(const _tContent &, _tParams...)
Definition: function.hpp:508
YSLib::IO::_tTraits
const string &path const String &path class class _tTraits
Definition: YSLib/Service/FileSystem.h:582
ystdex::cpp2014::enable_if_t
typename enable_if< _bCond, _type >::type enable_if_t
Definition: meta.hpp:199
ystdex::function_base
函数包装类模板。
Definition: function.hpp:578
ystdex::dep_ops::equality_comparable
_t< details::ops_seq< _type, _type2, _tOpt, cond_t< is_same< _type, _type2 >, index_sequence< 7 >, index_sequence< 6, 7, 8 > >> > equality_comparable
Definition: operators.hpp:265
ystdex::function_base< _tTraits, _tRet(_tParams...)>::operator=
function_base & operator=(nullptr_t)
Definition: function.hpp:749
ystdex::function_base< _tTraits, _tRet(_tParams...)>::function_base
function_base(const function_base &)=default
ystdex::variadic_param< 0U >::get
static auto get(_type &&arg) -> decltype(std::forward< decltype(arg)>(arg))
Definition: function.hpp:248
ynoexcept_spec
#define ynoexcept_spec(...)
表达式 noexcept 异常规范。
Definition: ydef.h:1181
ystdex::nullptr_t
空指针类。
Definition: ydef.h:1321
ystdex::seq_apply
void seq_apply(_func &&)
顺序递归调用。
Definition: function.hpp:298
ystdex::function_traits< _tRet(_tParams...), empty_function_policy::throwing >::init_empty
static void init_empty(const _tContent &, _fInvoke &f)
Definition: function.hpp:553
CHRLib::f
f(d, s)
yconstfn_relaxed
#define yconstfn_relaxed
指定编译时没有 C++11 限制和隐式成员 const 的常量函数。
Definition: ydef.h:1097
ystdex::default_init
const struct ystdex::default_init_t default_init
CHRLib::args
YB_ATTR_nodiscard _tParams && args
Definition: CharacterProcessing.h:649
ystdex::bool_
integral_constant< bool, _vInt > bool_
Definition: integral_constant.hpp:93
YB_Impl_Functional_ret_spec_f
#define YB_Impl_Functional_ret_spec_f(_e)
Definition: function.hpp:113
ystdex::empty_function_policy
empty_function_policy
空函数策略。
Definition: function.hpp:455
ystdex::details::ret_of
Definition: function.hpp:104
ystdex::make_function_type< _tRet, empty_base< _tParams... > >::type
_tRet(_tParams...) type
Definition: function.hpp:396
ystdex::details::_type2
_type2
Definition: operators.hpp:241
yassume
#define yassume(_expr)
假定：环境语义。
Definition: cassert.h:96
ystdex::parameter_of::type
vseq::at_t< make_parameter_list_t< _fCallable >, _vIdx > type
Definition: function.hpp:361
ystdex::empty_function_policy::no_check
@ no_check
调用空值行为未定义。
ystdex::function_traits< _tRet(_tParams...), empty_function_policy::no_effect >::call
static _tRet call(const _tContent &content, const _fInvoke &f, _tParams &&... args)
Definition: function.hpp:527
ystdex::any::allocated_value_handler_t
cond_t< any::opt_in_place_t< _type >, any_ops::value_handler< _type >, any_ops::allocator_value_handler_t< _tAlloc, _type > > allocated_value_handler_t
根据分配器类型和存储对象的类型取使用分配器构造时的处理器。
Definition: any.h:1689
any.h
动态泛型类型。
ystdex::function_base< _tTraits, _tRet(_tParams...)>::function_base
function_base(std::allocator_arg_t, const _tAlloc &a, _fCallable f)
Definition: function.hpp:713
ystdex::vseq::seq_size_t
_t< seq_size< _tSeq, _tEnabler > > seq_size_t
Definition: variadic.hpp:527
ystdex::function_traits< _tRet(_tParams...), empty_function_policy::throwing >::invoke_empty
static _tRet invoke_empty(const _tContent &, _tParams...)
Definition: function.hpp:545
YB_NORETURN
#define YB_NORETURN
指定无返回值函数。
Definition: ydef.h:877
yforward
#define yforward(_expr)
根据参数类型使用 std::forward 转发对应参数。
Definition: ydef.h:1508
ystdex::function_base< _tTraits, _tRet(_tParams...)>::target_type
const type_info & target_type() const
Definition: function.hpp:829
ystdex::function_base< _tTraits, _tRet(_tParams...)>::result_type
_tRet result_type
Definition: function.hpp:648
ystdex::make_function_type
取指定返回类型和元组指定参数类型的函数类型。
Definition: function.hpp:388
std
Definition: optional.h:982
YB_ATTR
#define YB_ATTR(...)
GNU 风格属性。
Definition: ydef.h:567
ystdex::function_base< _tTraits, _tRet(_tParams...)>::function_base
function_base(_fCallable f)
Definition: function.hpp:700
operators.hpp
重载操作符。
ystdex::function_base< _tTraits, _tRet(_tParams...)>::swap
friend void swap(function_base &x, function_base &y)
Definition: function.hpp:810
yunseq
#define yunseq
无序列依赖表达式组求值。
Definition: ydef.h:1535
ystdex::function_base< _tTraits, _tRet(_tParams...)>::operator=
function_base & operator=(const function_base &)=default
ystdex::function_base< _tTraits, _tRet(_tParams...)>::operator=
function_base & operator=(function_base &&f)=default
ystdex::return_of
取返回类型。
Definition: function.hpp:345
YB_Impl_Functional_ret_spec_mf
#define YB_Impl_Functional_ret_spec_mf(_e)
Definition: function.hpp:122
yconstraint
#define yconstraint(_expr)
约束：接口语义。
Definition: cassert.h:125
YSLib::UI::y
SPos SPos y
Definition: YWidget.cpp:44
ystdex::parameter_of_t
_t< parameter_of< _vIdx, _fCallable > > parameter_of_t
Definition: function.hpp:366
ystdex::function_base< _tTraits, _tRet(_tParams...)>::operator=
function_base & operator=(_fCallable &&f)
Definition: function.hpp:760
ystdex::true_
bool_< true > true_
Definition: integral_constant.hpp:109
ystdex::make_parameter_list_t
_t< make_parameter_list< _fCallable > > make_parameter_list_t
Definition: function.hpp:335
ystdex::function_traits< _tRet(_tParams...), empty_function_policy::no_effect >::init_empty
static void init_empty(const _tContent &, _fInvoke &f)
Definition: function.hpp:516
ystdex::function_base< _tTraits, _tRet(_tParams...)>::function_base
function_base(std::allocator_arg_t, const _tAlloc &, nullptr_t, const _tAlloc &)
Definition: function.hpp:688
ystdex::exclude_self_t
enable_if_t<!is_same_param< _tSelected, _tParam >::value, _type > exclude_self_t
排除选择类型的特定参数的重载。
Definition: meta.hpp:865
ystdex::vseq::at_t
_t< at< _tSeq, _vIdx, _tEnabler > > at_t
Definition: variadic.hpp:548
ystdex::function_base< _tTraits, _tRet(_tParams...)>::target
_type * target()
Definition: function.hpp:817
ystdex::function_base< _tTraits, _tRet(_tParams...)>::function_base
function_base(nullptr_t)
Definition: function.hpp:682
ystdex::variadic_param
变长参数操作模板。
Definition: function.hpp:228
ystdex::paramlist_size
取参数列表大小。
Definition: function.hpp:377
ystdex::function_not_empty
static bool function_not_empty(const std::function< _fSig > &f)
判断是否符合 std::function 实现初始化为空函数对象的条件。
Definition: function.hpp:590
ystdex::sizeof_params
size_t sizeof_params(_tParams &&...)
统计函数参数列表中的参数个数。
Definition: function.hpp:216
ystdex
<memory> 特性测试宏。
Definition: ydef.h:1262
ystdex::function_traits
函数包装特征。
Definition: function.hpp:477
YSLib::_tParams
YB_ATTR_nodiscard YB_PURE typename _tParams
Definition: ValueNode.h:1294
ystdex::any
基于类型擦除的动态泛型对象。
Definition: any.h:1634
ystdex::_t
typename _type::type _t
嵌套类型别名。
Definition: meta.hpp:45
ystdex::function_base< _tTraits, _tRet(_tParams...)>::function_base
function_base(std::allocator_arg_t, const _tAlloc &)
Definition: function.hpp:679
ystdex::function_traits< _tRet(_tParams...), empty_function_policy::no_check >::call
static _tRet call(const _tContent &content, const _fInvoke &f, _tParams &&... args)
Definition: function.hpp:489
ystdex::is_detected
typename details::detector< nonesuch, void, _gOp, _tParams... >::value_t is_detected
Definition: meta.hpp:396
ystdex::function_base< _tTraits, _tRet(_tParams...)>::operator=
function_base & operator=(std::reference_wrapper< _fCallable > f)
Definition: function.hpp:768
ystdex::cpp2014::integer_sequence
Definition: integer_sequence.hpp:53
ystdex::as_function_type_t
make_function_type_t< return_of_t< _fCallable >, make_parameter_list_t< _fCallable > > as_function_type_t
取内建函数类型。
Definition: function.hpp:421
ystdex::function_base< _tTraits, _tRet(_tParams...)>::invoker::invoke
static _tRet invoke(const any &a, _tParams... args)
Definition: function.hpp:655
platform::p
return p p
Definition: YCLib/FileSystem.h:209
ystdex::details::mk_plist
Definition: function.hpp:81
ystdex::empty_function_policy::throwing
@ throwing
调用空值抛出 std::bad_function_call 。
ystdex::function
function_base< function_traits< _fSig, empty_function_policy::throwing >, _fSig > function
函数包装类模板。
Definition: function.hpp:900
const
const Decapsulate const Decapsulate &y ynothrow ContextNode &ctx const
Definition: NPLA1Forms.cpp:1629
yimpl
#define yimpl(...)
实现标签。
Definition: ydef.h:413
platform::bool
YB_ATTR_nodiscard std::FILE *fp bool
Definition: FileIO.h:1271
ystdex::return_of_t
_t< return_of< _fCallable > > return_of_t
Definition: function.hpp:349
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:1199
apply.hpp
元组应用操作。
ystdex::function_base< _tTraits, _tRet(_tParams...)>::target
const _type * target() const
Definition: function.hpp:823
ystdex::vseq::at
取指定位置的元素。
Definition: variadic.hpp:548
ystdex::function_traits< _tRet(_tParams...), empty_function_policy::throwing >::call
static _tRet call(const _tContent &content, const _fInvoke &f, _tParams &&... args)
Definition: function.hpp:561
YB_Impl_Functional_ptuple_spec
#define YB_Impl_Functional_ptuple_spec(_exp, _p, _e)
Definition: function.hpp:83
ystdex::id_func_t
make_function_type_t< _type, vseq::join_n_t< _vN, empty_base< _tParam > >> id_func_t
取指定维数和指定参数类型的多元映射扩展恒等函数类型。
Definition: function.hpp:436
ystdex::empty_function_policy::no_effect
@ no_effect
调用空值无作用。
ynoexcept
#define ynoexcept(...)
YSLib 无异常抛出保证：指定特定的异常规范。
Definition: ydef.h:1151
ystdex::varg
auto varg(_tParams &&... args) -> decltype(variadic_param< _vN >::get(std::forward< decltype(args)>(args)...))
取指定位置的变长参数。
Definition: function.hpp:262
ystdex::any_ops::value_handler
动态泛型对象值处理器。
Definition: any.h:524
ystdex::details::elements_convertible
Definition: function.hpp:51
yconstfn
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:1073
YSLib::a
YB_PURE const _type * a
Definition: YCoreUtilities.h:168
ystdex::enable_fallback_t
enable_if_t<!is_detected< _gOp, _tParams &&... >::value, decltype(std::declval< _func >()(std::declval< _tParams >()...))> enable_fallback_t
启用备用重载。
Definition: function.hpp:430
ystdex::id_func_clr_t
id_func_t< _type, _vN, const _type & > id_func_clr_t
取指定维数和 const 左值引用参数类型的多元映射扩展恒等函数类型。
Definition: function.hpp:440
ystdex::function_traits< _tRet(_tParams...), empty_function_policy::no_check >::init_empty
static void init_empty(const _tContent &, _fInvoke &)
Definition: function.hpp:484
ystdex::id_func_rr_t
id_func_t< _type, _vN, _type && > id_func_rr_t
取指定维数和 const 右值引用参数类型的多元映射扩展恒等函数类型。
Definition: function.hpp:444