31#ifndef _GLIBCXX_BINDERS_H
32#define _GLIBCXX_BINDERS_H 1
35#pragma GCC system_header
38#if __cplusplus >= 202002L
43namespace std _GLIBCXX_VISIBILITY(default)
45_GLIBCXX_BEGIN_NAMESPACE_VERSION
47 template<
size_t,
typename _Tp>
48 struct _Indexed_bound_arg
50 [[no_unique_address]] _Tp _M_val;
53 template<
typename... _IndexedArgs>
54 struct _Bound_arg_storage : _IndexedArgs...
56 template<
bool _Back,
typename _Fd,
typename _Self,
typename... _CallArgs>
59 _S_apply(_Fd&& __fd, _Self&& __self, _CallArgs&&... __call_args)
64 __like_t<_Self, _IndexedArgs>(__self)._M_val...);
67 __like_t<_Self, _IndexedArgs>(__self)._M_val...,
72 template<
typename... _BoundArgs,
typename... _Args>
74 __make_bound_args(_Args&&... __args)
76 if constexpr (
sizeof...(_BoundArgs) == 1)
83 return _Bound_arg_storage<_Indexed_bound_arg<_Inds, _BoundArgs>...>
90 template<
bool _Back,
typename _Fd,
typename... _BoundArgs>
93 template<
typename _Self,
typename... _CallArgs>
94 using _Result_t = __conditional_t<
96 invoke_result<__like_t<_Self, _Fd>,
97 _CallArgs..., __like_t<_Self, _BoundArgs>...>,
98 invoke_result<__like_t<_Self, _Fd>,
99 __like_t<_Self, _BoundArgs>..., _CallArgs...>>::type;
101 template<
typename _Self,
typename... _CallArgs>
102 static consteval bool
103 _S_noexcept_invocable()
106 return is_nothrow_invocable_v< __like_t<_Self, _Fd>,
107 _CallArgs..., __like_t<_Self, _BoundArgs>...>;
109 return is_nothrow_invocable_v<__like_t<_Self, _Fd>,
110 __like_t<_Self, _BoundArgs>..., _CallArgs...>;
114 static_assert(is_move_constructible_v<_Fd>);
115 static_assert((is_move_constructible_v<_BoundArgs> && ...));
119 template<
typename _Fn,
typename... _Args>
121 _Binder(
int, _Fn&& __fn, _Args&&... __args)
122 noexcept(__and_<is_nothrow_constructible<_Fd, _Fn>,
123 is_nothrow_constructible<_BoundArgs, _Args>...>::value)
124 : _M_fd(std::
forward<_Fn>(__fn)),
125 _M_bound_args(__make_bound_args<_BoundArgs...>(std::
forward<_Args>(__args)...))
126 {
static_assert(
sizeof...(_Args) ==
sizeof...(_BoundArgs)); }
128#if __cpp_explicit_this_parameter
129 template<
typename _Self,
typename... _CallArgs>
130 constexpr _Result_t<_Self, _CallArgs...>
131 operator()(
this _Self&& __self, _CallArgs&&... __call_args)
132 noexcept(_S_noexcept_invocable<_Self, _CallArgs...>())
134 return _S_call(__like_t<_Self, _Binder>(__self),
138 template<
typename... _CallArgs>
140 constexpr _Result_t<_Binder&, _CallArgs...>
141 operator()(_CallArgs&&... __call_args) &
142 noexcept(_S_noexcept_invocable<_Binder&, _CallArgs...>())
147 template<
typename... _CallArgs>
149 constexpr _Result_t<
const _Binder&, _CallArgs...>
150 operator()(_CallArgs&&... __call_args)
const &
151 noexcept(_S_noexcept_invocable<
const _Binder&, _CallArgs...>())
156 template<
typename... _CallArgs>
158 constexpr _Result_t<_Binder&&, _CallArgs...>
159 operator()(_CallArgs&&... __call_args) &&
160 noexcept(_S_noexcept_invocable<_Binder&&, _CallArgs...>())
166 template<
typename... _CallArgs>
168 constexpr _Result_t<
const _Binder&&, _CallArgs...>
169 operator()(_CallArgs&&... __call_args)
const &&
170 noexcept(_S_noexcept_invocable<
const _Binder&&, _CallArgs...>())
176 template<
typename... _CallArgs>
177 void operator()(_CallArgs&&...) & =
delete;
179 template<
typename... _CallArgs>
180 void operator()(_CallArgs&&...) const & = delete;
182 template<typename... _CallArgs>
183 void operator()(_CallArgs&&...) && = delete;
185 template<typename... _CallArgs>
186 void operator()(_CallArgs&&...) const && = delete;
189 template<
typename _Tp,
typename... _CallArgs>
192 _S_call(_Tp&& __g, _CallArgs&&... __call_args)
194 if constexpr (
sizeof...(_BoundArgs) > 1)
195 return _BoundArgsStorage::template _S_apply<_Back>(
199 else if constexpr (
sizeof...(_BoundArgs) == 0)
202 else if constexpr (_Back)
213 using _BoundArgsStorage
217 [[no_unique_address]] _Fd _M_fd;
218 [[no_unique_address]] _BoundArgsStorage _M_bound_args;
221 template<
typename _Fn,
typename... _Args>
222 using _Bind_front_t = _Binder<false, decay_t<_Fn>,
decay_t<_Args>...>;
226 template<
typename _Fn,
typename... _Args>
230_GLIBCXX_END_NAMESPACE_VERSION
typename decay< _Tp >::type decay_t
Alias template for decay.
auto declval() noexcept -> decltype(__declval< _Tp >(0))
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr __invoke_result< _Callable, _Args... >::type __invoke(_Callable &&__fn, _Args &&... __args) noexcept(__is_nothrow_invocable< _Callable, _Args... >::value)
Invoke a callable object.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
ISO C++ entities toplevel namespace is std.
integer_sequence< size_t, _Idx... > index_sequence
Alias template index_sequence.
make_index_sequence< sizeof...(_Types)> index_sequence_for
Alias template index_sequence_for.