30 #ifndef _GLIBCXX_MOVE_ONLY_FUNCTION_H
31 #define _GLIBCXX_MOVE_ONLY_FUNCTION_H 1
33 #ifdef _GLIBCXX_SYSHDR
34 #pragma GCC system_header
39 #ifdef __glibcxx_move_only_function
44 namespace std _GLIBCXX_VISIBILITY(default)
46 _GLIBCXX_BEGIN_NAMESPACE_VERSION
48 template<
typename... _Signature>
49 class move_only_function;
55 _Mofunc_base() noexcept
59 _Mofunc_base(_Mofunc_base&& __x) noexcept
61 _M_manage = std::__exchange(__x._M_manage, _S_empty);
62 _M_manage(_M_storage, &__x._M_storage);
65 template<
typename _Tp,
typename... _Args>
67 _S_nothrow_init() noexcept
69 if constexpr (__stored_locally<_Tp>)
70 return is_nothrow_constructible_v<_Tp, _Args...>;
74 template<
typename _Tp,
typename... _Args>
76 _M_init(_Args&&... __args) noexcept(_S_nothrow_init<_Tp, _Args...>())
78 if constexpr (__stored_locally<_Tp>)
79 ::new (_M_storage._M_addr()) _Tp(
std::
forward<_Args>(__args)...);
81 _M_storage._M_p =
new _Tp(std::forward<_Args>(__args)...);
83 _M_manage = &_S_manage<_Tp>;
87 operator=(_Mofunc_base&& __x) noexcept
89 _M_manage(_M_storage,
nullptr);
90 _M_manage = std::__exchange(__x._M_manage, _S_empty);
91 _M_manage(_M_storage, &__x._M_storage);
96 operator=(nullptr_t) noexcept
98 _M_manage(_M_storage,
nullptr);
103 ~_Mofunc_base() { _M_manage(_M_storage,
nullptr); }
106 swap(_Mofunc_base& __x) noexcept
110 __x._M_manage(__s, &__x._M_storage);
111 _M_manage(__x._M_storage, &_M_storage);
112 __x._M_manage(_M_storage, &__s);
113 std::swap(_M_manage, __x._M_manage);
116 template<
typename _Tp,
typename _Self>
118 _S_access(_Self* __self) noexcept
120 if constexpr (__stored_locally<remove_const_t<_Tp>>)
121 return static_cast<_Tp*>(__self->_M_storage._M_addr());
123 return static_cast<_Tp*>(__self->_M_storage._M_p);
129 void* _M_addr() noexcept {
return &_M_bytes[0]; }
130 const void* _M_addr() const noexcept {
return &_M_bytes[0]; }
133 struct _Delegate { void (_Storage::*__pfm)(); _Storage* __obj; };
136 alignas(_Delegate)
alignas(
void(*)())
137 unsigned char _M_bytes[
sizeof(_Delegate)];
141 template<
typename _Tp>
142 static constexpr
bool __stored_locally
143 =
sizeof(_Tp) <=
sizeof(_Storage) &&
alignof(_Tp) <=
alignof(_Storage)
144 && is_nothrow_move_constructible_v<_Tp>;
148 using _Manager = void (*)(_Storage& __target, _Storage* __src) noexcept;
151 static void _S_empty(_Storage&, _Storage*) noexcept { }
154 template<
typename _Tp>
156 _S_manage(_Storage& __target, _Storage* __src) noexcept
158 if constexpr (__stored_locally<_Tp>)
162 _Tp* __rval =
static_cast<_Tp*
>(__src->_M_addr());
163 ::new (__target._M_addr()) _Tp(
std::
move(*__rval));
167 static_cast<_Tp*>(__target._M_addr())->~_Tp();
172 __target._M_p = __src->_M_p;
174 delete static_cast<_Tp*
>(__target._M_p);
182 template<
typename _Tp>
183 inline constexpr
bool __is_move_only_function_v =
false;
184 template<
typename _Tp>
185 constexpr
bool __is_move_only_function_v<move_only_function<_Tp>> =
true;
188 namespace __detail::__variant
190 template<
typename>
struct _Never_valueless_alt;
194 template<
typename... _Signature>
195 struct _Never_valueless_alt<
std::move_only_function<_Signature...>>
200 _GLIBCXX_END_NAMESPACE_VERSION
204 #define _GLIBCXX_MOF_CV const
206 #define _GLIBCXX_MOF_REF &
208 #define _GLIBCXX_MOF_REF &&
210 #define _GLIBCXX_MOF_CV const
211 #define _GLIBCXX_MOF_REF &
213 #define _GLIBCXX_MOF_CV const
214 #define _GLIBCXX_MOF_REF &&
__bool_constant< true > true_type
The type used as a compile-time boolean with true value.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr _Tp && forward(typename std::remove_reference< _Tp >::type &__t) noexcept
Forward an lvalue.
ISO C++ entities toplevel namespace is std.