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_PERFECT_FORWARD_H
0011 #define _LIBCPP___CXX03___FUNCTIONAL_PERFECT_FORWARD_H
0012 
0013 #include <__cxx03/__config>
0014 #include <__cxx03/__type_traits/enable_if.h>
0015 #include <__cxx03/__type_traits/invoke.h>
0016 #include <__cxx03/__type_traits/is_constructible.h>
0017 #include <__cxx03/__utility/declval.h>
0018 #include <__cxx03/__utility/forward.h>
0019 #include <__cxx03/__utility/integer_sequence.h>
0020 #include <__cxx03/__utility/move.h>
0021 #include <__cxx03/tuple>
0022 
0023 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0024 #  pragma GCC system_header
0025 #endif
0026 
0027 _LIBCPP_PUSH_MACROS
0028 #include <__cxx03/__undef_macros>
0029 
0030 _LIBCPP_BEGIN_NAMESPACE_STD
0031 
0032 #if _LIBCPP_STD_VER >= 17
0033 
0034 template <class _Op, class _Indices, class... _BoundArgs>
0035 struct __perfect_forward_impl;
0036 
0037 template <class _Op, size_t... _Idx, class... _BoundArgs>
0038 struct __perfect_forward_impl<_Op, index_sequence<_Idx...>, _BoundArgs...> {
0039 private:
0040   tuple<_BoundArgs...> __bound_args_;
0041 
0042 public:
0043   template <class... _Args, class = enable_if_t< is_constructible_v<tuple<_BoundArgs...>, _Args&&...> >>
0044   _LIBCPP_HIDE_FROM_ABI explicit constexpr __perfect_forward_impl(_Args&&... __bound_args)
0045       : __bound_args_(std::forward<_Args>(__bound_args)...) {}
0046 
0047   _LIBCPP_HIDE_FROM_ABI __perfect_forward_impl(__perfect_forward_impl const&) = default;
0048   _LIBCPP_HIDE_FROM_ABI __perfect_forward_impl(__perfect_forward_impl&&)      = default;
0049 
0050   _LIBCPP_HIDE_FROM_ABI __perfect_forward_impl& operator=(__perfect_forward_impl const&) = default;
0051   _LIBCPP_HIDE_FROM_ABI __perfect_forward_impl& operator=(__perfect_forward_impl&&)      = default;
0052 
0053   template <class... _Args, class = enable_if_t<is_invocable_v<_Op, _BoundArgs&..., _Args...>>>
0054   _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Args&&... __args) & noexcept(
0055       noexcept(_Op()(std::get<_Idx>(__bound_args_)..., std::forward<_Args>(__args)...)))
0056       -> decltype(_Op()(std::get<_Idx>(__bound_args_)..., std::forward<_Args>(__args)...)) {
0057     return _Op()(std::get<_Idx>(__bound_args_)..., std::forward<_Args>(__args)...);
0058   }
0059 
0060   template <class... _Args, class = enable_if_t<!is_invocable_v<_Op, _BoundArgs&..., _Args...>>>
0061   auto operator()(_Args&&...) & = delete;
0062 
0063   template <class... _Args, class = enable_if_t<is_invocable_v<_Op, _BoundArgs const&..., _Args...>>>
0064   _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Args&&... __args) const& noexcept(
0065       noexcept(_Op()(std::get<_Idx>(__bound_args_)..., std::forward<_Args>(__args)...)))
0066       -> decltype(_Op()(std::get<_Idx>(__bound_args_)..., std::forward<_Args>(__args)...)) {
0067     return _Op()(std::get<_Idx>(__bound_args_)..., std::forward<_Args>(__args)...);
0068   }
0069 
0070   template <class... _Args, class = enable_if_t<!is_invocable_v<_Op, _BoundArgs const&..., _Args...>>>
0071   auto operator()(_Args&&...) const& = delete;
0072 
0073   template <class... _Args, class = enable_if_t<is_invocable_v<_Op, _BoundArgs..., _Args...>>>
0074   _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Args&&... __args) && noexcept(
0075       noexcept(_Op()(std::get<_Idx>(std::move(__bound_args_))..., std::forward<_Args>(__args)...)))
0076       -> decltype(_Op()(std::get<_Idx>(std::move(__bound_args_))..., std::forward<_Args>(__args)...)) {
0077     return _Op()(std::get<_Idx>(std::move(__bound_args_))..., std::forward<_Args>(__args)...);
0078   }
0079 
0080   template <class... _Args, class = enable_if_t<!is_invocable_v<_Op, _BoundArgs..., _Args...>>>
0081   auto operator()(_Args&&...) && = delete;
0082 
0083   template <class... _Args, class = enable_if_t<is_invocable_v<_Op, _BoundArgs const..., _Args...>>>
0084   _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Args&&... __args) const&& noexcept(
0085       noexcept(_Op()(std::get<_Idx>(std::move(__bound_args_))..., std::forward<_Args>(__args)...)))
0086       -> decltype(_Op()(std::get<_Idx>(std::move(__bound_args_))..., std::forward<_Args>(__args)...)) {
0087     return _Op()(std::get<_Idx>(std::move(__bound_args_))..., std::forward<_Args>(__args)...);
0088   }
0089 
0090   template <class... _Args, class = enable_if_t<!is_invocable_v<_Op, _BoundArgs const..., _Args...>>>
0091   auto operator()(_Args&&...) const&& = delete;
0092 };
0093 
0094 // __perfect_forward implements a perfect-forwarding call wrapper as explained in [func.require].
0095 template <class _Op, class... _Args>
0096 using __perfect_forward = __perfect_forward_impl<_Op, index_sequence_for<_Args...>, _Args...>;
0097 
0098 #endif // _LIBCPP_STD_VER >= 17
0099 
0100 _LIBCPP_END_NAMESPACE_STD
0101 
0102 _LIBCPP_POP_MACROS
0103 
0104 #endif // _LIBCPP___CXX03___FUNCTIONAL_PERFECT_FORWARD_H