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