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 43 namespace std _GLIBCXX_VISIBILITY(default)
45 _GLIBCXX_BEGIN_NAMESPACE_VERSION
62 template<
typename _Res,
typename... _ArgTypes,
bool _Noex>
63 class move_only_function<_Res(_ArgTypes...) _GLIBCXX_MOF_CV
64 _GLIBCXX_MOF_REF noexcept(_Noex)>
65 : __polyfunc::_Mo_base
68 (std::__is_complete_or_unbounded(__type_identity<_ArgTypes>()) && ...),
69 "each parameter type must be a complete class");
71 using _Base = __polyfunc::_Mo_base;
72 using _Invoker = __polyfunc::_Invoker<_Noex, _Res, _ArgTypes...>;
73 using _Signature = _Invoker::_Signature;
75 template<
typename _Tp>
77 = __conditional_t<_Noex,
78 is_nothrow_invocable_r<_Res, _Tp, _ArgTypes...>,
79 is_invocable_r<_Res, _Tp, _ArgTypes...>>;
82 template<
typename _Vt>
83 static constexpr
bool __is_callable_from
84 = __and_v<__callable<_Vt _GLIBCXX_MOF_CV_REF>,
85 __callable<_Vt _GLIBCXX_MOF_INV_QUALS>>;
88 using result_type = _Res;
98 : _Base(static_cast<_Base&&>(__x)),
99 _M_invoke(std::__exchange(__x._M_invoke,
nullptr))
103 template<
typename _Fn,
typename _Vt = decay_t<_Fn>>
105 && (!__is_in_place_type_v<_Vt>) && __is_callable_from<_Vt>
106 move_only_function(_Fn&& __f) noexcept(_S_nothrow_init<_Vt, _Fn>())
112 || is_member_pointer_v<_Vt>
113 || __is_polymorphic_function_v<_Vt>)
119 if constexpr (__is_polymorphic_function_v<_Vt>
120 && __polyfunc::__is_invoker_convertible<_Vt, move_only_function>())
124 _Vt __tmp(std::forward<_Fn>(__f));
125 _M_move(__polyfunc::__base_of(__tmp));
126 _M_invoke = std::__exchange(__polyfunc::__invoker_of(__tmp),
nullptr);
130 _M_init<_Vt>(std::forward<_Fn>(__f));
131 _M_invoke = _Invoker::template _S_storage<_Vt _GLIBCXX_MOF_INV_QUALS>();
136 template<
typename _Tp,
typename... _Args>
137 requires is_constructible_v<_Tp, _Args...>
138 && __is_callable_from<_Tp>
140 move_only_function(in_place_type_t<_Tp>, _Args&&... __args)
141 noexcept(_S_nothrow_init<_Tp, _Args...>())
142 : _M_invoke(_Invoker::template _S_storage<_Tp _GLIBCXX_MOF_INV_QUALS>())
145 _M_init<_Tp>(std::forward<_Args>(__args)...);
149 template<
typename _Tp,
typename _Up,
typename... _Args>
150 requires is_constructible_v<_Tp, initializer_list<_Up>&, _Args...>
151 && __is_callable_from<_Tp>
156 : _M_invoke(_Invoker::template _S_storage<_Tp _GLIBCXX_MOF_INV_QUALS>())
159 _M_init<_Tp>(__il, std::forward<_Args>(__args)...);
164 operator=(move_only_function&& __x) noexcept
170 _Base::operator=(static_cast<_Base&&>(__x));
171 _M_invoke = std::__exchange(__x._M_invoke,
nullptr);
178 operator=(nullptr_t) noexcept
186 template<
typename _Fn>
187 requires is_constructible_v<move_only_function, _Fn>
190 noexcept(is_nothrow_constructible_v<move_only_function, _Fn>)
192 move_only_function(std::forward<_Fn>(__f)).swap(*
this);
196 ~move_only_function() =
default;
199 explicit operator bool() const noexcept
200 {
return _M_invoke !=
nullptr; }
211 operator()(_ArgTypes... __args) _GLIBCXX_MOF_CV_REF noexcept(_Noex)
213 __glibcxx_assert(*
this !=
nullptr);
214 return _M_invoke(this->_M_storage, std::forward<_ArgTypes>(__args)...);
219 swap(move_only_function& __x) noexcept
222 std::swap(_M_invoke, __x._M_invoke);
227 swap(move_only_function& __x, move_only_function& __y) noexcept
232 operator==(
const move_only_function& __x, nullptr_t) noexcept
233 {
return __x._M_invoke ==
nullptr; }
236 typename _Invoker::__storage_func_t _M_invoke =
nullptr;
238 template<
typename _Func>
240 __polyfunc::__invoker_of(_Func&) noexcept;
242 template<
typename _Func>
244 __polyfunc::__base_of(_Func&) noexcept;
246 template<
typename _Dst,
typename _Src>
247 friend consteval
bool 248 __polyfunc::__is_invoker_convertible() noexcept;
251 #undef _GLIBCXX_MOF_CV_REF 252 #undef _GLIBCXX_MOF_CV 253 #undef _GLIBCXX_MOF_REF 254 #undef _GLIBCXX_MOF_INV_QUALS 256 _GLIBCXX_END_NAMESPACE_VERSION
typename decay< _Tp >::type decay_t
Alias template for decay.
ISO C++ entities toplevel namespace is std.
move_only_function(move_only_function &&__x) noexcept
Moves the target object, leaving the source empty.
move_only_function() noexcept
Creates an empty object.
typename remove_pointer< _Tp >::type remove_pointer_t
Alias template for remove_pointer.
requires(!is_same_v< _Vt, move_only_function >) &&(!__is_in_place_type_v< _Vt >) &&__is_callable_from< _Vt > move_only_function(_Fn &&__f) noexcept(_S_nothrow_init< _Vt, _Fn >())
Stores a target object initialized from the argument.
constexpr _Tp * addressof(_Tp &__r) noexcept
Returns the actual address of the object or function referenced by r, even in the presence of an over...
move_only_function(nullptr_t) noexcept
Creates an empty object.