2929# pragma GCC system_header
3030#endif
3131
32+ // This file defines the following libc++-internal API (back-ported to C++03):
33+ //
34+ // template <class... Args>
35+ // decltype(auto) __invoke(Args&&... args) noexcept(noexcept(std::invoke(std::forward<Args>(args...)))) {
36+ // return std::invoke(std::forward<Args>(args)...);
37+ // }
38+ //
39+ // template <class Ret, class... Args>
40+ // Ret __invoke_r(Args&&... args) {
41+ // return std::invoke_r(std::forward<Args>(args)...);
42+ // }
43+ //
44+ // template <class Ret, class Func, class... Args>
45+ // inline const bool __is_invocable_r_v = is_invocable_r_v<Ret, Func, Args...>;
46+ //
47+ // template <class Func, class... Args>
48+ // struct __is_invocable : is_invocable<Func, Args...> {};
49+ //
50+ // template <class Func, class... Args>
51+ // inline const bool __is_invocable_v = is_invocable_v<Func, Args...>;
52+ //
53+ // template <class Func, class... Args>
54+ // inline const bool __is_nothrow_invocable_v = is_nothrow_invocable_v<Func, Args...>;
55+ //
56+ // template <class Func, class... Args>
57+ // struct __invoke_result : invoke_result {};
58+ //
59+ // template <class Func, class... Args>
60+ // using __invoke_result_t = invoke_result_t<Func, Args...>;
61+
3262_LIBCPP_BEGIN_NAMESPACE_STD
3363
3464template <class _DecayedFp >
@@ -167,7 +197,7 @@ struct __invokable_r {
167197 static const bool value = type::value;
168198};
169199template <class _Fp , class ... _Args>
170- using __invokable _LIBCPP_NODEBUG = __invokable_r<void , _Fp, _Args...>;
200+ using __is_invocable _LIBCPP_NODEBUG = __invokable_r<void , _Fp, _Args...>;
171201
172202template <bool _IsInvokable, bool _IsCVVoid, class _Ret , class _Fp , class ... _Args>
173203struct __nothrow_invokable_r_imp {
@@ -204,11 +234,7 @@ using __nothrow_invokable_r _LIBCPP_NODEBUG =
204234
205235template <class _Fp , class ... _Args>
206236using __nothrow_invokable _LIBCPP_NODEBUG =
207- __nothrow_invokable_r_imp<__invokable<_Fp, _Args...>::value, true , void , _Fp, _Args...>;
208-
209- template <class _Fp , class ... _Args>
210- struct __invoke_of
211- : public enable_if<__invokable<_Fp, _Args...>::value, typename __invokable_r<void , _Fp, _Args...>::_Result> {};
237+ __nothrow_invokable_r_imp<__is_invocable<_Fp, _Args...>::value, true , void , _Fp, _Args...>;
212238
213239template <class _Ret , bool = is_void<_Ret>::value>
214240struct __invoke_void_return_wrapper {
@@ -226,31 +252,51 @@ struct __invoke_void_return_wrapper<_Ret, true> {
226252 }
227253};
228254
255+ template <class _Func , class ... _Args>
256+ inline const bool __is_invocable_v = __is_invocable<_Func, _Args...>::value;
257+
258+ template <class _Ret , class _Func , class ... _Args>
259+ inline const bool __is_invocable_r_v = __invokable_r<_Ret, _Func, _Args...>::value;
260+
261+ template <class _Func , class ... _Args>
262+ inline const bool __is_nothrow_invocable_v = __nothrow_invokable<_Func, _Args...>::value;
263+
264+ template <class _Func , class ... _Args>
265+ struct __invoke_result
266+ : enable_if<__is_invocable_v<_Func, _Args...>, typename __invokable_r<void , _Func, _Args...>::_Result> {};
267+
268+ template <class _Func , class ... _Args>
269+ using __invoke_result_t = typename __invoke_result<_Func, _Args...>::type;
270+
271+ template <class _Ret , class ... _Args>
272+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Ret __invoke_r (_Args&&... __args) {
273+ return __invoke_void_return_wrapper<_Ret>::__call (std::forward<_Args>(__args)...);
274+ }
275+
229276#if _LIBCPP_STD_VER >= 17
230277
231278// is_invocable
232279
233280template <class _Fn , class ... _Args>
234- struct _LIBCPP_TEMPLATE_VIS is_invocable : integral_constant< bool , __invokable <_Fn, _Args...>::value > {};
281+ struct _LIBCPP_TEMPLATE_VIS is_invocable : bool_constant<__is_invocable_v <_Fn, _Args...>> {};
235282
236283template <class _Ret , class _Fn , class ... _Args>
237- struct _LIBCPP_TEMPLATE_VIS is_invocable_r : integral_constant< bool , __invokable_r <_Ret, _Fn, _Args...>::value > {};
284+ struct _LIBCPP_TEMPLATE_VIS is_invocable_r : bool_constant<__is_invocable_r_v <_Ret, _Fn, _Args...>> {};
238285
239286template <class _Fn , class ... _Args>
240- inline constexpr bool is_invocable_v = is_invocable <_Fn, _Args...>::value ;
287+ inline constexpr bool is_invocable_v = __is_invocable_v <_Fn, _Args...>;
241288
242289template <class _Ret , class _Fn , class ... _Args>
243- inline constexpr bool is_invocable_r_v = is_invocable_r <_Ret, _Fn, _Args...>::value ;
290+ inline constexpr bool is_invocable_r_v = __is_invocable_r_v <_Ret, _Fn, _Args...>;
244291
245292// is_nothrow_invocable
246293
247294template <class _Fn , class ... _Args>
248- struct _LIBCPP_TEMPLATE_VIS is_nothrow_invocable : integral_constant<bool , __nothrow_invokable<_Fn, _Args...>::value> {
249- };
295+ struct _LIBCPP_TEMPLATE_VIS is_nothrow_invocable : bool_constant<__nothrow_invokable<_Fn, _Args...>::value> {};
250296
251297template <class _Ret , class _Fn , class ... _Args>
252- struct _LIBCPP_TEMPLATE_VIS is_nothrow_invocable_r
253- : integral_constant< bool , __nothrow_invokable_r<_Ret, _Fn, _Args...>::value> { };
298+ struct _LIBCPP_TEMPLATE_VIS is_nothrow_invocable_r : bool_constant<__nothrow_invokable_r<_Ret, _Fn, _Args...>::value> {
299+ };
254300
255301template <class _Fn , class ... _Args>
256302inline constexpr bool is_nothrow_invocable_v = is_nothrow_invocable<_Fn, _Args...>::value;
@@ -259,7 +305,7 @@ template <class _Ret, class _Fn, class... _Args>
259305inline constexpr bool is_nothrow_invocable_r_v = is_nothrow_invocable_r<_Ret, _Fn, _Args...>::value;
260306
261307template <class _Fn , class ... _Args>
262- struct _LIBCPP_TEMPLATE_VIS invoke_result : __invoke_of <_Fn, _Args...> {};
308+ struct _LIBCPP_TEMPLATE_VIS invoke_result : __invoke_result <_Fn, _Args...> {};
263309
264310template <class _Fn , class ... _Args>
265311using invoke_result_t = typename invoke_result<_Fn, _Args...>::type;
0 commit comments