File indexing completed on 2026-05-03 08:13:51
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef _LIBCPP___FUNCTIONAL_INVOKE_H
0011 #define _LIBCPP___FUNCTIONAL_INVOKE_H
0012
0013 #include <__config>
0014 #include <__type_traits/invoke.h>
0015 #include <__type_traits/is_void.h>
0016 #include <__utility/forward.h>
0017
0018 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0019 # pragma GCC system_header
0020 #endif
0021
0022 _LIBCPP_BEGIN_NAMESPACE_STD
0023
0024 #if _LIBCPP_STD_VER >= 17
0025
0026 template <class _Fn, class... _Args>
0027 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 invoke_result_t<_Fn, _Args...>
0028 invoke(_Fn&& __f, _Args&&... __args) noexcept(is_nothrow_invocable_v<_Fn, _Args...>) {
0029 return std::__invoke(std::forward<_Fn>(__f), std::forward<_Args>(__args)...);
0030 }
0031
0032 #endif
0033
0034 #if _LIBCPP_STD_VER >= 23
0035 template <class _Result, class _Fn, class... _Args>
0036 requires is_invocable_r_v<_Result, _Fn, _Args...>
0037 _LIBCPP_HIDE_FROM_ABI constexpr _Result
0038 invoke_r(_Fn&& __f, _Args&&... __args) noexcept(is_nothrow_invocable_r_v<_Result, _Fn, _Args...>) {
0039 if constexpr (is_void_v<_Result>) {
0040 static_cast<void>(std::invoke(std::forward<_Fn>(__f), std::forward<_Args>(__args)...));
0041 } else {
0042
0043
0044
0045 static_assert(true,
0046 "Returning from invoke_r would bind a temporary object to the reference return type, "
0047 "which would result in a dangling reference.");
0048 return std::invoke(std::forward<_Fn>(__f), std::forward<_Args>(__args)...);
0049 }
0050 }
0051 #endif
0052
0053 _LIBCPP_END_NAMESPACE_STD
0054
0055 #endif