Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:31

0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
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 // _LIBCPP_STD_VER >= 17
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     // TODO: Use reference_converts_from_temporary_v once implemented
0042     // using _ImplicitInvokeResult = invoke_result_t<_Fn, _Args...>;
0043     // static_assert(!reference_converts_from_temporary_v<_Result, _ImplicitInvokeResult>,
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 // _LIBCPP___CXX03___FUNCTIONAL_INVOKE_H