30 #ifndef _GLIBCXX_DEBUG_VECTOR
31 #define _GLIBCXX_DEBUG_VECTOR 1
42 template<
typename _Tp,
45 :
public _GLIBCXX_STD_D::vector<_Tp, _Allocator>,
48 typedef _GLIBCXX_STD_D::vector<_Tp, _Allocator> _Base;
51 typedef typename _Base::const_iterator _Base_const_iterator;
55 typedef typename _Base::reference reference;
56 typedef typename _Base::const_reference const_reference;
63 typedef typename _Base::size_type size_type;
64 typedef typename _Base::difference_type difference_type;
66 typedef _Tp value_type;
67 typedef _Allocator allocator_type;
68 typedef typename _Base::pointer pointer;
69 typedef typename _Base::const_pointer const_pointer;
74 explicit vector(
const _Allocator& __a = _Allocator())
75 : _Base(__a), _M_guaranteed_capacity(0) { }
77 explicit vector(size_type __n,
const _Tp& __value = _Tp(),
78 const _Allocator& __a = _Allocator())
79 : _Base(__n, __value, __a), _M_guaranteed_capacity(__n) { }
81 template<
class _InputIterator>
82 vector(_InputIterator __first, _InputIterator __last,
83 const _Allocator& __a = _Allocator())
84 : _Base(__gnu_debug::__check_valid_range(__first, __last),
86 _M_guaranteed_capacity(0)
87 { _M_update_guaranteed_capacity(); }
89 vector(
const vector& __x)
90 : _Base(__x), _Safe_base(), _M_guaranteed_capacity(__x.size()) { }
93 vector(
const _Base& __x)
94 : _Base(__x), _Safe_base(), _M_guaranteed_capacity(__x.size()) { }
96 #ifdef __GXX_EXPERIMENTAL_CXX0X__
98 : _Base(std::forward<vector>(__x)), _Safe_base(),
99 _M_guaranteed_capacity(this->size())
102 __x._M_guaranteed_capacity = 0;
105 vector(initializer_list<value_type> __l,
106 const allocator_type& __a = allocator_type())
107 : _Base(__l, __a), _Safe_base(),
108 _M_guaranteed_capacity(__l.size()) { }
114 operator=(
const vector& __x)
116 static_cast<_Base&
>(*this) = __x;
118 _M_update_guaranteed_capacity();
122 #ifdef __GXX_EXPERIMENTAL_CXX0X__
124 operator=(vector&& __x)
133 operator=(initializer_list<value_type> __l)
135 static_cast<_Base&
>(*this) = __l;
137 _M_update_guaranteed_capacity();
142 template<
typename _InputIterator>
144 assign(_InputIterator __first, _InputIterator __last)
146 __glibcxx_check_valid_range(__first, __last);
147 _Base::assign(__first, __last);
149 _M_update_guaranteed_capacity();
153 assign(size_type __n,
const _Tp& __u)
155 _Base::assign(__n, __u);
157 _M_update_guaranteed_capacity();
160 #ifdef __GXX_EXPERIMENTAL_CXX0X__
162 assign(initializer_list<value_type> __l)
166 _M_update_guaranteed_capacity();
170 using _Base::get_allocator;
175 {
return iterator(_Base::begin(),
this); }
179 {
return const_iterator(_Base::begin(),
this); }
183 {
return iterator(_Base::end(),
this); }
187 {
return const_iterator(_Base::end(),
this); }
191 {
return reverse_iterator(end()); }
193 const_reverse_iterator
195 {
return const_reverse_iterator(end()); }
199 {
return reverse_iterator(begin()); }
201 const_reverse_iterator
203 {
return const_reverse_iterator(begin()); }
205 #ifdef __GXX_EXPERIMENTAL_CXX0X__
208 {
return const_iterator(_Base::begin(),
this); }
212 {
return const_iterator(_Base::end(),
this); }
214 const_reverse_iterator
216 {
return const_reverse_iterator(end()); }
218 const_reverse_iterator
220 {
return const_reverse_iterator(begin()); }
225 using _Base::max_size;
228 resize(size_type __sz, _Tp __c = _Tp())
230 bool __realloc = _M_requires_reallocation(__sz);
231 if (__sz < this->size())
233 _Base::resize(__sz, __c);
241 #ifdef _GLIBCXX_DEBUG_PEDANTIC
242 return _M_guaranteed_capacity;
244 return _Base::capacity();
251 reserve(size_type __n)
253 bool __realloc = _M_requires_reallocation(__n);
255 if (__n > _M_guaranteed_capacity)
256 _M_guaranteed_capacity = __n;
263 operator[](size_type __n)
265 __glibcxx_check_subscript(__n);
266 return _M_base()[__n];
270 operator[](size_type __n)
const
272 __glibcxx_check_subscript(__n);
273 return _M_base()[__n];
281 __glibcxx_check_nonempty();
282 return _Base::front();
288 __glibcxx_check_nonempty();
289 return _Base::front();
295 __glibcxx_check_nonempty();
296 return _Base::back();
302 __glibcxx_check_nonempty();
303 return _Base::back();
312 push_back(
const _Tp& __x)
314 bool __realloc = _M_requires_reallocation(this->size() + 1);
315 _Base::push_back(__x);
318 _M_update_guaranteed_capacity();
321 #ifdef __GXX_EXPERIMENTAL_CXX0X__
322 template<
typename _Up = _Tp>
323 typename __gnu_cxx::__enable_if<!std::__are_same<_Up, bool>::__value,
326 { emplace_back(std::move(__x)); }
328 template<
typename... _Args>
330 emplace_back(_Args&&... __args)
332 bool __realloc = _M_requires_reallocation(this->size() + 1);
333 _Base::emplace_back(std::forward<_Args>(__args)...);
336 _M_update_guaranteed_capacity();
343 __glibcxx_check_nonempty();
344 iterator __victim = end() - 1;
345 __victim._M_invalidate();
349 #ifdef __GXX_EXPERIMENTAL_CXX0X__
350 template<
typename... _Args>
352 emplace(iterator __position, _Args&&... __args)
355 bool __realloc = _M_requires_reallocation(this->size() + 1);
356 difference_type __offset = __position - begin();
357 typename _Base::iterator __res = _Base::emplace(__position.base(),
358 std::forward<_Args>(__args)...);
363 _M_update_guaranteed_capacity();
364 return iterator(__res,
this);
369 insert(iterator __position,
const _Tp& __x)
372 bool __realloc = _M_requires_reallocation(this->size() + 1);
373 difference_type __offset = __position - begin();
374 typename _Base::iterator __res = _Base::insert(__position.base(),__x);
379 _M_update_guaranteed_capacity();
380 return iterator(__res,
this);
383 #ifdef __GXX_EXPERIMENTAL_CXX0X__
384 template<
typename _Up = _Tp>
385 typename __gnu_cxx::__enable_if<!std::__are_same<_Up, bool>::__value,
387 insert(iterator __position, _Tp&& __x)
388 {
return emplace(__position, std::move(__x)); }
391 insert(iterator __position, initializer_list<value_type> __l)
392 { this->insert(__position, __l.begin(), __l.end()); }
396 insert(iterator __position, size_type __n,
const _Tp& __x)
399 bool __realloc = _M_requires_reallocation(this->size() + __n);
400 difference_type __offset = __position - begin();
401 _Base::insert(__position.base(), __n, __x);
406 _M_update_guaranteed_capacity();
409 template<
class _InputIterator>
411 insert(iterator __position,
412 _InputIterator __first, _InputIterator __last)
419 typename _Base::iterator __old_begin = _M_base().begin();
420 difference_type __offset = __position - begin();
421 _Base::insert(__position.base(), __first, __last);
423 if (_M_base().begin() != __old_begin)
427 _M_update_guaranteed_capacity();
431 erase(iterator __position)
434 difference_type __offset = __position - begin();
435 typename _Base::iterator __res = _Base::erase(__position.base());
437 return iterator(__res,
this);
441 erase(iterator __first, iterator __last)
447 difference_type __offset = __first - begin();
448 typename _Base::iterator __res = _Base::erase(__first.base(),
451 return iterator(__res,
this);
455 #ifdef __GXX_EXPERIMENTAL_CXX0X__
463 std::swap(_M_guaranteed_capacity, __x._M_guaranteed_capacity);
471 _M_guaranteed_capacity = 0;
475 _M_base() {
return *
this; }
478 _M_base()
const {
return *
this; }
481 size_type _M_guaranteed_capacity;
484 _M_requires_reallocation(size_type __elements)
485 {
return __elements > this->capacity(); }
488 _M_update_guaranteed_capacity()
490 if (this->size() > _M_guaranteed_capacity)
491 _M_guaranteed_capacity = this->size();
495 template<
typename _Tp,
typename _Alloc>
497 operator==(
const vector<_Tp, _Alloc>& __lhs,
498 const vector<_Tp, _Alloc>& __rhs)
499 {
return __lhs._M_base() == __rhs._M_base(); }
501 template<
typename _Tp,
typename _Alloc>
503 operator!=(
const vector<_Tp, _Alloc>& __lhs,
504 const vector<_Tp, _Alloc>& __rhs)
505 {
return __lhs._M_base() != __rhs._M_base(); }
507 template<
typename _Tp,
typename _Alloc>
509 operator<(const vector<_Tp, _Alloc>& __lhs,
510 const vector<_Tp, _Alloc>& __rhs)
511 {
return __lhs._M_base() < __rhs._M_base(); }
513 template<
typename _Tp,
typename _Alloc>
515 operator<=(const vector<_Tp, _Alloc>& __lhs,
516 const vector<_Tp, _Alloc>& __rhs)
517 {
return __lhs._M_base() <= __rhs._M_base(); }
519 template<
typename _Tp,
typename _Alloc>
521 operator>=(
const vector<_Tp, _Alloc>& __lhs,
522 const vector<_Tp, _Alloc>& __rhs)
523 {
return __lhs._M_base() >= __rhs._M_base(); }
525 template<
typename _Tp,
typename _Alloc>
527 operator>(
const vector<_Tp, _Alloc>& __lhs,
528 const vector<_Tp, _Alloc>& __rhs)
529 {
return __lhs._M_base() > __rhs._M_base(); }
531 template<
typename _Tp,
typename _Alloc>
533 swap(vector<_Tp, _Alloc>& __lhs, vector<_Tp, _Alloc>& __rhs)
534 { __lhs.swap(__rhs); }
536 #ifdef __GXX_EXPERIMENTAL_CXX0X__
537 template<
typename _Tp,
typename _Alloc>
539 swap(vector<_Tp, _Alloc>&& __lhs, vector<_Tp, _Alloc>& __rhs)
540 { __lhs.swap(__rhs); }
542 template<
typename _Tp,
typename _Alloc>
544 swap(vector<_Tp, _Alloc>& __lhs, vector<_Tp, _Alloc>&& __rhs)
545 { __lhs.swap(__rhs); }
void _M_invalidate_if(_Predicate __pred)
#define __glibcxx_check_insert_range(_Position, _First, _Last)
#define __glibcxx_check_erase(_Position)
Base class for constructing a "safe" sequence type that tracks iterators that reference it...
The "standard" allocator, as per [20.4].Further details: http://gcc.gnu.org/onlinedocs/libstdc++/manu...
void _M_invalidate_all() const
#define __glibcxx_check_erase_range(_First, _Last)
void _M_swap(_Safe_sequence_base &__x)
#define __glibcxx_check_insert(_Position)