63 class move_only_function<_Res(_ArgTypes...) _GLIBCXX_MOF_CV
64 _GLIBCXX_MOF_REF noexcept(_Noex)>
67 template<
typename _Tp>
69 = __conditional_t<_Noex,
70 is_nothrow_invocable_r<_Res, _Tp, _ArgTypes...>,
71 is_invocable_r<_Res, _Tp, _ArgTypes...>>;
74 template<
typename _Vt>
75 static constexpr bool __is_callable_from
76 = __and_v<__callable<_Vt _GLIBCXX_MOF_CV_REF>,
77 __callable<_Vt _GLIBCXX_MOF_INV_QUALS>>;
80 using result_type = _Res;
83 move_only_function() noexcept { }
86 move_only_function(nullptr_t)
noexcept { }
89 move_only_function(move_only_function&& __x) noexcept
90 : _Mofunc_base(
static_cast<_Mofunc_base&&
>(__x)),
91 _M_invoke(std::__exchange(__x._M_invoke,
nullptr))
95 template<
typename _Fn,
typename _Vt = decay_t<_Fn>>
96 requires (!is_same_v<_Vt, move_only_function>)
97 && (!__is_in_place_type_v<_Vt>) && __is_callable_from<_Vt>
98 move_only_function(_Fn&& __f)
noexcept(_S_nothrow_init<_Vt, _Fn>())
100 if constexpr (is_function_v<remove_pointer_t<_Vt>>
101 || is_member_pointer_v<_Vt>
102 || __is_move_only_function_v<_Vt>)
108 _M_invoke = &_S_invoke<_Vt>;
112 template<
typename _Tp,
typename... _Args>
113 requires is_constructible_v<_Tp, _Args...>
114 && __is_callable_from<_Tp>
116 move_only_function(in_place_type_t<_Tp>, _Args&&... __args)
117 noexcept(_S_nothrow_init<_Tp, _Args...>())
118 : _M_invoke(&_S_invoke<_Tp>)
120 static_assert(is_same_v<decay_t<_Tp>, _Tp>);
125 template<
typename _Tp,
typename _Up,
typename... _Args>
126 requires is_constructible_v<_Tp, initializer_list<_Up>&, _Args...>
127 && __is_callable_from<_Tp>
131 noexcept(_S_nothrow_init<_Tp, initializer_list<_Up>&, _Args...>())
132 : _M_invoke(&_S_invoke<_Tp>)
134 static_assert(is_same_v<decay_t<_Tp>, _Tp>);
140 operator=(move_only_function&& __x)
noexcept
142 _Mofunc_base::operator=(
static_cast<_Mofunc_base&&
>(__x));
143 _M_invoke = std::__exchange(__x._M_invoke,
nullptr);
149 operator=(nullptr_t)
noexcept
151 _Mofunc_base::operator=(
nullptr);
157 template<
typename _Fn>
158 requires is_constructible_v<move_only_function, _Fn>
161 noexcept(is_nothrow_constructible_v<move_only_function, _Fn>)
167 ~move_only_function() =
default;
170 explicit operator bool() const noexcept {
return _M_invoke !=
nullptr; }
181 operator()(_ArgTypes... __args) _GLIBCXX_MOF_CV_REF
noexcept(_Noex)
183 __glibcxx_assert(*
this !=
nullptr);
189 swap(move_only_function& __x)
noexcept
191 _Mofunc_base::swap(__x);
192 std::swap(_M_invoke, __x._M_invoke);
197 swap(move_only_function& __x, move_only_function& __y)
noexcept
202 operator==(
const move_only_function& __x, nullptr_t)
noexcept
203 {
return __x._M_invoke ==
nullptr; }
206 template<
typename _Tp>
207 using __param_t = __conditional_t<is_scalar_v<_Tp>, _Tp, _Tp&&>;
209 using _Invoker = _Res (*)(_Mofunc_base _GLIBCXX_MOF_CV*,
210 __param_t<_ArgTypes>...)
noexcept(_Noex);
212 template<
typename _Tp>
214 _S_invoke(_Mofunc_base _GLIBCXX_MOF_CV* __self,
215 __param_t<_ArgTypes>... __args)
noexcept(_Noex)
217 using _TpCv = _Tp _GLIBCXX_MOF_CV;
218 using _TpInv = _Tp _GLIBCXX_MOF_INV_QUALS;
219 return std::__invoke_r<_Res>(
224 _Invoker _M_invoke =
nullptr;