29 #ifndef _GLIBCXX_DEBUG_VECTOR
30 #define _GLIBCXX_DEBUG_VECTOR 1
37 namespace std _GLIBCXX_VISIBILITY(default)
42 template<
typename _Tp,
45 :
public _GLIBCXX_STD_C::vector<_Tp, _Allocator>,
48 typedef _GLIBCXX_STD_C::vector<_Tp, _Allocator>
_Base;
54 #if __cplusplus >= 201103L
60 typedef typename _Base::reference reference;
61 typedef typename _Base::const_reference const_reference;
68 typedef typename _Base::size_type size_type;
69 typedef typename _Base::difference_type difference_type;
71 typedef _Tp value_type;
72 typedef _Allocator allocator_type;
73 typedef typename _Base::pointer pointer;
74 typedef typename _Base::const_pointer const_pointer;
81 :
_Base(), _M_guaranteed_capacity(0) { }
84 vector(
const _Allocator& __a) _GLIBCXX_NOEXCEPT
85 :
_Base(__a), _M_guaranteed_capacity(0) { }
87 #if __cplusplus >= 201103L
89 vector(size_type __n,
const _Allocator& __a = _Allocator())
90 :
_Base(__n, __a), _M_guaranteed_capacity(__n) { }
92 vector(size_type __n,
const _Tp& __value,
93 const _Allocator& __a = _Allocator())
94 :
_Base(__n, __value, __a), _M_guaranteed_capacity(__n) { }
97 vector(size_type __n,
const _Tp& __value = _Tp(),
98 const _Allocator& __a = _Allocator())
99 :
_Base(__n, __value, __a), _M_guaranteed_capacity(__n) { }
102 #if __cplusplus >= 201103L
103 template<
class _InputIterator,
104 typename = std::_RequireInputIter<_InputIterator>>
106 template<
class _InputIterator>
108 vector(_InputIterator __first, _InputIterator __last,
109 const _Allocator& __a = _Allocator())
113 _M_guaranteed_capacity(0)
114 { _M_update_guaranteed_capacity(); }
116 vector(
const vector& __x)
117 :
_Base(__x), _M_guaranteed_capacity(__x.size()) { }
121 :
_Base(__x), _M_guaranteed_capacity(__x.
size()) { }
123 #if __cplusplus >= 201103L
124 vector(vector&& __x) noexcept
125 : _Base(std::move(__x)),
126 _Safe_base(std::move(__x)),
127 _M_guaranteed_capacity(this->
size())
128 { __x._M_guaranteed_capacity = 0; }
130 vector(
const vector& __x,
const allocator_type& __a)
131 : _Base(__x, __a), _M_guaranteed_capacity(__x.
size()) { }
133 vector(vector&& __x,
const allocator_type& __a)
134 : _Base(std::move(__x), __a),
135 _M_guaranteed_capacity(this->
size())
137 if (__x.get_allocator() == __a)
141 __x._M_guaranteed_capacity = 0;
144 vector(initializer_list<value_type> __l,
145 const allocator_type& __a = allocator_type())
147 _M_guaranteed_capacity(__l.
size()) { }
150 ~vector() _GLIBCXX_NOEXCEPT { }
153 operator=(
const vector& __x)
157 _M_update_guaranteed_capacity();
161 #if __cplusplus >= 201103L
163 operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
165 __glibcxx_check_self_move_assign(__x);
166 bool __xfer_memory = _Alloc_traits::_S_propagate_on_move_assign()
167 || __x.get_allocator() == this->get_allocator();
168 _M_base() = std::move(__x._M_base());
173 _M_update_guaranteed_capacity();
175 __x._M_guaranteed_capacity = 0;
180 operator=(initializer_list<value_type> __l)
184 _M_update_guaranteed_capacity();
189 #if __cplusplus >= 201103L
190 template<
typename _InputIterator,
191 typename = std::_RequireInputIter<_InputIterator>>
193 template<
typename _InputIterator>
196 assign(_InputIterator __first, _InputIterator __last)
198 __glibcxx_check_valid_range(__first, __last);
202 _M_update_guaranteed_capacity();
206 assign(size_type __n,
const _Tp& __u)
208 _Base::assign(__n, __u);
210 _M_update_guaranteed_capacity();
213 #if __cplusplus >= 201103L
215 assign(initializer_list<value_type> __l)
219 _M_update_guaranteed_capacity();
223 using _Base::get_allocator;
227 begin() _GLIBCXX_NOEXCEPT
228 {
return iterator(_Base::begin(),
this); }
231 begin() const _GLIBCXX_NOEXCEPT
232 {
return const_iterator(_Base::begin(),
this); }
235 end() _GLIBCXX_NOEXCEPT
236 {
return iterator(_Base::end(),
this); }
239 end() const _GLIBCXX_NOEXCEPT
240 {
return const_iterator(_Base::end(),
this); }
243 rbegin() _GLIBCXX_NOEXCEPT
244 {
return reverse_iterator(end()); }
246 const_reverse_iterator
247 rbegin() const _GLIBCXX_NOEXCEPT
248 {
return const_reverse_iterator(end()); }
251 rend() _GLIBCXX_NOEXCEPT
252 {
return reverse_iterator(begin()); }
254 const_reverse_iterator
255 rend() const _GLIBCXX_NOEXCEPT
256 {
return const_reverse_iterator(begin()); }
258 #if __cplusplus >= 201103L
260 cbegin() const noexcept
261 {
return const_iterator(_Base::begin(),
this); }
264 cend() const noexcept
265 {
return const_iterator(_Base::end(),
this); }
267 const_reverse_iterator
268 crbegin() const noexcept
269 {
return const_reverse_iterator(end()); }
271 const_reverse_iterator
272 crend() const noexcept
273 {
return const_reverse_iterator(begin()); }
278 using _Base::max_size;
280 #if __cplusplus >= 201103L
282 resize(size_type __sz)
284 bool __realloc = _M_requires_reallocation(__sz);
285 if (__sz < this->
size())
286 this->_M_invalidate_after_nth(__sz);
290 _M_update_guaranteed_capacity();
294 resize(size_type __sz,
const _Tp& __c)
296 bool __realloc = _M_requires_reallocation(__sz);
297 if (__sz < this->
size())
298 this->_M_invalidate_after_nth(__sz);
299 _Base::resize(__sz, __c);
302 _M_update_guaranteed_capacity();
306 resize(size_type __sz, _Tp __c = _Tp())
308 bool __realloc = _M_requires_reallocation(__sz);
309 if (__sz < this->
size())
310 this->_M_invalidate_after_nth(__sz);
311 _Base::resize(__sz, __c);
314 _M_update_guaranteed_capacity();
318 #if __cplusplus >= 201103L
322 if (_Base::_M_shrink_to_fit())
324 _M_guaranteed_capacity = _Base::capacity();
331 capacity() const _GLIBCXX_NOEXCEPT
333 #ifdef _GLIBCXX_DEBUG_PEDANTIC
334 return _M_guaranteed_capacity;
336 return _Base::capacity();
343 reserve(size_type __n)
345 bool __realloc = _M_requires_reallocation(__n);
347 if (__n > _M_guaranteed_capacity)
348 _M_guaranteed_capacity = __n;
355 operator[](size_type __n) _GLIBCXX_NOEXCEPT
357 __glibcxx_check_subscript(__n);
358 return _M_base()[__n];
362 operator[](size_type __n)
const _GLIBCXX_NOEXCEPT
364 __glibcxx_check_subscript(__n);
365 return _M_base()[__n];
371 front() _GLIBCXX_NOEXCEPT
373 __glibcxx_check_nonempty();
374 return _Base::front();
378 front() const _GLIBCXX_NOEXCEPT
380 __glibcxx_check_nonempty();
381 return _Base::front();
385 back() _GLIBCXX_NOEXCEPT
387 __glibcxx_check_nonempty();
388 return _Base::back();
392 back() const _GLIBCXX_NOEXCEPT
394 __glibcxx_check_nonempty();
395 return _Base::back();
404 push_back(
const _Tp& __x)
406 bool __realloc = _M_requires_reallocation(this->
size() + 1);
407 _Base::push_back(__x);
410 _M_update_guaranteed_capacity();
413 #if __cplusplus >= 201103L
414 template<
typename _Up = _Tp>
415 typename __gnu_cxx::__enable_if<!std::__are_same<_Up, bool>::__value,
418 { emplace_back(std::move(__x)); }
420 template<
typename... _Args>
422 emplace_back(_Args&&... __args)
424 bool __realloc = _M_requires_reallocation(this->
size() + 1);
425 _Base::emplace_back(std::forward<_Args>(__args)...);
428 _M_update_guaranteed_capacity();
433 pop_back() _GLIBCXX_NOEXCEPT
435 __glibcxx_check_nonempty();
440 #if __cplusplus >= 201103L
441 template<
typename... _Args>
443 emplace(const_iterator __position, _Args&&... __args)
446 bool __realloc = _M_requires_reallocation(this->
size() + 1);
447 difference_type __offset = __position.base() - _Base::begin();
448 _Base_iterator __res = _Base::emplace(__position.base(),
449 std::forward<_Args>(__args)...);
453 this->_M_invalidate_after_nth(__offset);
454 _M_update_guaranteed_capacity();
455 return iterator(__res,
this);
460 #if __cplusplus >= 201103L
461 insert(const_iterator __position,
const _Tp& __x)
463 insert(iterator __position,
const _Tp& __x)
467 bool __realloc = _M_requires_reallocation(this->
size() + 1);
468 difference_type __offset = __position.base() - _Base::begin();
469 _Base_iterator __res = _Base::insert(__position.base(), __x);
473 this->_M_invalidate_after_nth(__offset);
474 _M_update_guaranteed_capacity();
475 return iterator(__res,
this);
478 #if __cplusplus >= 201103L
479 template<
typename _Up = _Tp>
480 typename __gnu_cxx::__enable_if<!std::__are_same<_Up, bool>::__value,
482 insert(const_iterator __position, _Tp&& __x)
483 {
return emplace(__position, std::move(__x)); }
486 insert(const_iterator __position, initializer_list<value_type> __l)
487 {
return this->insert(__position, __l.begin(), __l.end()); }
490 #if __cplusplus >= 201103L
492 insert(const_iterator __position, size_type __n,
const _Tp& __x)
495 bool __realloc = _M_requires_reallocation(this->
size() + __n);
496 difference_type __offset = __position.base() - _Base::cbegin();
497 _Base_iterator __res = _Base::insert(__position.base(), __n, __x);
501 this->_M_invalidate_after_nth(__offset);
502 _M_update_guaranteed_capacity();
503 return iterator(__res,
this);
507 insert(iterator __position, size_type __n,
const _Tp& __x)
510 bool __realloc = _M_requires_reallocation(this->
size() + __n);
511 difference_type __offset = __position.base() - _Base::begin();
512 _Base::insert(__position.base(), __n, __x);
516 this->_M_invalidate_after_nth(__offset);
517 _M_update_guaranteed_capacity();
521 #if __cplusplus >= 201103L
522 template<
class _InputIterator,
523 typename = std::_RequireInputIter<_InputIterator>>
525 insert(const_iterator __position,
526 _InputIterator __first, _InputIterator __last)
533 _Base_iterator __old_begin = _M_base().begin();
534 difference_type __offset = __position.base() - _Base::cbegin();
535 _Base_iterator __res = _Base::insert(__position.base(),
539 if (_M_base().begin() != __old_begin)
542 this->_M_invalidate_after_nth(__offset);
543 _M_update_guaranteed_capacity();
544 return iterator(__res,
this);
547 template<
class _InputIterator>
549 insert(iterator __position,
550 _InputIterator __first, _InputIterator __last)
557 _Base_iterator __old_begin = _M_base().begin();
558 difference_type __offset = __position.base() - _Base::begin();
562 if (_M_base().begin() != __old_begin)
565 this->_M_invalidate_after_nth(__offset);
566 _M_update_guaranteed_capacity();
571 #if __cplusplus >= 201103L
572 erase(const_iterator __position)
574 erase(iterator __position)
578 difference_type __offset = __position.base() - _Base::begin();
579 _Base_iterator __res = _Base::erase(__position.base());
580 this->_M_invalidate_after_nth(__offset);
581 return iterator(__res,
this);
585 #if __cplusplus >= 201103L
586 erase(const_iterator __first, const_iterator __last)
588 erase(iterator __first, iterator __last)
595 if (__first.base() != __last.base())
597 difference_type __offset = __first.base() - _Base::begin();
598 _Base_iterator __res = _Base::erase(__first.base(),
600 this->_M_invalidate_after_nth(__offset);
601 return iterator(__res,
this);
604 #if __cplusplus >= 201103L
605 return begin() + (__first.base() - cbegin().
base());
613 #if __cplusplus >= 201103L
614 noexcept(_Alloc_traits::_S_nothrow_swap())
617 #if __cplusplus >= 201103L
618 if (!_Alloc_traits::_S_propagate_on_swap())
619 __glibcxx_check_equal_allocs(__x);
623 std::swap(_M_guaranteed_capacity, __x._M_guaranteed_capacity);
627 clear() _GLIBCXX_NOEXCEPT
631 _M_guaranteed_capacity = 0;
635 _M_base() _GLIBCXX_NOEXCEPT {
return *
this; }
638 _M_base() const _GLIBCXX_NOEXCEPT {
return *
this; }
641 size_type _M_guaranteed_capacity;
644 _M_requires_reallocation(size_type __elements) _GLIBCXX_NOEXCEPT
645 {
return __elements > this->capacity(); }
648 _M_update_guaranteed_capacity() _GLIBCXX_NOEXCEPT
650 if (this->
size() > _M_guaranteed_capacity)
651 _M_guaranteed_capacity = this->
size();
655 _M_invalidate_after_nth(difference_type __n) _GLIBCXX_NOEXCEPT
662 template<
typename _Tp,
typename _Alloc>
664 operator==(
const vector<_Tp, _Alloc>& __lhs,
665 const vector<_Tp, _Alloc>& __rhs)
666 {
return __lhs._M_base() == __rhs._M_base(); }
668 template<
typename _Tp,
typename _Alloc>
670 operator!=(
const vector<_Tp, _Alloc>& __lhs,
671 const vector<_Tp, _Alloc>& __rhs)
672 {
return __lhs._M_base() != __rhs._M_base(); }
674 template<
typename _Tp,
typename _Alloc>
676 operator<(const vector<_Tp, _Alloc>& __lhs,
677 const vector<_Tp, _Alloc>& __rhs)
678 {
return __lhs._M_base() < __rhs._M_base(); }
680 template<
typename _Tp,
typename _Alloc>
682 operator<=(const vector<_Tp, _Alloc>& __lhs,
683 const vector<_Tp, _Alloc>& __rhs)
684 {
return __lhs._M_base() <= __rhs._M_base(); }
686 template<
typename _Tp,
typename _Alloc>
688 operator>=(
const vector<_Tp, _Alloc>& __lhs,
689 const vector<_Tp, _Alloc>& __rhs)
690 {
return __lhs._M_base() >= __rhs._M_base(); }
692 template<
typename _Tp,
typename _Alloc>
694 operator>(
const vector<_Tp, _Alloc>& __lhs,
695 const vector<_Tp, _Alloc>& __rhs)
696 {
return __lhs._M_base() > __rhs._M_base(); }
698 template<
typename _Tp,
typename _Alloc>
700 swap(vector<_Tp, _Alloc>& __lhs, vector<_Tp, _Alloc>& __rhs)
701 { __lhs.swap(__rhs); }
705 #if __cplusplus >= 201103L
708 template<
typename _Alloc>
709 struct hash<__debug::vector<bool, _Alloc>>
710 :
public __hash_base<size_t, __debug::vector<bool, _Alloc>>
721 namespace __gnu_debug
723 template<
typename _Tp,
typename _Alloc>
724 struct _Is_contiguous_sequence<std::__debug::vector<_Tp, _Alloc> >
728 template<
typename _Alloc>
729 struct _Is_contiguous_sequence<std::__debug::vector<bool, _Alloc> >
constexpr size_t size() const noexcept
Returns the total number of bits.
#define __glibcxx_check_erase(_Position)
Primary class template hash.
void _M_swap(_Safe_sequence_base &__x)
void _M_invalidate_if(_Predicate __pred)
Uniform interface to C++98 and C++0x allocators.
Class std::vector with safety/checking/debug instrumentation.
vector(const _Base &__x)
Construction from a normal-mode vector.
_Siter_base< _Iterator >::iterator_type __base(_Iterator __it)
void _M_invalidate_all() const
The standard allocator, as per [20.4].
_Iterator base() const noexcept
Return the underlying iterator.
#define __glibcxx_check_insert_range(_Position, _First, _Last)
#define __glibcxx_check_erase_range(_First, _Last)
Base class for constructing a safe sequence type that tracks iterators that reference it...
#define __glibcxx_check_insert(_Position)