42#ifndef _DEBUG_ALLOCATOR_H
43#define _DEBUG_ALLOCATOR_H 1
51namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
53_GLIBCXX_BEGIN_NAMESPACE_VERSION
61 template<
typename _Alloc>
69 typedef typename _Traits::size_type size_type;
70 typedef typename _Traits::difference_type difference_type;
71 typedef typename _Traits::pointer pointer;
72 typedef typename _Traits::const_pointer const_pointer;
73 typedef typename _Traits::reference reference;
74 typedef typename _Traits::const_reference const_reference;
75 typedef typename _Traits::value_type value_type;
77 template<
typename _Up>
93 template<
typename _Alloc2,
99 template<
typename _Alloc2>
100 struct __convertible<_Alloc2, _Alloc>
102 typedef void* __type;
107 const std::size_t __obj_size =
sizeof(value_type);
108 return (
sizeof(size_type) + __obj_size - 1) / __obj_size;
114 template<
typename _Alloc2>
116 typename __convertible<_Alloc2>::__type = 0)
117 : _M_extra(_S_extra()), _M_allocator(__a2._M_allocator) { }
120 : _M_extra(_S_extra()), _M_allocator(__a) { }
122 _GLIBCXX_NODISCARD pointer
123 allocate(size_type __n)
125 pointer __res = _M_allocator.allocate(__n + _M_extra);
126 size_type* __ps =
reinterpret_cast<size_type*
>(__res);
128 return __res + _M_extra;
131 _GLIBCXX_NODISCARD pointer
132 allocate(size_type __n,
const void* __hint)
134 pointer __res = _M_allocator.allocate(__n + _M_extra, __hint);
135 size_type* __ps =
reinterpret_cast<size_type*
>(__res);
137 return __res + _M_extra;
141 deallocate(pointer __p, size_type __n)
143 using std::__throw_runtime_error;
146 pointer __real_p = __p - _M_extra;
147 if (*
reinterpret_cast<size_type*
>(__real_p) != __n)
148 __throw_runtime_error(
"debug_allocator::deallocate wrong size");
149 _M_allocator.deallocate(__real_p, __n + _M_extra);
152 __throw_runtime_error(
"debug_allocator::deallocate null pointer");
156 construct(pointer __p,
const value_type& __val)
157 { _Traits::construct(_M_allocator, __p, __val); }
159#if __cplusplus >= 201103L
160 template<
typename _Tp,
typename... _Args>
162 construct(_Tp* __p, _Args&&... __args)
164 _Traits::construct(_M_allocator, __p,
165 std::forward<_Args>(__args)...);
169 template<
typename _Tp>
172 { _Traits::destroy(_M_allocator, __p); }
175 max_size()
const throw()
178 template<
typename _Alloc2>
184#if __cpp_impl_three_way_comparison < 201907L
185 template<
typename _Alloc2>
189 {
return !(__lhs == __rhs); }
193_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.