Path: blob/main/contrib/llvm-project/libcxx/include/__functional/invoke.h
35260 views
// -*- C++ -*-1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//89#ifndef _LIBCPP___FUNCTIONAL_INVOKE_H10#define _LIBCPP___FUNCTIONAL_INVOKE_H1112#include <__config>13#include <__type_traits/invoke.h>14#include <__utility/forward.h>1516#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)17# pragma GCC system_header18#endif1920_LIBCPP_BEGIN_NAMESPACE_STD2122#if _LIBCPP_STD_VER >= 172324template <class _Fn, class... _Args>25_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 invoke_result_t<_Fn, _Args...>26invoke(_Fn&& __f, _Args&&... __args) noexcept(is_nothrow_invocable_v<_Fn, _Args...>) {27return std::__invoke(std::forward<_Fn>(__f), std::forward<_Args>(__args)...);28}2930#endif // _LIBCPP_STD_VER >= 173132#if _LIBCPP_STD_VER >= 2333template <class _Result, class _Fn, class... _Args>34requires is_invocable_r_v<_Result, _Fn, _Args...>35_LIBCPP_HIDE_FROM_ABI constexpr _Result36invoke_r(_Fn&& __f, _Args&&... __args) noexcept(is_nothrow_invocable_r_v<_Result, _Fn, _Args...>) {37if constexpr (is_void_v<_Result>) {38static_cast<void>(std::invoke(std::forward<_Fn>(__f), std::forward<_Args>(__args)...));39} else {40// TODO: Use reference_converts_from_temporary_v once implemented41// using _ImplicitInvokeResult = invoke_result_t<_Fn, _Args...>;42// static_assert(!reference_converts_from_temporary_v<_Result, _ImplicitInvokeResult>,43static_assert(true,44"Returning from invoke_r would bind a temporary object to the reference return type, "45"which would result in a dangling reference.");46return std::invoke(std::forward<_Fn>(__f), std::forward<_Args>(__args)...);47}48}49#endif5051_LIBCPP_END_NAMESPACE_STD5253#endif // _LIBCPP___FUNCTIONAL_INVOKE_H545556