30 #ifndef _GLIBCXX_INVOKE_H
31 #define _GLIBCXX_INVOKE_H 1
33 #pragma GCC system_header
35 #if __cplusplus < 201103L
41 namespace std _GLIBCXX_VISIBILITY(default)
43 _GLIBCXX_BEGIN_NAMESPACE_VERSION
52 template<typename _Tp, typename _Up = typename __inv_unwrap<_Tp>::type>
54 __invfwd(
typename remove_reference<_Tp>::type& __t) noexcept
55 {
return static_cast<_Up&&
>(__t); }
57 template<
typename _Res,
typename _Fn,
typename... _Args>
59 __invoke_impl(__invoke_other, _Fn&& __f, _Args&&... __args)
60 {
return std::forward<_Fn>(__f)(std::forward<_Args>(__args)...); }
62 template<
typename _Res,
typename _MemFun,
typename _Tp,
typename... _Args>
64 __invoke_impl(__invoke_memfun_ref, _MemFun&& __f, _Tp&& __t,
66 {
return (__invfwd<_Tp>(__t).*__f)(std::forward<_Args>(__args)...); }
68 template<
typename _Res,
typename _MemFun,
typename _Tp,
typename... _Args>
70 __invoke_impl(__invoke_memfun_deref, _MemFun&& __f, _Tp&& __t,
73 return ((*std::forward<_Tp>(__t)).*__f)(std::forward<_Args>(__args)...);
76 template<
typename _Res,
typename _MemPtr,
typename _Tp>
78 __invoke_impl(__invoke_memobj_ref, _MemPtr&& __f, _Tp&& __t)
79 {
return __invfwd<_Tp>(__t).*__f; }
81 template<
typename _Res,
typename _MemPtr,
typename _Tp>
83 __invoke_impl(__invoke_memobj_deref, _MemPtr&& __f, _Tp&& __t)
84 {
return (*std::forward<_Tp>(__t)).*__f; }
87 template<
typename _Callable,
typename... _Args>
88 constexpr
typename __invoke_result<_Callable, _Args...>::type
90 noexcept(__is_nothrow_invocable<_Callable, _Args...>::value)
92 using __result = __invoke_result<_Callable, _Args...>;
93 using __type =
typename __result::type;
94 using __tag =
typename __result::__invoke_type;
95 return std::__invoke_impl<__type>(__tag{}, std::forward<_Callable>(__fn),
96 std::forward<_Args>(__args)...);
99 #if __cplusplus >= 201703L
101 template<
typename _Res,
typename _Callable,
typename... _Args>
102 constexpr
enable_if_t<is_invocable_r_v<_Res, _Callable, _Args...>, _Res>
103 __invoke_r(_Callable&& __fn, _Args&&... __args)
104 noexcept(is_nothrow_invocable_r_v<_Res, _Callable, _Args...>)
106 using __result = __invoke_result<_Callable, _Args...>;
107 using __type =
typename __result::type;
108 using __tag =
typename __result::__invoke_type;
109 if constexpr (is_void_v<_Res>)
110 std::__invoke_impl<__type>(__tag{}, std::forward<_Callable>(__fn),
111 std::forward<_Args>(__args)...);
113 return std::__invoke_impl<__type>(__tag{},
114 std::forward<_Callable>(__fn),
115 std::forward<_Args>(__args)...);
118 template<
typename _Res,
typename _Callable,
typename... _Args>
119 using __can_invoke_as_void = __enable_if_t<
120 __and_<is_void<_Res>, __is_invocable<_Callable, _Args...>>::value,
124 template<
typename _Res,
typename _Callable,
typename... _Args>
125 using __can_invoke_as_nonvoid = __enable_if_t<
126 __and_<__not_<is_void<_Res>>,
127 is_convertible<
typename __invoke_result<_Callable, _Args...>::type,
134 template<
typename _Res,
typename _Callable,
typename... _Args>
135 constexpr __can_invoke_as_nonvoid<_Res, _Callable, _Args...>
136 __invoke_r(_Callable&& __fn, _Args&&... __args)
138 using __result = __invoke_result<_Callable, _Args...>;
139 using __type =
typename __result::type;
140 using __tag =
typename __result::__invoke_type;
141 return std::__invoke_impl<__type>(__tag{}, std::forward<_Callable>(__fn),
142 std::forward<_Args>(__args)...);
146 template<
typename _Res,
typename _Callable,
typename... _Args>
147 _GLIBCXX14_CONSTEXPR __can_invoke_as_void<_Res, _Callable, _Args...>
148 __invoke_r(_Callable&& __fn, _Args&&... __args)
150 using __result = __invoke_result<_Callable, _Args...>;
151 using __type =
typename __result::type;
152 using __tag =
typename __result::__invoke_type;
153 std::__invoke_impl<__type>(__tag{}, std::forward<_Callable>(__fn),
154 std::forward<_Args>(__args)...);
158 _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.