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
92 template<
typename _Tp1>
96#if __cplusplus >= 201103L
100#if __cplusplus <= 201703L
104 address(reference __x)
const _GLIBCXX_NOEXCEPT
108 address(const_reference __x)
const _GLIBCXX_NOEXCEPT
112#if __has_builtin(__builtin_operator_new) >= 201802L
113# define _GLIBCXX_OPERATOR_NEW __builtin_operator_new
114# define _GLIBCXX_OPERATOR_DELETE __builtin_operator_delete
116# define _GLIBCXX_OPERATOR_NEW ::operator new
117# define _GLIBCXX_OPERATOR_DELETE ::operator delete
122 _GLIBCXX_NODISCARD _Tp*
123 allocate(size_type __n,
const void* =
static_cast<const void*
>(0))
125#if __cplusplus >= 201103L
128 static_assert(
sizeof(_Tp) != 0,
"cannot allocate incomplete types");
131 if (__builtin_expect(__n > this->_M_max_size(),
false))
135 if (__n > (std::size_t(-1) /
sizeof(_Tp)))
136 std::__throw_bad_array_new_length();
137 std::__throw_bad_alloc();
141 if (
alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
143 std::align_val_t __al = std::align_val_t(
alignof(_Tp));
144 return static_cast<_Tp*
>(_GLIBCXX_OPERATOR_NEW(__n *
sizeof(_Tp),
148 return static_cast<_Tp*
>(_GLIBCXX_OPERATOR_NEW(__n *
sizeof(_Tp)));
153 deallocate(_Tp* __p, size_type __n __attribute__ ((__unused__)))
155#if __cpp_sized_deallocation
156# define _GLIBCXX_SIZED_DEALLOC(p, n) (p), (n) * sizeof(_Tp)
158# define _GLIBCXX_SIZED_DEALLOC(p, n) (p)
162 if (
alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
164 _GLIBCXX_OPERATOR_DELETE(_GLIBCXX_SIZED_DEALLOC(__p, __n),
165 std::align_val_t(
alignof(_Tp)));
169 _GLIBCXX_OPERATOR_DELETE(_GLIBCXX_SIZED_DEALLOC(__p, __n));
172#undef _GLIBCXX_SIZED_DEALLOC
173#undef _GLIBCXX_OPERATOR_DELETE
174#undef _GLIBCXX_OPERATOR_NEW
176#if __cplusplus <= 201703L
178 max_size()
const _GLIBCXX_USE_NOEXCEPT
179 {
return _M_max_size(); }
181#if __cplusplus >= 201103L
182 template<
typename _Up,
typename... _Args>
184 construct(_Up* __p, _Args&&... __args)
186 { ::new((
void *)__p) _Up(std::forward<_Args>(__args)...); }
188 template<
typename _Up>
197 construct(pointer __p,
const _Tp& __val)
198 { ::new((
void *)__p) _Tp(__val); }
201 destroy(pointer __p) { __p->~_Tp(); }
205 template<
typename _Up>
206 friend _GLIBCXX20_CONSTEXPR
bool
211#if __cpp_impl_three_way_comparison < 201907L
212 template<
typename _Up>
213 friend _GLIBCXX20_CONSTEXPR
bool
220 _GLIBCXX_CONSTEXPR size_type
221 _M_max_size()
const _GLIBCXX_USE_NOEXCEPT
223#if __PTRDIFF_MAX__ < __SIZE_MAX__
224 return std::size_t(__PTRDIFF_MAX__) /
sizeof(_Tp);
226 return std::size_t(-1) /
sizeof(_Tp);
231_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].