| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
#ifndef _EXTPTR_ALLOCATOR_H |
| 37 |
#define _EXTPTR_ALLOCATOR_H 1 |
| 38 |
|
| 39 |
#include <bits/requires_hosted.h> |
| 40 |
|
| 41 |
#include <memory> |
| 42 |
#include <ext/numeric_traits.h> |
| 43 |
#include <ext/pointer.h> |
| 44 |
|
| 45 |
namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) |
| 46 |
{ |
| 47 |
_GLIBCXX_BEGIN_NAMESPACE_VERSION |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
template<typename _Tp> |
| 58 |
class _ExtPtr_allocator |
| 59 |
{ |
| 60 |
public: |
| 61 |
typedef std::size_t size_type; |
| 62 |
typedef std::ptrdiff_t difference_type; |
| 63 |
|
| 64 |
|
| 65 |
typedef _Pointer_adapter<_Relative_pointer_impl<_Tp> > pointer; |
| 66 |
typedef _Pointer_adapter<_Relative_pointer_impl<const _Tp> > |
| 67 |
const_pointer; |
| 68 |
|
| 69 |
typedef _Tp& reference; |
| 70 |
typedef const _Tp& const_reference; |
| 71 |
typedef _Tp value_type; |
| 72 |
|
| 73 |
template<typename _Up> |
| 74 |
struct rebind |
| 75 |
{ typedef _ExtPtr_allocator<_Up> other; }; |
| 76 |
|
| 77 |
_ExtPtr_allocator() _GLIBCXX_USE_NOEXCEPT |
| 78 |
: _M_real_alloc() { } |
| 79 |
|
| 80 |
_ExtPtr_allocator(const _ExtPtr_allocator& __rarg) _GLIBCXX_USE_NOEXCEPT |
| 81 |
: _M_real_alloc(__rarg._M_real_alloc) { } |
| 82 |
|
| 83 |
template<typename _Up> |
| 84 |
_ExtPtr_allocator(const _ExtPtr_allocator<_Up>& __rarg) |
| 85 |
_GLIBCXX_USE_NOEXCEPT |
| 86 |
: _M_real_alloc(__rarg._M_getUnderlyingImp()) { } |
| 87 |
|
| 88 |
~_ExtPtr_allocator() _GLIBCXX_USE_NOEXCEPT |
| 89 |
{ } |
| 90 |
|
| 91 |
pointer address(reference __x) const _GLIBCXX_NOEXCEPT |
| 92 |
{ return std::__addressof(__x); } |
| 93 |
|
| 94 |
const_pointer address(const_reference __x) const _GLIBCXX_NOEXCEPT |
| 95 |
{ return std::__addressof(__x); } |
| 96 |
|
| 97 |
_GLIBCXX_NODISCARD pointer allocate(size_type __n, const void* = 0) |
| 98 |
{ return _M_real_alloc.allocate(__n); } |
| 99 |
|
| 100 |
void deallocate(pointer __p, size_type __n) |
| 101 |
{ _M_real_alloc.deallocate(__p.get(), __n); } |
| 102 |
|
| 103 |
size_type max_size() const _GLIBCXX_USE_NOEXCEPT |
| 104 |
{ return __numeric_traits<size_type>::__max / sizeof(_Tp); } |
| 105 |
|
| 106 |
#if __cplusplus >= 201103L |
| 107 |
template<typename _Up, typename... _Args> |
| 108 |
void |
| 109 |
construct(_Up* __p, _Args&&... __args) |
| 110 |
{ ::new((void *)__p) _Up(std::forward<_Args>(__args)...); } |
| 111 |
|
| 112 |
template<typename... _Args> |
| 113 |
void |
| 114 |
construct(pointer __p, _Args&&... __args) |
| 115 |
{ construct(__p.get(), std::forward<_Args>(__args)...); } |
| 116 |
|
| 117 |
template<typename _Up> |
| 118 |
void |
| 119 |
destroy(_Up* __p) |
| 120 |
{ __p->~_Up(); } |
| 121 |
|
| 122 |
void destroy(pointer __p) |
| 123 |
{ destroy(__p.get()); } |
| 124 |
|
| 125 |
#else |
| 126 |
|
| 127 |
void construct(pointer __p, const _Tp& __val) |
| 128 |
{ ::new(__p.get()) _Tp(__val); } |
| 129 |
|
| 130 |
void destroy(pointer __p) |
| 131 |
{ __p->~_Tp(); } |
| 132 |
#endif |
| 133 |
|
| 134 |
template<typename _Up> |
| 135 |
inline bool |
| 136 |
operator==(const _ExtPtr_allocator<_Up>& __rarg) const |
| 137 |
{ return _M_real_alloc == __rarg._M_getUnderlyingImp(); } |
| 138 |
|
| 139 |
inline bool |
| 140 |
operator==(const _ExtPtr_allocator& __rarg) const |
| 141 |
{ return _M_real_alloc == __rarg._M_real_alloc; } |
| 142 |
|
| 143 |
#if __cpp_impl_three_way_comparison < 201907L |
| 144 |
template<typename _Up> |
| 145 |
inline bool |
| 146 |
operator!=(const _ExtPtr_allocator<_Up>& __rarg) const |
| 147 |
{ return _M_real_alloc != __rarg._M_getUnderlyingImp(); } |
| 148 |
|
| 149 |
inline bool |
| 150 |
operator!=(const _ExtPtr_allocator& __rarg) const |
| 151 |
{ return _M_real_alloc != __rarg._M_real_alloc; } |
| 152 |
#endif |
| 153 |
|
| 154 |
template<typename _Up> |
| 155 |
inline friend void |
| 156 |
swap(_ExtPtr_allocator<_Up>&, _ExtPtr_allocator<_Up>&); |
| 157 |
|
| 158 |
|
| 159 |
const std::allocator<_Tp>& |
| 160 |
_M_getUnderlyingImp() const |
| 161 |
{ return _M_real_alloc; } |
| 162 |
|
| 163 |
private: |
| 164 |
std::allocator<_Tp> _M_real_alloc; |
| 165 |
}; |
| 166 |
|
| 167 |
|
| 168 |
template<> |
| 169 |
class _ExtPtr_allocator<void> |
| 170 |
{ |
| 171 |
public: |
| 172 |
typedef std::size_t size_type; |
| 173 |
typedef std::ptrdiff_t difference_type; |
| 174 |
typedef void value_type; |
| 175 |
|
| 176 |
|
| 177 |
typedef _Pointer_adapter<_Relative_pointer_impl<void> > pointer; |
| 178 |
typedef _Pointer_adapter<_Relative_pointer_impl<const void> > |
| 179 |
const_pointer; |
| 180 |
|
| 181 |
_ExtPtr_allocator() { } |
| 182 |
|
| 183 |
template<typename _Up> |
| 184 |
_ExtPtr_allocator(const _ExtPtr_allocator<_Up>&) { } |
| 185 |
|
| 186 |
template<typename _Up> |
| 187 |
struct rebind |
| 188 |
{ typedef _ExtPtr_allocator<_Up> other; }; |
| 189 |
|
| 190 |
private: |
| 191 |
std::allocator<void> _M_real_alloc; |
| 192 |
}; |
| 193 |
|
| 194 |
template<typename _Tp> |
| 195 |
inline void |
| 196 |
swap(_ExtPtr_allocator<_Tp>& __larg, _ExtPtr_allocator<_Tp>& __rarg) |
| 197 |
{ |
| 198 |
std::allocator<_Tp> __tmp( __rarg._M_real_alloc ); |
| 199 |
__rarg._M_real_alloc = __larg._M_real_alloc; |
| 200 |
__larg._M_real_alloc = __tmp; |
| 201 |
} |
| 202 |
|
| 203 |
_GLIBCXX_END_NAMESPACE_VERSION |
| 204 |
} |
| 205 |
|
| 206 |
#endif |