42 #ifndef _DEBUG_ALLOCATOR_H
43 #define _DEBUG_ALLOCATOR_H 1
49 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
51 _GLIBCXX_BEGIN_NAMESPACE_VERSION
59 template<
typename _Alloc>
67 typedef typename _Traits::size_type size_type;
68 typedef typename _Traits::difference_type difference_type;
69 typedef typename _Traits::pointer pointer;
70 typedef typename _Traits::const_pointer const_pointer;
71 typedef typename _Traits::reference reference;
72 typedef typename _Traits::const_reference const_reference;
73 typedef typename _Traits::value_type value_type;
75 template<
typename _Up>
91 template<
typename _Alloc2,
97 template<
typename _Alloc2>
98 struct __convertible<_Alloc2, _Alloc>
100 typedef void* __type;
105 const std::size_t __obj_size =
sizeof(value_type);
106 return (
sizeof(size_type) + __obj_size - 1) / __obj_size;
112 template<
typename _Alloc2>
114 typename __convertible<_Alloc2>::__type = 0)
115 : _M_extra(_S_extra()), _M_allocator(__a2._M_allocator) { }
118 : _M_extra(_S_extra()), _M_allocator(__a) { }
120 _GLIBCXX_NODISCARD pointer
121 allocate(size_type __n)
123 pointer __res = _M_allocator.allocate(__n + _M_extra);
124 size_type* __ps =
reinterpret_cast<size_type*
>(__res);
126 return __res + _M_extra;
129 _GLIBCXX_NODISCARD pointer
130 allocate(size_type __n,
const void* __hint)
132 pointer __res = _M_allocator.allocate(__n + _M_extra, __hint);
133 size_type* __ps =
reinterpret_cast<size_type*
>(__res);
135 return __res + _M_extra;
139 deallocate(pointer __p, size_type __n)
141 using std::__throw_runtime_error;
144 pointer __real_p = __p - _M_extra;
145 if (*
reinterpret_cast<size_type*
>(__real_p) != __n)
146 __throw_runtime_error(
"debug_allocator::deallocate wrong size");
147 _M_allocator.deallocate(__real_p, __n + _M_extra);
150 __throw_runtime_error(
"debug_allocator::deallocate null pointer");
154 construct(pointer __p,
const value_type& __val)
155 { _Traits::construct(_M_allocator, __p, __val); }
157 #if __cplusplus >= 201103L
158 template<
typename _Tp,
typename... _Args>
160 construct(_Tp* __p, _Args&&... __args)
162 _Traits::construct(_M_allocator, __p,
163 std::forward<_Args>(__args)...);
167 template<
typename _Tp>
170 { _Traits::destroy(_M_allocator, __p); }
173 max_size()
const throw()
176 template<
typename _Alloc2>
182 #if __cpp_impl_three_way_comparison < 201907L
183 template<
typename _Alloc2>
187 {
return !(__lhs == __rhs); }
191 _GLIBCXX_END_NAMESPACE_VERSION
GNU extensions for public use.
Uniform interface to C++98 and C++11 allocators.
static constexpr size_type max_size(const _Alloc &__a) noexcept
The maximum supported allocation size.
A meta-allocator with debugging bits.