30#ifndef _GLIBCXX_MOF_CV
31# define _GLIBCXX_MOF_CV
34#ifdef _GLIBCXX_MOF_REF
35# define _GLIBCXX_MOF_INV_QUALS _GLIBCXX_MOF_CV _GLIBCXX_MOF_REF
37# define _GLIBCXX_MOF_REF
38# define _GLIBCXX_MOF_INV_QUALS _GLIBCXX_MOF_CV &
41#define _GLIBCXX_MOF_CV_REF _GLIBCXX_MOF_CV _GLIBCXX_MOF_REF
43namespace std _GLIBCXX_VISIBILITY(default)
45_GLIBCXX_BEGIN_NAMESPACE_VERSION
63 template<
typename _Res,
typename... _ArgTypes,
bool _Noex>
64 class move_only_function<_Res(_ArgTypes...) _GLIBCXX_MOF_CV
65 _GLIBCXX_MOF_REF noexcept(_Noex)>
68 template<
typename _Tp>
70 = __conditional_t<_Noex,
75 template<
typename _Vt>
76 static constexpr bool __is_callable_from
77 = __and_v<__callable<_Vt _GLIBCXX_MOF_CV_REF>,
78 __callable<_Vt _GLIBCXX_MOF_INV_QUALS>>;
81 using result_type = _Res;
91 : _Mofunc_base(
static_cast<_Mofunc_base&&
>(__x)),
92 _M_invoke(std::__exchange(__x._M_invoke,
nullptr))
96 template<
typename _Fn,
typename _Vt = decay_t<_Fn>>
97 requires (!is_same_v<_Vt, move_only_function>)
98 && (!__is_in_place_type_v<_Vt>) && __is_callable_from<_Vt>
101 if constexpr (is_function_v<remove_pointer_t<_Vt>>
102 || is_member_pointer_v<_Vt>
103 || __is_move_only_function_v<_Vt>)
108 _M_init<_Vt>(std::forward<_Fn>(__f));
109 _M_invoke = &_S_invoke<_Vt>;
113 template<
typename _Tp,
typename... _Args>
114 requires is_constructible_v<_Tp, _Args...>
115 && __is_callable_from<_Tp>
118 noexcept(_S_nothrow_init<_Tp, _Args...>())
119 : _M_invoke(&_S_invoke<_Tp>)
121 static_assert(is_same_v<decay_t<_Tp>, _Tp>);
122 _M_init<_Tp>(std::forward<_Args>(__args)...);
126 template<
typename _Tp,
typename _Up,
typename... _Args>
127 requires is_constructible_v<_Tp, initializer_list<_Up>&, _Args...>
128 && __is_callable_from<_Tp>
132 noexcept(_S_nothrow_init<_Tp, initializer_list<_Up>&, _Args...>())
133 : _M_invoke(&_S_invoke<_Tp>)
135 static_assert(is_same_v<decay_t<_Tp>, _Tp>);
136 _M_init<_Tp>(__il, std::forward<_Args>(__args)...);
143 _Mofunc_base::operator=(
static_cast<_Mofunc_base&&
>(__x));
144 _M_invoke = std::__exchange(__x._M_invoke,
nullptr);
152 _Mofunc_base::operator=(
nullptr);
158 template<
typename _Fn>
159 requires is_constructible_v<move_only_function, _Fn>
162 noexcept(is_nothrow_constructible_v<move_only_function, _Fn>)
164 move_only_function(std::forward<_Fn>(__f)).swap(*
this);
168 ~move_only_function() =
default;
171 explicit operator bool() const noexcept {
return _M_invoke !=
nullptr; }
182 operator()(_ArgTypes... __args) _GLIBCXX_MOF_CV_REF
noexcept(_Noex)
184 __glibcxx_assert(*
this !=
nullptr);
185 return _M_invoke(
this, std::forward<_ArgTypes>(__args)...);
190 swap(move_only_function& __x)
noexcept
192 _Mofunc_base::swap(__x);
198 swap(move_only_function& __x, move_only_function& __y)
noexcept
203 operator==(
const move_only_function& __x, nullptr_t)
noexcept
204 {
return __x._M_invoke ==
nullptr; }
207 template<
typename _Tp>
208 using __param_t = __conditional_t<is_scalar_v<_Tp>, _Tp, _Tp&&>;
210 using _Invoker = _Res (*)(_Mofunc_base _GLIBCXX_MOF_CV*,
211 __param_t<_ArgTypes>...)
noexcept(_Noex);
213 template<
typename _Tp>
215 _S_invoke(_Mofunc_base _GLIBCXX_MOF_CV* __self,
216 __param_t<_ArgTypes>... __args)
noexcept(_Noex)
218 using _TpCv = _Tp _GLIBCXX_MOF_CV;
219 using _TpInv = _Tp _GLIBCXX_MOF_INV_QUALS;
220 return std::__invoke_r<_Res>(
221 std::forward<_TpInv>(*_S_access<_TpCv>(__self)),
225 _Invoker _M_invoke =
nullptr;
228#undef _GLIBCXX_MOF_CV_REF
229#undef _GLIBCXX_MOF_CV
230#undef _GLIBCXX_MOF_REF
231#undef _GLIBCXX_MOF_INV_QUALS
233_GLIBCXX_END_NAMESPACE_VERSION
void swap(any &__x, any &__y) noexcept
Exchange the states of two any objects.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
ISO C++ entities toplevel namespace is std.
std::is_nothrow_invocable_r
move_only_function & operator=(nullptr_t) noexcept
Destroys the target object (if any).
_Res operator()(_ArgTypes... __args) _GLIBCXX_MOF_CV noexcept(_Noex)
move_only_function(_Fn &&__f) noexcept(_S_nothrow_init< _Vt, _Fn >())
Stores a target object initialized from the argument.
friend void swap(move_only_function &__x, move_only_function &__y) noexcept
Exchange the target objects (if any).
move_only_function & operator=(move_only_function &&__x) noexcept
Stores a new target object, leaving x empty.
move_only_function & operator=(_Fn &&__f) noexcept(is_nothrow_constructible_v< move_only_function, _Fn >)
Stores a new target object, initialized from the argument.
friend bool operator==(const move_only_function &__x, nullptr_t) noexcept
Check for emptiness by comparing with nullptr.
move_only_function() noexcept
Creates an empty object.
void swap(move_only_function &__x) noexcept
Exchange the target objects (if any).
move_only_function(in_place_type_t< _Tp >, initializer_list< _Up > __il, _Args &&... __args) noexcept(_S_nothrow_init< _Tp, initializer_list< _Up > &, _Args... >())
Stores a target object initialized from the arguments.
move_only_function(in_place_type_t< _Tp >, _Args &&... __args) noexcept(_S_nothrow_init< _Tp, _Args... >())
Stores a target object initialized from the arguments.
move_only_function(move_only_function &&__x) noexcept
Moves the target object, leaving the source empty.
move_only_function(nullptr_t) noexcept
Creates an empty object.