[lld][WebAssembly] Reinstate mistakenly disabled test. NFC
[llvm-project.git] / libcxx / include / __functional / perfect_forward.h
blob308b304a76dc09099d62f288f3a673ec1b140102
1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP___FUNCTIONAL_PERFECT_FORWARD_H
11 #define _LIBCPP___FUNCTIONAL_PERFECT_FORWARD_H
13 #include <__config>
14 #include <__utility/declval.h>
15 #include <__utility/forward.h>
16 #include <__utility/move.h>
17 #include <tuple>
18 #include <type_traits>
20 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
21 #pragma GCC system_header
22 #endif
24 _LIBCPP_BEGIN_NAMESPACE_STD
26 #if _LIBCPP_STD_VER > 14
28 template <class _Op, class _Indices, class ..._Bound>
29 struct __perfect_forward_impl;
31 template <class _Op, size_t ..._Idx, class ..._Bound>
32 struct __perfect_forward_impl<_Op, index_sequence<_Idx...>, _Bound...> {
33 private:
34 tuple<_Bound...> __bound_;
36 public:
37 template <class ..._BoundArgs, class = enable_if_t<
38 is_constructible_v<tuple<_Bound...>, _BoundArgs&&...>
40 explicit constexpr __perfect_forward_impl(_BoundArgs&& ...__bound)
41 : __bound_(_VSTD::forward<_BoundArgs>(__bound)...)
42 { }
44 __perfect_forward_impl(__perfect_forward_impl const&) = default;
45 __perfect_forward_impl(__perfect_forward_impl&&) = default;
47 __perfect_forward_impl& operator=(__perfect_forward_impl const&) = default;
48 __perfect_forward_impl& operator=(__perfect_forward_impl&&) = default;
50 template <class ..._Args, class = enable_if_t<is_invocable_v<_Op, _Bound&..., _Args...>>>
51 _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Args&&... __args) &
52 noexcept(noexcept(_Op()(_VSTD::get<_Idx>(__bound_)..., _VSTD::forward<_Args>(__args)...)))
53 -> decltype( _Op()(_VSTD::get<_Idx>(__bound_)..., _VSTD::forward<_Args>(__args)...))
54 { return _Op()(_VSTD::get<_Idx>(__bound_)..., _VSTD::forward<_Args>(__args)...); }
56 template <class ..._Args, class = enable_if_t<!is_invocable_v<_Op, _Bound&..., _Args...>>>
57 auto operator()(_Args&&...) & = delete;
59 template <class ..._Args, class = enable_if_t<is_invocable_v<_Op, _Bound const&..., _Args...>>>
60 _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Args&&... __args) const&
61 noexcept(noexcept(_Op()(_VSTD::get<_Idx>(__bound_)..., _VSTD::forward<_Args>(__args)...)))
62 -> decltype( _Op()(_VSTD::get<_Idx>(__bound_)..., _VSTD::forward<_Args>(__args)...))
63 { return _Op()(_VSTD::get<_Idx>(__bound_)..., _VSTD::forward<_Args>(__args)...); }
65 template <class ..._Args, class = enable_if_t<!is_invocable_v<_Op, _Bound const&..., _Args...>>>
66 auto operator()(_Args&&...) const& = delete;
68 template <class ..._Args, class = enable_if_t<is_invocable_v<_Op, _Bound..., _Args...>>>
69 _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Args&&... __args) &&
70 noexcept(noexcept(_Op()(_VSTD::get<_Idx>(_VSTD::move(__bound_))..., _VSTD::forward<_Args>(__args)...)))
71 -> decltype( _Op()(_VSTD::get<_Idx>(_VSTD::move(__bound_))..., _VSTD::forward<_Args>(__args)...))
72 { return _Op()(_VSTD::get<_Idx>(_VSTD::move(__bound_))..., _VSTD::forward<_Args>(__args)...); }
74 template <class ..._Args, class = enable_if_t<!is_invocable_v<_Op, _Bound..., _Args...>>>
75 auto operator()(_Args&&...) && = delete;
77 template <class ..._Args, class = enable_if_t<is_invocable_v<_Op, _Bound const..., _Args...>>>
78 _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Args&&... __args) const&&
79 noexcept(noexcept(_Op()(_VSTD::get<_Idx>(_VSTD::move(__bound_))..., _VSTD::forward<_Args>(__args)...)))
80 -> decltype( _Op()(_VSTD::get<_Idx>(_VSTD::move(__bound_))..., _VSTD::forward<_Args>(__args)...))
81 { return _Op()(_VSTD::get<_Idx>(_VSTD::move(__bound_))..., _VSTD::forward<_Args>(__args)...); }
83 template <class ..._Args, class = enable_if_t<!is_invocable_v<_Op, _Bound const..., _Args...>>>
84 auto operator()(_Args&&...) const&& = delete;
87 // __perfect_forward implements a perfect-forwarding call wrapper as explained in [func.require].
88 template <class _Op, class ..._Args>
89 using __perfect_forward = __perfect_forward_impl<_Op, index_sequence_for<_Args...>, _Args...>;
91 #endif // _LIBCPP_STD_VER > 14
93 _LIBCPP_END_NAMESPACE_STD
95 #endif // _LIBCPP___FUNCTIONAL_PERFECT_FORWARD_H