29 #ifndef _NEW_ALLOCATOR_H
30 #define _NEW_ALLOCATOR_H 1
36 #if __cplusplus >= 201103L
40 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
42 _GLIBCXX_BEGIN_NAMESPACE_VERSION
54 template<
typename _Tp>
58 typedef _Tp value_type;
59 typedef std::size_t size_type;
60 typedef std::ptrdiff_t difference_type;
61 #if __cplusplus <= 201703L
63 typedef const _Tp* const_pointer;
64 typedef _Tp& reference;
65 typedef const _Tp& const_reference;
67 template<
typename _Tp1>
72 #if __cplusplus >= 201103L
84 template<
typename _Tp1>
88 #if __cplusplus <= 201703L
92 address(reference __x)
const _GLIBCXX_NOEXCEPT
96 address(const_reference __x)
const _GLIBCXX_NOEXCEPT
100 #if __has_builtin(__builtin_operator_new) >= 201802L
101 # define _GLIBCXX_OPERATOR_NEW __builtin_operator_new
102 # define _GLIBCXX_OPERATOR_DELETE __builtin_operator_delete
104 # define _GLIBCXX_OPERATOR_NEW ::operator new
105 # define _GLIBCXX_OPERATOR_DELETE ::operator delete
110 _GLIBCXX_NODISCARD _Tp*
111 allocate(size_type __n,
const void* =
static_cast<const void*
>(0))
113 #if __cplusplus >= 201103L
116 static_assert(
sizeof(_Tp) != 0,
"cannot allocate incomplete types");
119 if (__builtin_expect(__n > this->_M_max_size(),
false))
123 if (__n > (std::size_t(-1) /
sizeof(_Tp)))
124 std::__throw_bad_array_new_length();
125 std::__throw_bad_alloc();
128 #if __cpp_aligned_new
129 if (
alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
131 std::align_val_t __al = std::align_val_t(
alignof(_Tp));
132 return static_cast<_Tp*
>(_GLIBCXX_OPERATOR_NEW(__n *
sizeof(_Tp),
136 return static_cast<_Tp*
>(_GLIBCXX_OPERATOR_NEW(__n *
sizeof(_Tp)));
141 deallocate(_Tp* __p, size_type __n __attribute__ ((__unused__)))
143 #if __cpp_sized_deallocation
144 # define _GLIBCXX_SIZED_DEALLOC(p, n) (p), (n) * sizeof(_Tp)
146 # define _GLIBCXX_SIZED_DEALLOC(p, n) (p)
149 #if __cpp_aligned_new
150 if (
alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
152 _GLIBCXX_OPERATOR_DELETE(_GLIBCXX_SIZED_DEALLOC(__p, __n),
153 std::align_val_t(
alignof(_Tp)));
157 _GLIBCXX_OPERATOR_DELETE(_GLIBCXX_SIZED_DEALLOC(__p, __n));
160 #undef _GLIBCXX_SIZED_DEALLOC
161 #undef _GLIBCXX_OPERATOR_DELETE
162 #undef _GLIBCXX_OPERATOR_NEW
164 #if __cplusplus <= 201703L
166 max_size()
const _GLIBCXX_USE_NOEXCEPT
167 {
return _M_max_size(); }
169 #if __cplusplus >= 201103L
170 template<
typename _Up,
typename... _Args>
172 construct(_Up* __p, _Args&&... __args)
174 { ::new((
void *)__p) _Up(std::forward<_Args>(__args)...); }
176 template<
typename _Up>
185 construct(pointer __p,
const _Tp& __val)
186 { ::new((
void *)__p) _Tp(__val); }
189 destroy(pointer __p) { __p->~_Tp(); }
193 template<
typename _Up>
194 friend _GLIBCXX20_CONSTEXPR
bool
199 #if __cpp_impl_three_way_comparison < 201907L
200 template<
typename _Up>
201 friend _GLIBCXX20_CONSTEXPR
bool
208 _GLIBCXX_CONSTEXPR size_type
209 _M_max_size()
const _GLIBCXX_USE_NOEXCEPT
211 #if __PTRDIFF_MAX__ < __SIZE_MAX__
212 return std::size_t(__PTRDIFF_MAX__) /
sizeof(_Tp);
214 return std::size_t(-1) /
sizeof(_Tp);
219 _GLIBCXX_END_NAMESPACE_VERSION
constexpr _Tp * __addressof(_Tp &__r) noexcept
Same as C++11 std::addressof.
GNU extensions for public use.
An allocator that uses global new, as per C++03 [20.4.1].