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
62 template<
typename _Res,
typename... _ArgTypes,
bool _Noex>
63 class copyable_function<_Res(_ArgTypes...) _GLIBCXX_MOF_CV
64 _GLIBCXX_MOF_REF noexcept(_Noex)>
65 : __polyfunc::_Cpy_base
68 (std::__is_complete_or_unbounded(__type_identity<_ArgTypes>()) && ...),
69 "each parameter type must be a complete class");
71 using _Base = __polyfunc::_Cpy_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))
104 : _Base(static_cast<const _Base&>(__x)),
105 _M_invoke(__x._M_invoke)
109 template<
typename _Fn,
typename _Vt = decay_t<_Fn>>
110 requires (!is_same_v<_Vt, copyable_function>)
111 && (!__is_in_place_type_v<_Vt>) && __is_callable_from<_Vt>
114 static_assert(is_copy_constructible_v<_Vt>);
115 if constexpr (is_function_v<remove_pointer_t<_Vt>>
116 || is_member_pointer_v<_Vt>
117 || __is_polymorphic_function_v<_Vt>)
123 if constexpr (!__is_polymorphic_function_v<_Vt>
124 || !__polyfunc::__is_invoker_convertible<_Vt, copyable_function>())
126 _M_init<_Vt>(std::forward<_Fn>(__f));
127 _M_invoke = _Invoker::template _S_storage<_Vt _GLIBCXX_MOF_INV_QUALS>();
129 else if constexpr (is_lvalue_reference_v<_Fn>)
131 _M_copy(__polyfunc::__base_of(__f));
132 _M_invoke = __polyfunc::__invoker_of(__f);
136 _M_move(__polyfunc::__base_of(__f));
137 _M_invoke = std::__exchange(__polyfunc::__invoker_of(__f),
nullptr);
142 template<
typename _Tp,
typename... _Args>
143 requires is_constructible_v<_Tp, _Args...>
144 && __is_callable_from<_Tp>
147 noexcept(_S_nothrow_init<_Tp, _Args...>())
148 : _M_invoke(_Invoker::template _S_storage<_Tp _GLIBCXX_MOF_INV_QUALS>())
150 static_assert(is_same_v<decay_t<_Tp>, _Tp>);
151 static_assert(is_copy_constructible_v<_Tp>);
152 _M_init<_Tp>(std::forward<_Args>(__args)...);
156 template<
typename _Tp,
typename _Up,
typename... _Args>
157 requires is_constructible_v<_Tp, initializer_list<_Up>&, _Args...>
158 && __is_callable_from<_Tp>
162 noexcept(_S_nothrow_init<_Tp, initializer_list<_Up>&, _Args...>())
163 : _M_invoke(_Invoker::template _S_storage<_Tp _GLIBCXX_MOF_INV_QUALS>())
165 static_assert(is_same_v<decay_t<_Tp>, _Tp>);
166 static_assert(is_copy_constructible_v<_Tp>);
167 _M_init<_Tp>(__il, std::forward<_Args>(__args)...);
178 _Base::operator=(
static_cast<_Base&&
>(__x));
179 _M_invoke = std::__exchange(__x._M_invoke,
nullptr);
188 copyable_function(__x).swap(*
this);
202 template<
typename _Fn>
203 requires is_constructible_v<copyable_function, _Fn>
206 noexcept(is_nothrow_constructible_v<copyable_function, _Fn>)
208 copyable_function(std::forward<_Fn>(__f)).swap(*
this);
212 ~copyable_function() =
default;
215 explicit operator bool() const noexcept
216 {
return _M_invoke !=
nullptr; }
227 operator()(_ArgTypes... __args) _GLIBCXX_MOF_CV_REF
noexcept(_Noex)
229 __glibcxx_assert(*
this !=
nullptr);
230 return _M_invoke(this->_M_storage, std::forward<_ArgTypes>(__args)...);
235 swap(copyable_function& __x)
noexcept
238 std::swap(_M_invoke, __x._M_invoke);
243 swap(copyable_function& __x, copyable_function& __y)
noexcept
249 {
return __x._M_invoke ==
nullptr; }
252 typename _Invoker::__storage_func_t _M_invoke =
nullptr;
254 template<
typename _Func>
256 __polyfunc::__invoker_of(_Func&)
noexcept;
258 template<
typename _Func>
260 __polyfunc::__base_of(_Func&)
noexcept;
262 template<
typename _Dst,
typename _Src>
263 friend consteval bool
264 __polyfunc::__is_invoker_convertible() noexcept;
267#undef _GLIBCXX_MOF_CV_REF
268#undef _GLIBCXX_MOF_CV
269#undef _GLIBCXX_MOF_REF
270#undef _GLIBCXX_MOF_INV_QUALS
272_GLIBCXX_END_NAMESPACE_VERSION
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...
ISO C++ entities toplevel namespace is std.
copyable_function(nullptr_t) noexcept
Creates an empty object.
copyable_function(in_place_type_t< _Tp >, _Args &&... __args) noexcept(_S_nothrow_init< _Tp, _Args... >())
Stores a target object initialized from the arguments.
copyable_function(copyable_function &&__x) noexcept
Moves the target object, leaving the source empty.
copyable_function & operator=(nullptr_t) noexcept
Destroys the target object (if any).
_Res operator()(_ArgTypes... __args) _GLIBCXX_MOF_CV noexcept(_Noex)
friend bool operator==(const copyable_function &__x, nullptr_t) noexcept
Check for emptiness by comparing with nullptr.
void swap(copyable_function &__x) noexcept
Exchange the target objects (if any).
copyable_function(copyable_function const &__x)
Copies the target object.
copyable_function() noexcept
Creates an empty object.
friend void swap(copyable_function &__x, copyable_function &__y) noexcept
Exchange the target objects (if any).
copyable_function & operator=(const copyable_function &__x)
Stores a copy of the source target object.
copyable_function & operator=(_Fn &&__f) noexcept(is_nothrow_constructible_v< copyable_function, _Fn >)
Stores a new target object, initialized from the argument.
copyable_function(_Fn &&__f) noexcept(_S_nothrow_init< _Vt, _Fn >())
Stores a target object initialized from the argument.
copyable_function & operator=(copyable_function &&__x) noexcept
Stores a new target object, leaving x empty.
copyable_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.