Back to home page

EIC code displayed by LXR

 
 

    


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

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