30#ifndef _STD_NEW_ALLOCATOR_H
31#define _STD_NEW_ALLOCATOR_H 1
37#if __cplusplus >= 201103L
41namespace std _GLIBCXX_VISIBILITY(default)
43_GLIBCXX_BEGIN_NAMESPACE_VERSION
62 template<
typename _Tp>
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>
80#if __cplusplus >= 201103L
86 __attribute__((__always_inline__))
90 __attribute__((__always_inline__))
94 template<
typename _Tp1>
95 __attribute__((__always_inline__))
99#if __cplusplus <= 201703L
103 address(reference __x)
const _GLIBCXX_NOEXCEPT
107 address(const_reference __x)
const _GLIBCXX_NOEXCEPT
111#if __has_builtin(__builtin_operator_new) >= 201802L
112# define _GLIBCXX_OPERATOR_NEW __builtin_operator_new
113# define _GLIBCXX_OPERATOR_DELETE __builtin_operator_delete
115# define _GLIBCXX_OPERATOR_NEW ::operator new
116# define _GLIBCXX_OPERATOR_DELETE ::operator delete
121 _GLIBCXX_NODISCARD _Tp*
122 allocate(size_type __n,
const void* =
static_cast<const void*
>(0))
124#if __cplusplus >= 201103L
127 static_assert(
sizeof(_Tp) != 0,
"cannot allocate incomplete types");
130 if (__builtin_expect(__n > this->_M_max_size(),
false))
134 if (__n > (std::size_t(-1) /
sizeof(_Tp)))
135 std::__throw_bad_array_new_length();
136 std::__throw_bad_alloc();
140 if (
alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
142 std::align_val_t __al = std::align_val_t(
alignof(_Tp));
143 return static_cast<_Tp*
>(_GLIBCXX_OPERATOR_NEW(__n *
sizeof(_Tp),
147 return static_cast<_Tp*
>(_GLIBCXX_OPERATOR_NEW(__n *
sizeof(_Tp)));
152 deallocate(_Tp* __p, size_type __n __attribute__ ((__unused__)))
154#if __cpp_sized_deallocation
155# define _GLIBCXX_SIZED_DEALLOC(p, n) (p), (n) * sizeof(_Tp)
157# define _GLIBCXX_SIZED_DEALLOC(p, n) (p)
161 if (
alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
163 _GLIBCXX_OPERATOR_DELETE(_GLIBCXX_SIZED_DEALLOC(__p, __n),
164 std::align_val_t(
alignof(_Tp)));
168 _GLIBCXX_OPERATOR_DELETE(_GLIBCXX_SIZED_DEALLOC(__p, __n));
171#undef _GLIBCXX_SIZED_DEALLOC
172#undef _GLIBCXX_OPERATOR_DELETE
173#undef _GLIBCXX_OPERATOR_NEW
175#if __cplusplus <= 201703L
176 __attribute__((__always_inline__))
178 max_size()
const _GLIBCXX_USE_NOEXCEPT
179 {
return _M_max_size(); }
181#if __cplusplus >= 201103L
182 template<
typename _Up,
typename... _Args>
183 __attribute__((__always_inline__))
185 construct(_Up* __p, _Args&&... __args)
187 { ::new((
void *)__p) _Up(std::forward<_Args>(__args)...); }
189 template<
typename _Up>
190 __attribute__((__always_inline__))
198 __attribute__((__always_inline__))
200 construct(pointer __p,
const _Tp& __val)
201 { ::new((
void *)__p) _Tp(__val); }
203 __attribute__((__always_inline__))
205 destroy(pointer __p) { __p->~_Tp(); }
209 template<
typename _Up>
210 friend __attribute__((__always_inline__)) _GLIBCXX20_CONSTEXPR
bool
215#if __cpp_impl_three_way_comparison < 201907L
216 template<
typename _Up>
217 friend __attribute__((__always_inline__)) _GLIBCXX20_CONSTEXPR
bool
224 __attribute__((__always_inline__))
225 _GLIBCXX_CONSTEXPR size_type
226 _M_max_size()
const _GLIBCXX_USE_NOEXCEPT
228#if __PTRDIFF_MAX__ < __SIZE_MAX__
229 return std::size_t(__PTRDIFF_MAX__) /
sizeof(_Tp);
231 return std::size_t(-1) /
sizeof(_Tp);
236_GLIBCXX_END_NAMESPACE_VERSION
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
ISO C++ entities toplevel namespace is std.
An allocator that uses global new, as per C++03 [20.4.1].