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...>;
74 template<
typename _Tp>
76 = __conditional_t<_Noex,
77 is_nothrow_invocable_r<_Res, _Tp, _ArgTypes...>,
78 is_invocable_r<_Res, _Tp, _ArgTypes...>>;
81 template<
typename _Vt>
82 static constexpr bool __is_callable_from
83 = __and_v<__callable<_Vt _GLIBCXX_MOF_CV_REF>,
84 __callable<_Vt _GLIBCXX_MOF_INV_QUALS>>;
87 using result_type = _Res;
97 : _Base(
static_cast<_Base&&
>(__x)),
98 _M_invoke(std::__exchange(__x._M_invoke,
nullptr))
103 : _Base(static_cast<const _Base&>(__x)),
104 _M_invoke(__x._M_invoke)
108 template<
typename _Fn,
typename _Vt = decay_t<_Fn>>
109 requires (!is_same_v<_Vt, copyable_function>)
110 && (!__is_in_place_type_v<_Vt>) && __is_callable_from<_Vt>
113 static_assert(is_copy_constructible_v<_Vt>);
114 if constexpr (is_function_v<remove_pointer_t<_Vt>>
115 || is_member_pointer_v<_Vt>
116 || __is_polymorphic_function_v<_Vt>)
122 if constexpr (!__is_polymorphic_function_v<_Vt>
123 || !__polyfunc::__is_invoker_convertible<_Vt, copyable_function>())
126 _M_invoke = _Invoker::template _S_storage<_Vt _GLIBCXX_MOF_INV_QUALS>();
128 else if constexpr (is_lvalue_reference_v<_Fn>)
130 _M_copy(__polyfunc::__base_of(__f));
131 _M_invoke = __polyfunc::__invoker_of(__f);
135 _M_move(__polyfunc::__base_of(__f));
136 _M_invoke = std::__exchange(__polyfunc::__invoker_of(__f),
nullptr);
141 template<
typename _Tp,
typename... _Args>
142 requires is_constructible_v<_Tp, _Args...>
143 && __is_callable_from<_Tp>
146 noexcept(_S_nothrow_init<_Tp, _Args...>())
147 : _M_invoke(_Invoker::template _S_storage<_Tp _GLIBCXX_MOF_INV_QUALS>())
149 static_assert(is_same_v<decay_t<_Tp>, _Tp>);
150 static_assert(is_copy_constructible_v<_Tp>);
155 template<
typename _Tp,
typename _Up,
typename... _Args>
156 requires is_constructible_v<_Tp, initializer_list<_Up>&, _Args...>
157 && __is_callable_from<_Tp>
161 noexcept(_S_nothrow_init<_Tp, initializer_list<_Up>&, _Args...>())
162 : _M_invoke(_Invoker::template _S_storage<_Tp _GLIBCXX_MOF_INV_QUALS>())
164 static_assert(is_same_v<decay_t<_Tp>, _Tp>);
165 static_assert(is_copy_constructible_v<_Tp>);
177 _Base::operator=(
static_cast<_Base&&
>(__x));
178 _M_invoke = std::__exchange(__x._M_invoke,
nullptr);
201 template<
typename _Fn>
202 requires is_constructible_v<copyable_function, _Fn>
205 noexcept(is_nothrow_constructible_v<copyable_function, _Fn>)
211 ~copyable_function() =
default;
214 explicit operator bool() const noexcept
215 {
return _M_invoke !=
nullptr; }
226 operator()(_ArgTypes... __args) _GLIBCXX_MOF_CV_REF
noexcept(_Noex)
228 __glibcxx_assert(*
this !=
nullptr);
237 std::swap(_M_invoke, __x._M_invoke);
248 {
return __x._M_invoke ==
nullptr; }
251 typename _Invoker::__storage_func_t _M_invoke =
nullptr;
253 template<
typename _Func>
254 friend constexpr auto&
255 __polyfunc::__invoker_of(_Func&)
noexcept;
257 template<
typename _Func>
258 friend constexpr auto&
259 __polyfunc::__base_of(_Func&)
noexcept;
261 template<
typename _Src,
typename _Dst>
262 friend consteval bool
263 __polyfunc::__is_invoker_convertible() noexcept;