30 #ifndef _GLIBCXX_INVOKE_H
31 #define _GLIBCXX_INVOKE_H 1
33 #pragma GCC system_header
35 #if __cplusplus < 201103L
42 namespace std _GLIBCXX_VISIBILITY(default)
44 _GLIBCXX_BEGIN_NAMESPACE_VERSION
53 template<typename _Tp, typename _Up = typename __inv_unwrap<_Tp>::type>
55 __invfwd(
typename remove_reference<_Tp>::type& __t) noexcept
56 {
return static_cast<_Up&&
>(__t); }
58 template<
typename _Res,
typename _Fn,
typename... _Args>
60 __invoke_impl(__invoke_other, _Fn&& __f, _Args&&... __args)
61 {
return std::forward<_Fn>(__f)(std::forward<_Args>(__args)...); }
63 template<
typename _Res,
typename _MemFun,
typename _Tp,
typename... _Args>
65 __invoke_impl(__invoke_memfun_ref, _MemFun&& __f, _Tp&& __t,
67 {
return (__invfwd<_Tp>(__t).*__f)(std::forward<_Args>(__args)...); }
69 template<
typename _Res,
typename _MemFun,
typename _Tp,
typename... _Args>
71 __invoke_impl(__invoke_memfun_deref, _MemFun&& __f, _Tp&& __t,
74 return ((*std::forward<_Tp>(__t)).*__f)(std::forward<_Args>(__args)...);
77 template<
typename _Res,
typename _MemPtr,
typename _Tp>
79 __invoke_impl(__invoke_memobj_ref, _MemPtr&& __f, _Tp&& __t)
80 {
return __invfwd<_Tp>(__t).*__f; }
82 template<
typename _Res,
typename _MemPtr,
typename _Tp>
84 __invoke_impl(__invoke_memobj_deref, _MemPtr&& __f, _Tp&& __t)
85 {
return (*std::forward<_Tp>(__t)).*__f; }
88 template<
typename _Callable,
typename... _Args>
89 constexpr
typename __invoke_result<_Callable, _Args...>::type
91 noexcept(__is_nothrow_invocable<_Callable, _Args...>::value)
93 using __result = __invoke_result<_Callable, _Args...>;
94 using __type =
typename __result::type;
95 using __tag =
typename __result::__invoke_type;
96 return std::__invoke_impl<__type>(__tag{}, std::forward<_Callable>(__fn),
97 std::forward<_Args>(__args)...);
100 #if __cplusplus >= 201703L
102 template<
typename _Res,
typename _Callable,
typename... _Args>
103 constexpr
enable_if_t<is_invocable_r_v<_Res, _Callable, _Args...>, _Res>
104 __invoke_r(_Callable&& __fn, _Args&&... __args)
105 noexcept(is_nothrow_invocable_r_v<_Res, _Callable, _Args...>)
107 using __result = __invoke_result<_Callable, _Args...>;
108 using __type =
typename __result::type;
109 using __tag =
typename __result::__invoke_type;
110 if constexpr (is_void_v<_Res>)
111 std::__invoke_impl<__type>(__tag{}, std::forward<_Callable>(__fn),
112 std::forward<_Args>(__args)...);
114 return std::__invoke_impl<__type>(__tag{},
115 std::forward<_Callable>(__fn),
116 std::forward<_Args>(__args)...);
119 template<
typename _Res,
typename _Callable,
typename... _Args>
120 using __can_invoke_as_void = __enable_if_t<
121 __and_<is_void<_Res>, __is_invocable<_Callable, _Args...>>::value,
125 template<
typename _Res,
typename _Callable,
typename... _Args>
126 using __can_invoke_as_nonvoid = __enable_if_t<
127 __and_<__not_<is_void<_Res>>,
128 is_convertible<
typename __invoke_result<_Callable, _Args...>::type,
135 template<
typename _Res,
typename _Callable,
typename... _Args>
136 constexpr __can_invoke_as_nonvoid<_Res, _Callable, _Args...>
137 __invoke_r(_Callable&& __fn, _Args&&... __args)
139 using __result = __invoke_result<_Callable, _Args...>;
140 using __type =
typename __result::type;
141 using __tag =
typename __result::__invoke_type;
142 return std::__invoke_impl<__type>(__tag{}, std::forward<_Callable>(__fn),
143 std::forward<_Args>(__args)...);
147 template<
typename _Res,
typename _Callable,
typename... _Args>
148 _GLIBCXX14_CONSTEXPR __can_invoke_as_void<_Res, _Callable, _Args...>
149 __invoke_r(_Callable&& __fn, _Args&&... __args)
151 using __result = __invoke_result<_Callable, _Args...>;
152 using __type =
typename __result::type;
153 using __tag =
typename __result::__invoke_type;
154 std::__invoke_impl<__type>(__tag{}, std::forward<_Callable>(__fn),
155 std::forward<_Args>(__args)...);
159 _GLIBCXX_END_NAMESPACE_VERSION
typename enable_if< _Cond, _Tp >::type enable_if_t
Alias template for enable_if.
constexpr __invoke_result< _Callable, _Args... >::type __invoke(_Callable &&__fn, _Args &&... __args) noexcept(__is_nothrow_invocable< _Callable, _Args... >::value)
Invoke a callable object.
ISO C++ entities toplevel namespace is std.