66 typedef _Tp value_type;
67 typedef std::size_t size_type;
68 typedef std::ptrdiff_t difference_type;
69#if __cplusplus <= 201703L
71 typedef const _Tp* const_pointer;
72 typedef _Tp& reference;
73 typedef const _Tp& const_reference;
75 template<
typename _Tp1>
77 {
typedef __new_allocator<_Tp1> other; };
80#if __cplusplus >= 201103L
86 __attribute__((__always_inline__))
88 __new_allocator() _GLIBCXX_USE_NOEXCEPT { }
90 __attribute__((__always_inline__))
92 __new_allocator(
const __new_allocator&) _GLIBCXX_USE_NOEXCEPT { }
94 template<
typename _Tp1>
95 __attribute__((__always_inline__))
97 __new_allocator(
const __new_allocator<_Tp1>&) _GLIBCXX_USE_NOEXCEPT { }
99#if __cplusplus >= 201103L
100 __new_allocator& operator=(
const __new_allocator&) =
default;
103#if __cplusplus <= 201703L
104 ~__new_allocator() _GLIBCXX_USE_NOEXCEPT { }
107 address(reference __x)
const _GLIBCXX_NOEXCEPT
111 address(const_reference __x)
const _GLIBCXX_NOEXCEPT
115#if __has_builtin(__builtin_operator_new) >= 201802L
116# define _GLIBCXX_OPERATOR_NEW __builtin_operator_new
117# define _GLIBCXX_OPERATOR_DELETE __builtin_operator_delete
119# define _GLIBCXX_OPERATOR_NEW ::operator new
120# define _GLIBCXX_OPERATOR_DELETE ::operator delete
123#pragma GCC diagnostic push
124#pragma GCC diagnostic ignored "-Wc++17-extensions"
128 _GLIBCXX_NODISCARD _GLIBCXX20_CONSTEXPR _Tp*
129 allocate(size_type __n,
const void* =
static_cast<const void*
>(0))
131#if __cplusplus >= 201103L
135 static_assert(
sizeof(_Tp) != 0,
"cannot allocate incomplete types");
137 static_assert(
requires {
sizeof(_Tp); },
138 "cannot allocate incomplete types");
140 if constexpr (!
requires {
sizeof(_Tp); })
145 if (__builtin_expect(__n > this->_M_max_size(),
false))
149 if (__n > (std::size_t(-1) /
sizeof(_Tp)))
150 std::__throw_bad_array_new_length();
151 std::__throw_bad_alloc();
153#if __cpp_aligned_new && __cplusplus >= 201103L
154 else if constexpr (
alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
156 std::align_val_t __al = std::align_val_t(
alignof(_Tp));
157 return static_cast<_Tp*
>(_GLIBCXX_OPERATOR_NEW(__n *
sizeof(_Tp),
162 return static_cast<_Tp*
>(_GLIBCXX_OPERATOR_NEW(__n *
sizeof(_Tp)));
166 _GLIBCXX20_CONSTEXPR
void
167 deallocate(_Tp* __p, size_type __n __attribute__ ((__unused__)))
169#if __cpp_sized_deallocation
170# define _GLIBCXX_SIZED_DEALLOC(p, n) (p), (n) * sizeof(_Tp)
172# define _GLIBCXX_SIZED_DEALLOC(p, n) (p)
175#if __cpp_aligned_new && __cplusplus >= 201103L
176 if constexpr (
alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
178 _GLIBCXX_OPERATOR_DELETE(_GLIBCXX_SIZED_DEALLOC(__p, __n),
179 std::align_val_t(
alignof(_Tp)));
183 _GLIBCXX_OPERATOR_DELETE(_GLIBCXX_SIZED_DEALLOC(__p, __n));
186#pragma GCC diagnostic pop
187#undef _GLIBCXX_SIZED_DEALLOC
188#undef _GLIBCXX_OPERATOR_DELETE
189#undef _GLIBCXX_OPERATOR_NEW
191#if __cplusplus <= 201703L
192 __attribute__((__always_inline__))
194 max_size()
const _GLIBCXX_USE_NOEXCEPT
195 {
return _M_max_size(); }
197#if __cplusplus >= 201103L
198 template<
typename _Up,
typename... _Args>
199 __attribute__((__always_inline__))
201 construct(_Up* __p, _Args&&... __args)
202 noexcept(__is_nothrow_new_constructible<_Up, _Args...>)
205 template<
typename _Up>
206 __attribute__((__always_inline__))
214 __attribute__((__always_inline__))
216 construct(pointer __p,
const _Tp& __val)
217 { ::new((
void *)__p) _Tp(__val); }
219 __attribute__((__always_inline__))
221 destroy(pointer __p) { __p->~_Tp(); }
225 template<
typename _Up>
226 friend __attribute__((__always_inline__)) _GLIBCXX20_CONSTEXPR
bool
227 operator==(
const __new_allocator&,
const __new_allocator<_Up>&)
231#if __cpp_impl_three_way_comparison < 201907L
232 template<
typename _Up>
233 friend __attribute__((__always_inline__)) _GLIBCXX20_CONSTEXPR
bool
234 operator!=(
const __new_allocator&,
const __new_allocator<_Up>&)
240 __attribute__((__always_inline__))
241 _GLIBCXX_CONSTEXPR size_type
242 _M_max_size()
const _GLIBCXX_USE_NOEXCEPT
244#if __PTRDIFF_MAX__ < __SIZE_MAX__
245 return std::size_t(__PTRDIFF_MAX__) /
sizeof(_Tp);
247 return std::size_t(-1) /
sizeof(_Tp);