| 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 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
#ifndef _ALLOCATOR_H |
| 44 |
#define _ALLOCATOR_H 1 |
| 45 |
|
| 46 |
#include <bits/c++allocator.h> |
| 47 |
#include <bits/memoryfwd.h> |
| 48 |
#if __cplusplus >= 201103L |
| 49 |
#include <type_traits> |
| 50 |
#endif |
| 51 |
|
| 52 |
#pragma GCC diagnostic push |
| 53 |
#pragma GCC diagnostic ignored "-Wc++11-extensions" |
| 54 |
|
| 55 |
namespace std _GLIBCXX_VISIBILITY(default) |
| 56 |
{ |
| 57 |
_GLIBCXX_BEGIN_NAMESPACE_VERSION |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
template<> |
| 76 |
class allocator<void> |
| 77 |
{ |
| 78 |
public: |
| 79 |
typedef void value_type; |
| 80 |
typedef size_t size_type; |
| 81 |
typedef ptrdiff_t difference_type; |
| 82 |
|
| 83 |
#if __cplusplus <= 201703L |
| 84 |
|
| 85 |
typedef void* pointer; |
| 86 |
typedef const void* const_pointer; |
| 87 |
|
| 88 |
template<typename _Tp1> |
| 89 |
struct rebind |
| 90 |
{ typedef allocator<_Tp1> other; }; |
| 91 |
#endif |
| 92 |
|
| 93 |
#if __cplusplus >= 201103L |
| 94 |
|
| 95 |
|
| 96 |
using propagate_on_container_move_assignment = true_type; |
| 97 |
|
| 98 |
#if __cplusplus <= 202302L |
| 99 |
using is_always_equal |
| 100 |
_GLIBCXX20_DEPRECATED_SUGGEST("std::allocator_traits::is_always_equal") |
| 101 |
= true_type; |
| 102 |
#endif |
| 103 |
|
| 104 |
#if __cplusplus >= 202002L |
| 105 |
|
| 106 |
|
| 107 |
allocator() = default; |
| 108 |
~allocator() = default; |
| 109 |
|
| 110 |
template<typename _Up> |
| 111 |
__attribute__((__always_inline__)) |
| 112 |
constexpr |
| 113 |
allocator(const allocator<_Up>&) noexcept { } |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
#endif |
| 119 |
#endif |
| 120 |
}; |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
template<typename _Tp> |
| 133 |
class allocator : public __allocator_base<_Tp> |
| 134 |
{ |
| 135 |
public: |
| 136 |
typedef _Tp value_type; |
| 137 |
typedef size_t size_type; |
| 138 |
typedef ptrdiff_t difference_type; |
| 139 |
|
| 140 |
#if __cplusplus <= 201703L |
| 141 |
|
| 142 |
typedef _Tp* pointer; |
| 143 |
typedef const _Tp* const_pointer; |
| 144 |
typedef _Tp& reference; |
| 145 |
typedef const _Tp& const_reference; |
| 146 |
|
| 147 |
template<typename _Tp1> |
| 148 |
struct rebind |
| 149 |
{ typedef allocator<_Tp1> other; }; |
| 150 |
#endif |
| 151 |
|
| 152 |
#if __cplusplus >= 201103L |
| 153 |
|
| 154 |
|
| 155 |
using propagate_on_container_move_assignment = true_type; |
| 156 |
|
| 157 |
#if __cplusplus <= 202302L |
| 158 |
using is_always_equal |
| 159 |
_GLIBCXX20_DEPRECATED_SUGGEST("std::allocator_traits::is_always_equal") |
| 160 |
= true_type; |
| 161 |
#endif |
| 162 |
#endif |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
__attribute__((__always_inline__)) |
| 167 |
_GLIBCXX20_CONSTEXPR |
| 168 |
allocator() _GLIBCXX_NOTHROW { } |
| 169 |
|
| 170 |
__attribute__((__always_inline__)) |
| 171 |
_GLIBCXX20_CONSTEXPR |
| 172 |
allocator(const allocator& __a) _GLIBCXX_NOTHROW |
| 173 |
: __allocator_base<_Tp>(__a) { } |
| 174 |
|
| 175 |
#if __cplusplus >= 201103L |
| 176 |
|
| 177 |
allocator& operator=(const allocator&) = default; |
| 178 |
#endif |
| 179 |
|
| 180 |
template<typename _Tp1> |
| 181 |
__attribute__((__always_inline__)) |
| 182 |
_GLIBCXX20_CONSTEXPR |
| 183 |
allocator(const allocator<_Tp1>&) _GLIBCXX_NOTHROW { } |
| 184 |
|
| 185 |
__attribute__((__always_inline__)) |
| 186 |
#if __cpp_constexpr_dynamic_alloc |
| 187 |
constexpr |
| 188 |
#endif |
| 189 |
~allocator() _GLIBCXX_NOTHROW { } |
| 190 |
|
| 191 |
#if __cplusplus > 201703L |
| 192 |
[[nodiscard,__gnu__::__always_inline__]] |
| 193 |
constexpr _Tp* |
| 194 |
allocate(size_t __n) |
| 195 |
{ |
| 196 |
if (std::__is_constant_evaluated()) |
| 197 |
{ |
| 198 |
if (__builtin_mul_overflow(__n, sizeof(_Tp), &__n)) |
| 199 |
std::__throw_bad_array_new_length(); |
| 200 |
return static_cast<_Tp*>(::operator new(__n)); |
| 201 |
} |
| 202 |
|
| 203 |
return __allocator_base<_Tp>::allocate(__n, 0); |
| 204 |
} |
| 205 |
|
| 206 |
[[__gnu__::__always_inline__]] |
| 207 |
constexpr void |
| 208 |
deallocate(_Tp* __p, size_t __n) |
| 209 |
{ |
| 210 |
if (std::__is_constant_evaluated()) |
| 211 |
{ |
| 212 |
::operator delete(__p); |
| 213 |
return; |
| 214 |
} |
| 215 |
__allocator_base<_Tp>::deallocate(__p, __n); |
| 216 |
} |
| 217 |
#endif |
| 218 |
|
| 219 |
friend __attribute__((__always_inline__)) _GLIBCXX20_CONSTEXPR |
| 220 |
bool |
| 221 |
operator==(const allocator&, const allocator&) _GLIBCXX_NOTHROW |
| 222 |
{ return true; } |
| 223 |
|
| 224 |
#if __cpp_impl_three_way_comparison < 201907L |
| 225 |
friend __attribute__((__always_inline__)) _GLIBCXX20_CONSTEXPR |
| 226 |
bool |
| 227 |
operator!=(const allocator&, const allocator&) _GLIBCXX_NOTHROW |
| 228 |
{ return false; } |
| 229 |
#endif |
| 230 |
|
| 231 |
|
| 232 |
}; |
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
template<typename _T1, typename _T2> |
| 240 |
__attribute__((__always_inline__)) |
| 241 |
inline _GLIBCXX20_CONSTEXPR bool |
| 242 |
operator==(const allocator<_T1>&, const allocator<_T2>&) |
| 243 |
_GLIBCXX_NOTHROW |
| 244 |
{ return true; } |
| 245 |
|
| 246 |
#if __cpp_impl_three_way_comparison < 201907L |
| 247 |
template<typename _T1, typename _T2> |
| 248 |
__attribute__((__always_inline__)) |
| 249 |
inline _GLIBCXX20_CONSTEXPR bool |
| 250 |
operator!=(const allocator<_T1>&, const allocator<_T2>&) |
| 251 |
_GLIBCXX_NOTHROW |
| 252 |
{ return false; } |
| 253 |
#endif |
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
template<typename _Tp> |
| 260 |
class allocator<const _Tp> |
| 261 |
{ |
| 262 |
public: |
| 263 |
typedef _Tp value_type; |
| 264 |
allocator() { } |
| 265 |
template<typename _Up> allocator(const allocator<_Up>&) { } |
| 266 |
}; |
| 267 |
|
| 268 |
template<typename _Tp> |
| 269 |
class allocator<volatile _Tp> |
| 270 |
{ |
| 271 |
public: |
| 272 |
typedef _Tp value_type; |
| 273 |
allocator() { } |
| 274 |
template<typename _Up> allocator(const allocator<_Up>&) { } |
| 275 |
}; |
| 276 |
|
| 277 |
template<typename _Tp> |
| 278 |
class allocator<const volatile _Tp> |
| 279 |
{ |
| 280 |
public: |
| 281 |
typedef _Tp value_type; |
| 282 |
allocator() { } |
| 283 |
template<typename _Up> allocator(const allocator<_Up>&) { } |
| 284 |
}; |
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
#if _GLIBCXX_EXTERN_TEMPLATE |
| 292 |
extern template class allocator<char>; |
| 293 |
extern template class allocator<wchar_t>; |
| 294 |
#endif |
| 295 |
|
| 296 |
|
| 297 |
#undef __allocator_base |
| 298 |
|
| 299 |
_GLIBCXX_END_NAMESPACE_VERSION |
| 300 |
} |
| 301 |
|
| 302 |
#pragma GCC diagnostic pop |
| 303 |
#endif |