30#ifndef _ALLOCATED_PTR_H
31#define _ALLOCATED_PTR_H 1
33#if __cplusplus < 201103L
34# include <bits/c++0xwarning.h>
40namespace std _GLIBCXX_VISIBILITY(default)
42_GLIBCXX_BEGIN_NAMESPACE_VERSION
46 template<
typename _Alloc>
47 struct __allocated_ptr
53 __allocated_ptr(_Alloc& __a, pointer __ptr) noexcept
58 template<
typename _Ptr,
59 typename _Req = _Require<is_same<_Ptr, value_type*>>>
60 __allocated_ptr(_Alloc& __a, _Ptr __ptr)
62 _M_ptr(pointer_traits<pointer>::pointer_to(*__ptr))
66 __allocated_ptr(__allocated_ptr&& __gd) noexcept
67 : _M_alloc(__gd._M_alloc), _M_ptr(__gd._M_ptr)
68 { __gd._M_ptr =
nullptr; }
73 if (_M_ptr !=
nullptr)
85 explicit operator bool() const noexcept {
return (
bool)_M_ptr; }
90 pointer release() {
return std::__exchange(_M_ptr,
nullptr); }
98 template<
typename _Alloc>
99 inline __allocated_ptr<_Alloc>
100 __allocate_guarded(_Alloc& __a)
106 template<
typename _Alloc>
107 struct __allocated_obj : __allocated_ptr<_Alloc>
109 using value_type =
typename __allocated_ptr<_Alloc>::value_type;
111 __allocated_obj(__allocated_obj<_Alloc>&&) =
default;
114 __allocated_obj(__allocated_ptr<_Alloc>&& __ptr)
115 : __allocated_ptr<_Alloc>(
std::
move(__ptr))
116 { ::new ((
void*)this->get()) value_type; }
121 if (
static_cast<bool>(*
this))
122 this->get()->~value_type();
125 using __allocated_ptr<_Alloc>::operator=;
127 value_type&
operator*()
const {
return *this->get(); }
128 value_type* operator->()
const {
return this->get(); }
132 template<
typename _Alloc>
133 inline __allocated_obj<_Alloc>
134 __allocate_guarded_obj(_Alloc& __a)
140_GLIBCXX_END_NAMESPACE_VERSION
constexpr complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
ISO C++ entities toplevel namespace is std.
__detected_or_t< value_type *, __pointer, _Alloc > pointer
The allocator's pointer type.
static constexpr pointer allocate(_Alloc &__a, size_type __n)
Allocate memory.
_Alloc::value_type value_type
The allocated type.
static constexpr void deallocate(_Alloc &__a, pointer __p, size_type __n)
Deallocate memory.