Back to home page

EIC code displayed by LXR

 
 

    


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

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___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 // _LIBCPP_STD_VER >= 17
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     // TODO: Use reference_converts_from_temporary_v once implemented
0043     // using _ImplicitInvokeResult = invoke_result_t<_Fn, _Args...>;
0044     // static_assert(!reference_converts_from_temporary_v<_Result, _ImplicitInvokeResult>,
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 // _LIBCPP___FUNCTIONAL_INVOKE_H