YSTest: functional.hpp 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

functional.hpp
浏览该文件的文档.
1 /*
2 © 2010-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_functional_hpp_
29 #define YB_INC_ystdex_functional_hpp_ 1
30
31 #include "functor.hpp" // for "ref.hpp", "invoke.hpp", <functional>,
32 // exclude_self_t, addressof_op, less, mem_get, true_, false_, is_void,
33 // is_constructible, enable_if_t, std::allocator_arg_t, std::allocator_arg,
34 // is_nothrow_copy_constructible;
35 #include "function.hpp" // for "function.hpp", std::tuple, index_sequence,
36 // index_sequence_for, is_nothrow_swappable, common_nonvoid_t,
37 // make_index_sequence, as_function_type_t, equality_comparable;
38 #include "swap.hpp" // for "swap.hpp", ystdex::swap_dependent;
39 #include "apply.hpp" // for call_projection;
40 #include <numeric> // for std::accumulate;
41
42 namespace ystdex
43 {
44
50 template<typename _func, typename... _tParams>
52 YB_ATTR_nodiscard YB_PURE inline auto
53 bind1(_func&& f, _tParams&&... args) -> decltype(
54 std::bind(yforward(f), std::placeholders::_1, yforward(args)...))
55 {
56 return std::bind(yforward(f), std::placeholders::_1, yforward(args)...);
57 }
59 template<typename _tRes, typename _func, typename... _tParams>
60 YB_ATTR_nodiscard YB_PURE inline auto
61 bind1(_func&& f, _tParams&&... args) -> decltype(
62 std::bind<_tRes>(yforward(f), std::placeholders::_1, yforward(args)...))
63 {
64 return
65 std::bind<_tRes>(yforward(f), std::placeholders::_1, yforward(args)...);
66 }
68
75 template<typename _func, typename _func2, typename... _tParams>
76 YB_ATTR_nodiscard YB_PURE inline auto
77 bind_forward(_func&& f, _func2&& f2, _tParams&&... args)
78 -> decltype(ystdex::bind1(yforward(f), std::bind(yforward(f2),
79 std::placeholders::_2, yforward(args)...)))
80 {
81 return ystdex::bind1(yforward(f), std::bind(yforward(f2),
82 std::placeholders::_2, yforward(args)...));
83 }
84
85
87
88 template<typename _func, typename _func2>
90 struct composed
91 {
92 _func f;
93 _func2 g;
94
99 template<typename... _tParams>
100 yconstfn auto
101 operator()(_tParams&&... args) const ynoexcept_spec(f(g(yforward(args)...)))
102 -> decltype(f(g(yforward(args)...)))
103 {
104 return f(g(yforward(args)...));
105 }
106 };
107
115 template<typename _func, typename _func2>
116 YB_ATTR_nodiscard YB_PURE yconstfn composed<_func, _func2>
117 compose(_func f, _func2 g)
118 {
119 return composed<_func, _func2>{f, g};
120 }
122 template<typename _func, typename _func2, typename _func3, typename... _funcs>
123 YB_ATTR_nodiscard YB_PURE yconstfn auto
124 compose(_func f, _func2 g, _func3 h, _funcs... args)
125 -> decltype(ystdex::compose(ystdex::compose(f, g), h, args...))
126 {
127 return ystdex::compose(ystdex::compose(f, g), h, args...);
128 }
130
131
132
134
135 template<typename _func, typename _func2>
137 struct composed_n
138 {
139 _func f;
140 _func2 g;
141
143 template<typename... _tParams>
144 yconstfn auto
145 operator()(_tParams&&... args) const ynoexcept_spec(f(g(yforward(args))...))
146 -> decltype(f(g(yforward(args))...))
147 {
148 return f(g(yforward(args))...);
149 }
150 };
151
159 template<typename _func, typename _func2>
161 yconstfn composed_n<_func, _func2>
162 compose_n(_func f, _func2 g)
163 {
164 return composed_n<_func, _func2>{f, g};
165 }
166 template<typename _func, typename _func2, typename _func3, typename... _funcs>
167 yconstfn auto
168 compose_n(_func f, _func2 g, _func3 h, _funcs... args)
169 -> decltype(ystdex::compose_n(ystdex::compose_n(f, g), h, args...))
170 {
171 return ystdex::compose_n(ystdex::compose_n(f, g), h, args...);
172 }
174
175
177 template<typename _func, typename... _funcs>
178 struct generalized_composed
179 {
180 _func f;
181 std::tuple<_funcs...> g;
182
183 template<typename... _tParams>
184 yconstfn auto
185 operator()(_tParams&&... args) const ynoexcept_spec(yimpl(call(
186 index_sequence_for<_tParams...>(), yforward(args)...))) -> decltype(
187 yimpl(call(index_sequence_for<_tParams...>(), yforward(args)...)))
188 {
189 return call(index_sequence_for<_tParams...>(), yforward(args)...);
190 }
191
192 private:
193 template<size_t... _vSeq, typename... _tParams>
194 yconstfn auto
195 call(index_sequence<_vSeq...>, _tParams&&... args) const
196 ynoexcept_spec(f(std::get<_vSeq>(g)(yforward(args))...))
197 -> decltype(f(std::get<_vSeq>(g)(yforward(args))...))
198 {
199 return f(std::get<_vSeq>(g)(yforward(args))...);
200 }
201 };
202
208 template<typename _func, typename... _funcs>
209 yconstfn generalized_composed<_func, std::tuple<_funcs...>>
210 generalized_compose(_func f, _funcs... args)
211 {
212 return generalized_composed<_func,
213 std::tuple<_funcs...>>{f, make_tuple(args...)};
214 }
216
217
223 template<class _tThunk, typename _func>
224 void
225 update_thunk(_tThunk& thunk, _func&& f)
226 {
227 // TODO: Blocked. Use C++14 lambda initializers to simplify the
228 // implementation.
229 thunk = std::bind([&thunk](_tThunk& tnk, const _func& cur){
230 thunk = std::move(tnk);
231 cur();
232 }, std::move(thunk), yforward(f));
233 }
234
235
245 template<typename _func, typename _tRes = void, typename _tState = bool>
246 struct one_shot
247 {
248 static_assert(is_nothrow_move_constructible<_func>(),
249 "Invalid target type found.");
250 static_assert(is_nothrow_move_constructible<_tRes>(),
251 "Invalid result type found.");
252 static_assert(is_nothrow_swappable<_tState>(),
253 "Invalid state type found.");
254
255 _func func;
256 mutable _tRes result;
257 mutable _tState fresh{};
258
260 template<typename _type, typename _type2 = _tState,
261 yimpl(typename = exclude_self_t<one_shot, _type>)>
262 one_shot(_type&& f, _tRes r = {}, _type2&& s = {})
263 : func(yforward(f)), result(r), fresh(yforward(s))
264 {}
265 one_shot(one_shot&& f) ynothrow
266 : func(std::move(f.func)), result(std::move(f.result))
267 {
268 ystdex::swap_dependent(fresh, f.fresh);
269 }
270
272 one_shot&
273 operator=(one_shot&& f) ynothrow
274 {
275 ystdex::swap_dependent(*this, f);
276 return *this;
277 }
278
279 template<typename... _tParams>
280 yconstfn_relaxed auto
281 operator()(_tParams&&... args) const
282 ynoexcept(noexcept(func(yforward(args)...)))
283 -> decltype(func(yforward(args)...))
284 {
285 if(fresh)
286 {
287 result = func(yforward(args)...);
288 fresh = {};
289 }
290 return std::forward<_tRes>(result);
291 }
292 };
293
294 template<typename _func, typename _tState>
295 struct one_shot<_func, void, _tState>
296 {
297 static_assert(is_nothrow_move_constructible<_func>(),
298 "Invalid target type found.");
299 static_assert(is_nothrow_swappable<_tState>(),
300 "Invalid state type found.");
301
302 _func func;
303 mutable _tState fresh{};
304
306 template<typename _type, typename _type2 = _tState,
307 yimpl(typename = exclude_self_t<one_shot, _type>)>
308 one_shot(_type&& f, _type2&& s = {})
309 : func(yforward(f)), fresh(yforward(s))
310 {}
311 one_shot(one_shot&& f) ynothrow
312 : func(std::move(f.func))
313 {
314 ystdex::swap_dependent(fresh, f.fresh);
315 }
316
318 one_shot&
319 operator=(one_shot&& f) ynothrow
320 {
321 ystdex::swap_dependent(*this, f);
322 return *this;
323 }
324
325 template<typename... _tParams>
326 yconstfn_relaxed void
327 operator()(_tParams&&... args) const
328 ynoexcept(noexcept(func(yforward(args)...)))
329 {
330 if(fresh)
331 {
332 func(yforward(args)...);
333 fresh = {};
334 }
335 }
336 };
337
338 template<typename _func, typename _tRes>
339 struct one_shot<_func, _tRes, void>
340 {
341 static_assert(is_nothrow_move_constructible<_func>(),
342 "Invalid target type found.");
343 static_assert(is_nothrow_move_constructible<_tRes>(),
344 "Invalid result type found.");
345
346 mutable _func func;
347 mutable _tRes result;
348
349 one_shot(_func f, _tRes r = {})
350 : func(f), result(r)
351 {}
352
353 template<typename... _tParams>
354 yconstfn_relaxed auto
355 operator()(_tParams&&... args) const
356 ynoexcept(noexcept(func(yforward(args)...)))
357 -> decltype(func(yforward(args)...) && noexcept(func = {}))
358 {
359 if(func)
360 {
361 result = func(yforward(args)...);
362 func = {};
363 }
364 return std::forward<_tRes>(result);
365 }
366 };
367
368 template<typename _func>
369 struct one_shot<_func, void, void>
370 {
371 static_assert(is_nothrow_move_constructible<_func>(),
372 "Invalid target type found.");
373
374 mutable _func func;
375
376 one_shot(_func f)
377 : func(f)
378 {}
379
380 template<typename... _tParams>
381 yconstfn_relaxed void
382 operator()(_tParams&&... args) const
383 ynoexcept(noexcept(func(yforward(args)...) && noexcept(func = {})))
384 {
385 if(func)
386 {
387 func(yforward(args)...);
388 func = {};
389 }
390 }
391 };
393
394
400
402 template<typename _type = void>
403 struct get_equal_to
404 : composed_n<equal_to<_type*>, composed<addressof_op<_type>, mem_get<>>>
405 {};
406
407 template<>
408 struct get_equal_to<void>
409 : composed_n<equal_to<>, composed<addressof_op<>, mem_get<>>>
410 {};
412
414
415 template<typename _type = void>
416 struct get_less
417 : composed_n<less<_type*>, composed<addressof_op<_type>, mem_get<>>>
418 {};
419
420 template<>
421 struct get_less<void>
422 : composed_n<less<>, composed<addressof_op<>, mem_get<>>>
423 {};
425
426
427
429 namespace details
430 {
431
433 template<typename _type, typename _fCallable, typename... _tParams>
434 YB_ATTR_nodiscard _type
435 invoke_for_value(true_, _type&& val, _fCallable&& f, _tParams&&... args)
436 {
437 ystdex::invoke(yforward(f), yforward(args)...);
438 return yforward(val);
439 }
440
442 template<typename _type, typename _fCallable, typename... _tParams>
443 YB_ATTR_nodiscard auto
444 invoke_for_value(false_, _type&&, _fCallable&& f, _tParams&&... args)
445 -> invoke_result_t<_fCallable, _tParams...>
446 {
447 return ystdex::invoke(yforward(f), yforward(args)...);
448 }
449
450 } // unnamed namespace;
451
456 template<typename _type, typename _fCallable, typename... _tParams>
457 YB_ATTR_nodiscard auto
458 invoke_for_value(_type&& val, _fCallable&& f, _tParams&&... args)
459 -> common_nonvoid_t<invoke_result_t<_fCallable, _tParams...>, _type>
460 {
461 return details::invoke_for_value(is_void<invoke_result_t<_fCallable,
462 _tParams...>>(), yforward(val), yforward(f), yforward(args)...);
463 }
464
465
467
468 template<typename _fCallable, size_t _vLen = paramlist_size<_fCallable>::value>
469 struct expand_proxy : private call_projection<_fCallable,
470 make_index_sequence<_vLen>>, private expand_proxy<_fCallable, _vLen - 1>
471 {
478
480 using call_projection<_fCallable, make_index_sequence<_vLen>>::apply_call;
481 template<typename... _tParams>
482 static auto
483 apply_call(_tParams&&... args) -> decltype(
484 expand_proxy<_fCallable, _vLen - 1>::apply_call(yforward(args)...))
485 {
486 return expand_proxy<_fCallable, _vLen - 1>::apply_call(
487 yforward(args)...);
488 }
489
490 using call_projection<_fCallable, make_index_sequence<_vLen>>::apply_invoke;
491 template<typename... _tParams>
492 static auto
493 apply_invoke(_tParams&&... args) -> decltype(
494 expand_proxy<_fCallable, _vLen - 1>::apply_invoke(yforward(args)...))
495 {
496 return expand_proxy<_fCallable, _vLen - 1>::apply_invoke(
497 yforward(args)...);
498 }
500
501 using call_projection<_fCallable, make_index_sequence<_vLen>>::call;
503 template<typename... _tParams>
504 static auto
505 call(_tParams&&... args) -> decltype(
506 expand_proxy<_fCallable, _vLen - 1>::call(yforward(args)...))
507 {
508 return expand_proxy<_fCallable, _vLen - 1>::call(yforward(args)...);
509 }
510
512
513 using call_projection<_fCallable, make_index_sequence<_vLen>>::invoke;
514 template<typename... _tParams>
515 static auto
516 invoke(_tParams&&... args) -> decltype(
517 expand_proxy<_fCallable, _vLen - 1>::invoke(yforward(args)...))
518 {
519 return expand_proxy<_fCallable, _vLen - 1>::invoke(yforward(args)...);
520 }
522
523 };
524
525 template<typename _fCallable>
526 struct expand_proxy<_fCallable, 0>
527 : private call_projection<_fCallable, index_sequence<>>
528 {
530 using call_projection<_fCallable, index_sequence<>>::apply_call;
531
533 using call_projection<_fCallable, index_sequence<>>::apply_invoke;
534
535 using call_projection<_fCallable, index_sequence<>>::call;
536
538 using call_projection<_fCallable, index_sequence<>>::invoke;
539 };
541
542
552 template<typename _fCond, typename _fCallable, typename... _tParams>
553 invoke_result_t<_fCallable, _tParams...>
554 retry_on_cond(_fCond cond, _fCallable&& f, _tParams&&... args)
555 {
556 using res_t = invoke_result_t<_fCallable, _tParams...>;
557 using obj_t = object_result_t<res_t>;
558 obj_t res;
559
560 do
561 res = ystdex::invoke_nonvoid(yforward(f), yforward(args)...);
562 while(expand_proxy<bool(obj_t&)>::call(cond, res));
563 return res_t(res);
564 }
565
566
572 template<typename _fHandler, typename _fCaller>
573 struct expanded_caller
574 {
576 static_assert(is_object<_fCaller>(), "Callable object type is needed.");
577
579 _fCaller caller;
580
582
583 expanded_caller() = default;
584 template<typename _func,
585 yimpl(typename = exclude_self_t<expanded_caller, _fCaller>)>
586 expanded_caller(_func f)
587 : caller(yforward(f))
588 {}
589 expanded_caller(const expanded_caller&) = default;
590 expanded_caller(expanded_caller&&) = default;
591
592 expanded_caller&
593 operator=(const expanded_caller&) = default;
594 expanded_caller&
595 operator=(expanded_caller&&) = default;
597
599 template<typename... _tParams>
600 inline auto
601 operator()(_tParams&&... args) const
602 -> decltype(expand_proxy<_fHandler>::call(caller, yforward(args)...))
603 {
604 return expand_proxy<_fHandler>::call(caller, yforward(args)...);
605 }
606 };
607
614 template<typename _fHandler, typename _fCallable>
615 YB_ATTR_nodiscard YB_PURE inline expanded_caller<_fHandler, _fCallable>
616 make_expanded(_fCallable f)
617 {
618 return expanded_caller<_fHandler, _fCallable>(std::move(f));
619 }
620
621
627 template<typename _func, typename _fCallable>
628 using is_expandable = is_constructible<_func,
629 expanded_caller<as_function_type_t<_func>, _fCallable>>;
630
631
633
634
643 template<typename _fSig, class = function<_fSig>>
644 class expanded_function;
645
651 template<typename _tRet, typename... _tParams, class _tBase>
652 class expanded_function<_tRet(_tParams...), _tBase>
653 : protected _tBase, private equality_comparable<expanded_function<
654 _tRet(_tParams...), _tBase>>, private equality_comparable<
655 expanded_function<_tRet(_tParams...), _tBase>, nullptr_t>
656 {
657 public:
658 using base_type = _tBase;
659 using result_type = typename base_type::result_type;
660
661 private:
662 template<typename _fCallable>
663 using enable_if_expandable_t = enable_if_t<
664 !is_constructible<base_type, _fCallable>::value
665 && is_expandable<base_type, _fCallable>::value>;
666
667 public:
669
670 expanded_function() ynothrow
671 : base_type()
672 {}
674 expanded_function(_tRet(*f)(_tParams...)) ynothrow
675 : base_type(f)
676 {}
678 template<class _tAlloc>
679 inline
680 expanded_function(std::allocator_arg_t, const _tAlloc& a) ynothrow
681 : base_type(std::allocator_arg, a)
682 {}
684 template<class _tAlloc>
685 inline
686 expanded_function(std::allocator_arg_t, const _tAlloc& a,
687 _tRet(*f)(_tParams...)) ynothrow
688 : base_type(std::allocator_arg, a, f)
689 {}
691 template<class _fCallable, yimpl(typename = exclude_self_t<
693 expanded_function, _fCallable>, typename = enable_if_t<is_constructible<
694 base_type, _fCallable>::value>)>
695 expanded_function(_fCallable f)
696 : base_type(std::move(f))
697 {}
699 template<class _fCallable, class _tAlloc,
700 yimpl(typename = exclude_self_t<expanded_function, _fCallable>,
701 typename = enable_if_t<
702 std::is_constructible<base_type, _fCallable>::value>)>
703 expanded_function(std::allocator_arg_t, const _tAlloc& a, _fCallable&& f)
704 : base_type(std::allocator_arg, a, yforward(f))
705 {}
707 template<typename _fCallable,
708 yimpl(typename = enable_if_expandable_t<_fCallable>)>
709 expanded_function(_fCallable f)
710 : base_type(ystdex::make_expanded<_tRet(_tParams...)>(std::move(f)))
711 {}
713 template<typename _fCallable, class _tAlloc,
714 yimpl(typename = enable_if_expandable_t<_fCallable>)>
715 expanded_function(std::allocator_arg_t, const _tAlloc& a, _fCallable f)
716 : base_type(std::allocator_arg, a,
717 ystdex::make_expanded<_tRet(_tParams...)>(std::move(f)))
718 {}
725 template<class _type>
726 yconstfn
727 expanded_function(_type& obj, _tRet(_type::*pm)(_tParams...))
728 : expanded_function([&, pm](_tParams... args) ynoexcept(
729 noexcept((obj.*pm)(yforward(args)...))
730 && is_nothrow_copy_constructible<_tRet>::value){
731 return (obj.*pm)(yforward(args)...);
732 })
733 {}
734 template<class _type, class _tAlloc>
735 yconstfn
736 expanded_function(std::allocator_arg_t, const _tAlloc& a, _type& obj,
737 _tRet(_type::*pm)(_tParams...))
738 : expanded_function(std::allocator_arg, a,
739 [&, pm](_tParams... args) ynoexcept(
740 noexcept((obj.*pm)(yforward(args)...))
741 && is_nothrow_copy_constructible<_tRet>::value){
742 return (obj.*pm)(yforward(args)...);
743 })
744 {}
746
748 template<class _tAlloc>
749 expanded_function(std::allocator_arg_t, const _tAlloc& a,
750 const expanded_function& x)
751 : base_type(std::allocator_arg, a, x)
752 {}
753 template<class _tAlloc>
754 expanded_function(std::allocator_arg_t, const _tAlloc& a,
755 expanded_function&& x)
756 : base_type(std::allocator_arg, a, std::move(x))
757 {}
759 expanded_function(const expanded_function&) = default;
760 expanded_function(expanded_function&&) = default;
761
762 expanded_function&
763 operator=(nullptr_t) ynothrow
764 {
765 base_type::operator=(nullptr);
766 return *this;
767 }
768 template<typename _fCallable, yimpl(typename
769 = exclude_self_t<expanded_function, _fCallable>), yimpl(typename
770 = enable_if_t<is_invocable_r<_tRet, _fCallable&, _tParams...>::value>)>
771 expanded_function&
772 operator=(_fCallable&& f)
773 {
774 return *this = expanded_function(std::move(f));
775 }
776 template<typename _fCallable>
777 expanded_function&
778 operator=(std::reference_wrapper<_fCallable> f) ynothrow
779 {
780 return *this = expanded_function(f);
781 }
782 expanded_function&
783 operator=(const expanded_function&) = default;
784 expanded_function&
785 operator=(expanded_function&&) = default;
786
787 using base_type::operator();
788
789 using base_type::operator bool;
790
791 friend void
792 swap(expanded_function& x, expanded_function& y) ynothrow
793 {
794 ystdex::swap_dependent(static_cast< base_type&>(x),
795 static_cast< base_type&>(y));
796 }
797
798 using base_type::target;
799
800 using base_type::target_type;
801 };
802
804
805 template<typename _fSig, class _tBase>
806 struct make_parameter_list<expanded_function<_fSig, _tBase>>
807 : make_parameter_list<_fSig>
808 {};
809
810 template<typename _fSig, class _tBase>
811 struct return_of<expanded_function<_fSig, _tBase>> : return_of<_fSig>
812 {};
813
814 template<typename _tFrom, typename _tTo,
815 typename... _tFromParams, typename... _tToParams, class _tBase>
816 struct is_covariant<expanded_function<_tFrom(_tFromParams...), _tBase>,
817 expanded_function<_tTo(_tToParams...), _tBase>>
818 : is_covariant<_tFrom(_tFromParams...), _tTo(_tToParams...)>
819 {};
820
821 template<typename _tResFrom, typename _tResTo,
822 typename... _tFromParams, typename... _tToParams, class _tBase>
823 struct is_contravariant<expanded_function<_tResFrom(_tFromParams...), _tBase>,
824 expanded_function<_tResTo(_tToParams...), _tBase>>
825 : is_contravariant<_tResFrom(_tFromParams...), _tResTo(_tToParams...)>
826 {};
827
828 template<typename _tRet, typename _tUnused, typename... _tParams, class _tBase>
829 struct make_function_type<_tRet, expanded_function<_tUnused(_tParams...),
830 _tBase>>
831 : make_function_type<_tRet, empty_base<_tParams...>>
832 {};
833
834 template<typename _tRet, typename... _tParams, class _tBase, size_t... _vSeq>
835 struct call_projection<expanded_function<_tRet(_tParams...), _tBase>,
836 index_sequence<_vSeq...>>
837 : call_projection<_tRet(_tParams...), index_sequence<_vSeq...>>
838 {};
840
841
842
849 template<typename _type>
850 struct default_last_value
851 {
852 template<typename _tIn>
853 _type
854 operator()(_tIn first, _tIn last, const _type& val = {}) const
855 {
856 return std::accumulate(first, last, val,
857 [](const _type&, decltype(*first) v){
858 return yforward(v);
859 });
860 }
861 };
862
863 template<>
864 struct default_last_value<void>
865 {
866 template<typename _tIn>
867 void
868 operator()(_tIn first, _tIn last) const
869 {
870 for(; first != last; ++first)
871 *first;
872 }
873 };
875
876 } // namespace ystdex;
877
878 #endif
879
ystdex::expanded_function< _tRet(_tParams...), _tBase >::expanded_function
expanded_function(expanded_function &&)=default
ystdex::call_projection
调用投影：向原调用传递序列指定的位置的参数。
Definition: apply.hpp:70
ystdex::composed::f
_func f
Definition: functional.hpp:92
ystdex::cpp2017::is_invocable_r
Definition: invoke.hpp:369
ystdex::composed_n::operator()
auto operator()(_tParams &&... args) const -> decltype(f(g(std::forward< decltype(args)>(args))...))
Definition: functional.hpp:145
ystdex::expanded_function< _tRet(_tParams...), _tBase >::operator=
expanded_function & operator=(expanded_function &&)=default
ystdex::cond
conditional< _tCond::value, _tThen, _tElse > cond
条件判断。
Definition: meta.hpp:787
ystdex::expanded_function< _tRet(_tParams...), _tBase >::expanded_function
expanded_function(_fCallable f)
使用函数对象。
Definition: functional.hpp:695
ystdex::generalized_composed::f
_func f
Definition: functional.hpp:180
ystdex::one_shot::func
_func func
Definition: functional.hpp:249
YB_ATTR_nodiscard
#define YB_ATTR_nodiscard
标记返回值不被忽略的属性。
Definition: ydef.h:715
ystdex::cpp2017::is_nothrow_swappable
Definition: swap.hpp:77
ystdex::expanded_function< _tRet(_tParams...), _tBase >::expanded_function
expanded_function(std::allocator_arg_t, const _tAlloc &a, _tRet(*f)(_tParams...))
构造：使用分配器和函数指针。
Definition: functional.hpp:686
ystdex::one_shot< _func, void, void >::one_shot
one_shot(_func f)
Definition: functional.hpp:376
ystdex::expanded_function< _tRet(_tParams...), _tBase >::expanded_function
expanded_function(std::allocator_arg_t, const _tAlloc &a, expanded_function &&x)
Definition: functional.hpp:754
x
const EncapsulationBase & x
Definition: NPLA1Forms.cpp:1536
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:77
ystdex::details::invoke_for_value
_type invoke_for_value(true_, _type &&val, _fCallable &&f, _tParams &&... args)
Definition: functional.hpp:435
ystdex::make_parameter_list
取参数列表。
Definition: function.hpp:332
ystdex::is_contravariant
判断指定类型之间是否逆变。
Definition: function.hpp:179
ystdex::is_covariant
判断指定类型之间是否协变。
Definition: function.hpp:145
ystdex::one_shot< _func, _tRes, void >::operator()
auto operator()(_tParams &&... args) const -> decltype(func(std::forward< decltype(args)>(args)...) &&noexcept(func=
Definition: functional.hpp:355
ystdex::invoke
invoke_result_t< _fCallable, _tParams... > invoke(_fCallable &&f, _tParams &&... args)
调用可调用对象。
Definition: invoke.hpp:538
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:53
YB_PURE
#define YB_PURE
指示函数或函数模板实例为纯函数。
Definition: ydef.h:919
ystdex::update_thunk
void update_thunk(_tThunk &thunk, _func &&f)
更新间接调用对象。
Definition: functional.hpp:225
ystdex::invoke_nonvoid
nonvoid_result_t< invoke_result_t< _fCallable, _tParams... > > invoke_nonvoid(_fCallable &&f, _tParams &&... args)
调用可调用对象，保证返回值非空。
Definition: invoke.hpp:572
ystdex::one_shot< _func, _tRes, void >::one_shot
one_shot(_func f, _tRes r={})
Definition: functional.hpp:349
ystdex::expanded_caller::operator()
auto operator()(_tParams &&... args) const -> decltype(expand_proxy< _fHandler >::call(caller, std::forward< decltype(args)>(args)...))
Definition: functional.hpp:601
ystdex::retry_on_cond
invoke_result_t< _fCallable, _tParams... > retry_on_cond(_fCond cond, _fCallable &&f, _tParams &&... args)
循环重复调用：代替直接使用 do-while 语句以避免过多引入作用域外的变量。
Definition: functional.hpp:554
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::one_shot< _func, void, void >::func
_func func
Definition: functional.hpp:372
ystdex::expanded_function< _tRet(_tParams...), _tBase >::expanded_function
expanded_function(_fCallable f)
使用扩展函数对象。
Definition: functional.hpp:709
ystdex::cpp2014::index_sequence_for
make_index_sequence< sizeof...(_types)> index_sequence_for
Definition: integer_sequence.hpp:308
ystdex::one_shot< _func, void, _tState >::func
_func func
Definition: functional.hpp:298
ystdex::cpp2014::enable_if_t
typename enable_if< _bCond, _type >::type enable_if_t
Definition: meta.hpp:199
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::get_less
get 成员小于仿函数。
Definition: functional.hpp:418
ystdex::expand_proxy::apply_call
static auto apply_call(_tParams &&... args) -> decltype(expand_proxy< _fCallable, _vLen - 1 >::apply_call(std::forward< decltype(args)>(args)...))
Definition: functional.hpp:483
ystdex::expanded_function
扩展函数包装类模板。
Definition: functional.hpp:644
ystdex::expanded_caller::expanded_caller
expanded_caller(_func f)
Definition: functional.hpp:586
ystdex::expanded_function< _tRet(_tParams...), _tBase >::expanded_function
expanded_function(std::allocator_arg_t, const _tAlloc &a, _fCallable f)
使用分配器和扩展函数对象。
Definition: functional.hpp:715
ystdex::expanded_function< _tRet(_tParams...), _tBase >::operator=
expanded_function & operator=(nullptr_t)
Definition: functional.hpp:763
ystdex::invoke_for_value
auto invoke_for_value(_type &&val, _fCallable &&f, _tParams &&... args) -> common_nonvoid_t< invoke_result_t< _fCallable, _tParams... >, _type >
调用第二参数起指定的函数对象，若返回空类型则使用第一参数的值为返回值。
Definition: functional.hpp:458
swap.hpp
交换操作。
ynoexcept_spec
#define ynoexcept_spec(...)
表达式 noexcept 异常规范。
Definition: ydef.h:1181
ystdex::nullptr_t
空指针类。
Definition: ydef.h:1321
ystdex::expanded_function< _tRet(_tParams...), _tBase >::operator=
expanded_function & operator=(const expanded_function &)=default
ystdex::expanded_function< _tRet(_tParams...), _tBase >::expanded_function
expanded_function(_tRet(*f)(_tParams...))
构造：使用函数指针。
Definition: functional.hpp:674
ystdex::default_last_value< void >::operator()
void operator()(_tIn first, _tIn last) const
Definition: functional.hpp:868
ystdex::expanded_function< _tRet(_tParams...), _tBase >::base_type
_tBase base_type
Definition: functional.hpp:658
ystdex::object_result_t
cond_t< is_object< _type >, _type, pseudo_output > object_result_t
若类型不是对象类型则取后备结果类型（默认为 pseudo_output ）。
Definition: invoke.hpp:104
ystdex::common_nonvoid_t
cond_or_t< is_void< _type >, _type, common_type_t, _types... > common_nonvoid_t
取公共非空类型：若第一参数为非空类型则为第一参数，否则从其余参数推断。
Definition: type_op.hpp:274
ystdex::composed_n
多元分发的复合函数。
Definition: functional.hpp:138
ystdex::expand_proxy
Definition: functional.hpp:471
ystdex::one_shot< _func, void, _tState >::operator()
void operator()(_tParams &&... args) const
Definition: functional.hpp:327
CHRLib::f
f(d, s)
yconstfn_relaxed
#define yconstfn_relaxed
指定编译时没有 C++11 限制和隐式成员 const 的常量函数。
Definition: ydef.h:1097
NPL::A1::Internals::cur
_fCurrent && cur
Definition: NPLA1Internals.h:591
ystdex::swap_dependent
void swap_dependent(_type &x, _type &y)(is_nothrow_swappable< _type >())
支持基于 ystdex_swap::swap 的 ADL 的左值交换。
Definition: swap.hpp:371
ystdex::composed::operator()
auto operator()(_tParams &&... args) const -> decltype(f(g(std::forward< decltype(args)>(args)...)))
Definition: functional.hpp:101
YSLib::Drawing::g
The boundary is out of the const Graphics & g
Definition: YDraw.h:161
ystdex::composed_n::f
_func f
Definition: functional.hpp:139
ystdex::composed_n::g
_func2 g
Definition: functional.hpp:140
CHRLib::args
YB_ATTR_nodiscard _tParams && args
Definition: CharacterProcessing.h:649
ystdex::details::_type2
_type2
Definition: operators.hpp:241
ystdex::expanded_function< _tRet(_tParams...), _tBase >::expanded_function
expanded_function(std::allocator_arg_t, const _tAlloc &a, const expanded_function &x)
Definition: functional.hpp:749
ystdex::expanded_function< _tRet(_tParams...), _tBase >::enable_if_expandable_t
enable_if_t< !is_constructible< base_type, _fCallable >::value &&is_expandable< base_type, _fCallable >::value > enable_if_expandable_t
Definition: functional.hpp:665
ystdex::expanded_function< _tRet(_tParams...), _tBase >::expanded_function
expanded_function()
Definition: functional.hpp:670
function.hpp
函数基本操作和调用包装对象。
ystdex::one_shot::operator=
one_shot & operator=(one_shot &&f)
Definition: functional.hpp:273
ystdex::default_last_value::operator()
_type operator()(_tIn first, _tIn last, const _type &val={}) const
Definition: functional.hpp:854
ystdex::one_shot::one_shot
one_shot(_type &&f, _tRes r={}, _type2 &&s={})
Definition: functional.hpp:262
yforward
#define yforward(_expr)
根据参数类型使用 std::forward 转发对应参数。
Definition: ydef.h:1508
ystdex::expand_proxy::call
static auto call(_tParams &&... args) -> decltype(expand_proxy< _fCallable, _vLen - 1 >::call(std::forward< decltype(args)>(args)...))
Definition: functional.hpp:505
ystdex::one_shot< _func, _tRes, void >::func
_func func
Definition: functional.hpp:342
ystdex::generalized_composed::g
std::tuple< _funcs... > g
Definition: functional.hpp:181
ystdex::make_function_type
取指定返回类型和元组指定参数类型的函数类型。
Definition: function.hpp:388
std
Definition: optional.h:982
ystdex::generalized_composed::operator()
auto operator()(_tParams &&... args) const -> decltype(call(index_sequence_for< _tParams... >(), std::forward< decltype(args)>(args)...))
Definition: functional.hpp:185
ystdex::is_expandable
is_constructible< _func, expanded_caller< as_function_type_t< _func >, _fCallable > > is_expandable
判断可调用类型是可展开到指定函数对象的类型。
Definition: functional.hpp:629
ystdex::expanded_function< _tRet(_tParams...), _tBase >::expanded_function
expanded_function(const expanded_function &)=default
ystdex::thunk
包装惰性求值的过程。
Definition: thunk.hpp:110
ystdex::composed_n::compose_n
composed_n< _func, _func2 > compose_n(_func f, _func2 g)
单一分派的多元函数复合。
Definition: functional.hpp:162
ystdex::one_shot::fresh
_tState fresh
Definition: functional.hpp:257
ystdex::expanded_caller::expanded_caller
expanded_caller(expanded_caller &&)=default
ystdex::return_of
取返回类型。
Definition: function.hpp:345
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:195
YSLib::UI::y
SPos SPos y
Definition: YWidget.cpp:44
ystdex::cpp2017::invoke_result_t
_t< invoke_result< _fCallable, _tParams... > > invoke_result_t
Definition: invoke.hpp:393
ystdex::expanded_function< _tRet(_tParams...), _tBase >::swap
friend void swap(expanded_function &x, expanded_function &y)
Definition: functional.hpp:792
ystdex::true_
bool_< true > true_
Definition: integral_constant.hpp:109
ystdex::compose_n
auto compose_n(_func f, _func2 g, _func3 h, _funcs... args) -> decltype(ystdex::compose_n(ystdex::compose_n(f, g), h, args...))
Definition: functional.hpp:168
ystdex::one_shot
调用一次的函数包装模板。
Definition: functional.hpp:247
CHRLib::s
_tDst const _tSrc * s
Definition: CharacterProcessing.h:143
ystdex::one_shot< _func, void, void >::operator()
void operator()(_tParams &&... args) const
Definition: functional.hpp:382
ystdex::expanded_caller
接受冗余参数的可调用对象。
Definition: functional.hpp:574
ystdex::expanded_function< _tRet(_tParams...), _tBase >::operator=
expanded_function & operator=(std::reference_wrapper< _fCallable > f)
Definition: functional.hpp:778
ystdex::exclude_self_t
enable_if_t<!is_same_param< _tSelected, _tParam >::value, _type > exclude_self_t
排除选择类型的特定参数的重载。
Definition: meta.hpp:865
ystdex::expanded_caller::expanded_caller
expanded_caller()=default
ystdex::one_shot::one_shot
one_shot(one_shot &&f)
Definition: functional.hpp:265
ystdex::expanded_caller::operator=
expanded_caller & operator=(const expanded_caller &)=default
v
byte v
Definition: CharRenderer.cpp:76
ystdex
<memory> 特性测试宏。
Definition: ydef.h:1262
ystdex::expanded_caller::expanded_caller
expanded_caller(const expanded_caller &)=default
ystdex::expand_proxy::invoke
static auto invoke(_tParams &&... args) -> decltype(expand_proxy< _fCallable, _vLen - 1 >::invoke(std::forward< decltype(args)>(args)...))
Definition: functional.hpp:516
YSLib::_tParams
YB_ATTR_nodiscard YB_PURE typename _tParams
Definition: ValueNode.h:1294
ystdex::composed
复合函数。
Definition: functional.hpp:91
ystdex::one_shot::operator()
auto operator()(_tParams &&... args) const -> decltype(func(std::forward< decltype(args)>(args)...))
Definition: functional.hpp:281
ystdex::one_shot< _func, void, _tState >::one_shot
one_shot(_type &&f, _type2 &&s={})
Definition: functional.hpp:308
ystdex::expanded_function< _tRet(_tParams...), _tBase >::expanded_function
expanded_function(std::allocator_arg_t, const _tAlloc &a, _type &obj, _tRet(_type::*pm)(_tParams...))
Definition: functional.hpp:736
ystdex::expanded_caller::caller
_fCaller caller
Definition: functional.hpp:576
ystdex::cpp2014::integer_sequence
Definition: integer_sequence.hpp:53
ystdex::expanded_caller::make_expanded
expanded_caller< _fHandler, _fCallable > make_expanded(_fCallable f)
构造接受冗余参数的可调用对象。
Definition: functional.hpp:616
ystdex::one_shot::result
_tRes result
Definition: functional.hpp:256
ystdex::expanded_function< _tRet(_tParams...), _tBase >::operator=
expanded_function & operator=(_fCallable &&f)
Definition: functional.hpp:772
ystdex::generalized_composed
多元复合函数。
Definition: functional.hpp:179
ystdex::get_equal_to
get 成员等于仿函数。
Definition: functional.hpp:405
ystdex::default_last_value
合并值序列。
Definition: functional.hpp:851
ystdex::generalized_composed::generalized_compose
generalized_composed< _func, std::tuple< _funcs... > > generalized_compose(_func f, _funcs... args)
多元函数复合。
Definition: functional.hpp:210
yimpl
#define yimpl(...)
实现标签。
Definition: ydef.h:413
ystdex::compose
auto compose(_func f, _func2 g, _func3 h, _funcs... args) -> decltype(ystdex::compose(ystdex::compose(f, g), h, args...))
Definition: functional.hpp:124
platform::bool
YB_ATTR_nodiscard std::FILE *fp bool
Definition: FileIO.h:1271
ystdex::one_shot< _func, _tRes, void >::result
_tRes result
Definition: functional.hpp:347
ystdex::false_
bool_< false > false_
Definition: integral_constant.hpp:110
ystdex::expanded_function< _tRet(_tParams...), _tBase >::expanded_function
expanded_function(std::allocator_arg_t, const _tAlloc &a)
构造：使用分配器。
Definition: functional.hpp:680
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:1199
apply.hpp
元组应用操作。
functor.hpp
通用仿函数。
ystdex::expanded_function< _tRet(_tParams...), _tBase >::result_type
typename base_type::result_type result_type
Definition: functional.hpp:659
ystdex::expanded_caller::operator=
expanded_caller & operator=(expanded_caller &&)=default
ystdex::expanded_function< _tRet(_tParams...), _tBase >::expanded_function
expanded_function(std::allocator_arg_t, const _tAlloc &a, _fCallable &&f)
使用分配器和函数对象。
Definition: functional.hpp:703
ynoexcept
#define ynoexcept(...)
YSLib 无异常抛出保证：指定特定的异常规范。
Definition: ydef.h:1151
ystdex::one_shot< _func, void, _tState >::operator=
one_shot & operator=(one_shot &&f)
Definition: functional.hpp:319
ystdex::expand_proxy::apply_invoke
static auto apply_invoke(_tParams &&... args) -> decltype(expand_proxy< _fCallable, _vLen - 1 >::apply_invoke(std::forward< decltype(args)>(args)...))
Definition: functional.hpp:493
ystdex::one_shot< _func, void, _tState >::one_shot
one_shot(one_shot &&f)
Definition: functional.hpp:311
ystdex::expanded_function< _tRet(_tParams...), _tBase >::expanded_function
expanded_function(_type &obj, _tRet(_type::*pm)(_tParams...))
构造：使用对象引用和成员函数指针。
Definition: functional.hpp:727
yconstfn
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:1073
ystdex::composed::compose
composed< _func, _func2 > compose(_func f, _func2 g)
函数复合。
Definition: functional.hpp:117
YSLib::a
YB_PURE const _type * a
Definition: YCoreUtilities.h:168
ystdex::composed::g
_func2 g
Definition: functional.hpp:93