30 #ifndef _GLIBCXX_MOVE_ONLY_FUNCTION_H
31 #define _GLIBCXX_MOVE_ONLY_FUNCTION_H 1
33 #pragma GCC system_header
35 #if __cplusplus > 202002L
40 namespace std _GLIBCXX_VISIBILITY(default)
42 _GLIBCXX_BEGIN_NAMESPACE_VERSION
44 #define __cpp_lib_move_only_function 202110L
46 template<
typename... _Signature>
47 class move_only_function;
53 _Mofunc_base() noexcept
57 _Mofunc_base(_Mofunc_base&& __x) noexcept
59 _M_manage = std::__exchange(__x._M_manage, _S_empty);
60 _M_manage(_M_storage, &__x._M_storage);
63 template<
typename _Tp,
typename... _Args>
65 _S_nothrow_init() noexcept
67 if constexpr (__stored_locally<_Tp>)
68 return is_nothrow_constructible_v<_Tp, _Args...>;
72 template<
typename _Tp,
typename... _Args>
74 _M_init(_Args&&... __args) noexcept(_S_nothrow_init<_Tp, _Args...>())
76 if constexpr (__stored_locally<_Tp>)
77 ::new (_M_storage._M_addr()) _Tp(
std::
forward<_Args>(__args)...);
79 _M_storage._M_p =
new _Tp(std::forward<_Args>(__args)...);
81 _M_manage = &_S_manage<_Tp>;
85 operator=(_Mofunc_base&& __x) noexcept
87 _M_manage(_M_storage,
nullptr);
88 _M_manage = std::__exchange(__x._M_manage, _S_empty);
89 _M_manage(_M_storage, &__x._M_storage);
94 operator=(nullptr_t) noexcept
96 _M_manage(_M_storage,
nullptr);
101 ~_Mofunc_base() { _M_manage(_M_storage,
nullptr); }
104 swap(_Mofunc_base& __x) noexcept
108 __x._M_manage(__s, &__x._M_storage);
109 _M_manage(__x._M_storage, &_M_storage);
110 __x._M_manage(_M_storage, &__s);
114 template<
typename _Tp,
typename _Self>
116 _S_access(_Self* __self) noexcept
118 if constexpr (__stored_locally<remove_const_t<_Tp>>)
119 return static_cast<_Tp*>(__self->_M_storage._M_addr());
121 return static_cast<_Tp*>(__self->_M_storage._M_p);
127 void* _M_addr() noexcept {
return &_M_bytes[0]; }
128 const void* _M_addr() const noexcept {
return &_M_bytes[0]; }
131 struct _Delegate { void (_Storage::*__pfm)(); _Storage* __obj; };
134 alignas(_Delegate)
alignas(
void(*)())
135 unsigned char _M_bytes[
sizeof(_Delegate)];
139 template<
typename _Tp>
140 static constexpr
bool __stored_locally
141 =
sizeof(_Tp) <=
sizeof(_Storage) &&
alignof(_Tp) <=
alignof(_Storage)
142 && is_nothrow_move_constructible_v<_Tp>;
146 using _Manager = void (*)(_Storage& __target, _Storage* __src) noexcept;
149 static void _S_empty(_Storage&, _Storage*) noexcept { }
152 template<
typename _Tp>
154 _S_manage(_Storage& __target, _Storage* __src) noexcept
156 if constexpr (__stored_locally<_Tp>)
160 _Tp* __rval =
static_cast<_Tp*
>(__src->_M_addr());
161 ::new (__target._M_addr()) _Tp(
std::
move(*__rval));
165 static_cast<_Tp*>(__target._M_addr())->~_Tp();
170 __target._M_p = __src->_M_p;
172 delete static_cast<_Tp*
>(__target._M_p);
180 template<
typename _Tp>
181 inline constexpr
bool __is_move_only_function_v =
false;
182 template<
typename _Tp>
183 constexpr
bool __is_move_only_function_v<move_only_function<_Tp>> =
true;
186 _GLIBCXX_END_NAMESPACE_VERSION
190 #define _GLIBCXX_MOF_CV const
192 #define _GLIBCXX_MOF_REF &
194 #define _GLIBCXX_MOF_REF &&
196 #define _GLIBCXX_MOF_CV const
197 #define _GLIBCXX_MOF_REF &
199 #define _GLIBCXX_MOF_CV const
200 #define _GLIBCXX_MOF_REF &&
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.
void swap(any &__x, any &__y) noexcept
Exchange the states of two any objects.
ISO C++ entities toplevel namespace is std.