29 #ifndef _GLIBCXX_DEBUG_VECTOR
30 #define _GLIBCXX_DEBUG_VECTOR 1
46 template<
typename _SafeSequence,
47 typename _BaseSequence>
50 typedef typename _BaseSequence::size_type size_type;
53 _M_seq()
const {
return *
static_cast<const _SafeSequence*
>(
this); }
57 : _M_guaranteed_capacity(0)
58 { _M_update_guaranteed_capacity(); }
61 : _M_guaranteed_capacity(0)
62 { _M_update_guaranteed_capacity(); }
65 : _M_guaranteed_capacity(__n)
68 #if __cplusplus >= 201103L
71 { __x._M_guaranteed_capacity = 0; }
76 _M_update_guaranteed_capacity();
83 _M_update_guaranteed_capacity();
84 __x._M_guaranteed_capacity = 0;
89 size_type _M_guaranteed_capacity;
92 _M_requires_reallocation(size_type __elements)
const _GLIBCXX_NOEXCEPT
93 {
return __elements > _M_seq().capacity(); }
96 _M_update_guaranteed_capacity() _GLIBCXX_NOEXCEPT
98 if (_M_seq().size() > _M_guaranteed_capacity)
99 _M_guaranteed_capacity = _M_seq().size();
104 namespace std _GLIBCXX_VISIBILITY(default)
109 template<
typename _Tp,
113 vector<_Tp, _Allocator>, _Allocator, __gnu_debug::_Safe_sequence>,
114 public _GLIBCXX_STD_C::vector<_Tp, _Allocator>,
116 vector<_Tp, _Allocator>,
117 _GLIBCXX_STD_C::vector<_Tp, _Allocator> >
119 typedef _GLIBCXX_STD_C::vector<_Tp, _Allocator>
_Base;
129 typedef typename _Base::reference reference;
130 typedef typename _Base::const_reference const_reference;
137 typedef typename _Base::size_type size_type;
138 typedef typename _Base::difference_type difference_type;
140 typedef _Tp value_type;
141 typedef _Allocator allocator_type;
142 typedef typename _Base::pointer pointer;
143 typedef typename _Base::const_pointer const_pointer;
149 #if __cplusplus < 201103L
150 vector() _GLIBCXX_NOEXCEPT
157 vector(
const _Allocator& __a) _GLIBCXX_NOEXCEPT
160 #if __cplusplus >= 201103L
162 vector(size_type __n,
const _Allocator& __a = _Allocator())
163 : _Base(__n, __a), _Safe_vector(__n) { }
165 vector(size_type __n,
const _Tp& __value,
166 const _Allocator& __a = _Allocator())
167 : _Base(__n, __value, __a) { }
170 vector(size_type __n,
const _Tp& __value = _Tp(),
171 const _Allocator& __a = _Allocator())
172 : _Base(__n, __value, __a) { }
175 #if __cplusplus >= 201103L
176 template<
class _InputIterator,
177 typename = std::_RequireInputIter<_InputIterator>>
179 template<
class _InputIterator>
181 vector(_InputIterator __first, _InputIterator __last,
182 const _Allocator& __a = _Allocator())
187 #if __cplusplus < 201103L
188 vector(
const vector& __x)
191 ~vector() _GLIBCXX_NOEXCEPT { }
193 vector(
const vector&) =
default;
194 vector(vector&&) =
default;
196 vector(
const vector& __x,
const allocator_type& __a)
197 : _Base(__x, __a) { }
199 vector(vector&& __x,
const allocator_type& __a)
200 : _Safe(std::move(__x._M_safe()), __a),
201 _Base(std::move(__x._M_base()), __a),
202 _Safe_vector(std::move(__x)) { }
205 const allocator_type& __a = allocator_type())
206 : _Base(__l, __a) { }
215 #if __cplusplus < 201103L
217 operator=(
const vector& __x)
219 this->_M_safe() = __x;
221 this->_M_update_guaranteed_capacity();
226 operator=(
const vector&) =
default;
229 operator=(vector&&) =
default;
236 this->_M_update_guaranteed_capacity();
241 #if __cplusplus >= 201103L
242 template<
typename _InputIterator,
243 typename = std::_RequireInputIter<_InputIterator>>
245 template<
typename _InputIterator>
248 assign(_InputIterator __first, _InputIterator __last)
250 __glibcxx_check_valid_range(__first, __last);
254 this->_M_update_guaranteed_capacity();
258 assign(size_type __n,
const _Tp& __u)
260 _Base::assign(__n, __u);
262 this->_M_update_guaranteed_capacity();
265 #if __cplusplus >= 201103L
267 assign(initializer_list<value_type> __l)
271 this->_M_update_guaranteed_capacity();
275 using _Base::get_allocator;
279 begin() _GLIBCXX_NOEXCEPT
280 {
return iterator(_Base::begin(),
this); }
283 begin() const _GLIBCXX_NOEXCEPT
284 {
return const_iterator(_Base::begin(),
this); }
287 end() _GLIBCXX_NOEXCEPT
288 {
return iterator(_Base::end(),
this); }
291 end() const _GLIBCXX_NOEXCEPT
292 {
return const_iterator(_Base::end(),
this); }
295 rbegin() _GLIBCXX_NOEXCEPT
296 {
return reverse_iterator(end()); }
298 const_reverse_iterator
299 rbegin() const _GLIBCXX_NOEXCEPT
300 {
return const_reverse_iterator(end()); }
303 rend() _GLIBCXX_NOEXCEPT
304 {
return reverse_iterator(begin()); }
306 const_reverse_iterator
307 rend() const _GLIBCXX_NOEXCEPT
308 {
return const_reverse_iterator(begin()); }
310 #if __cplusplus >= 201103L
312 cbegin() const noexcept
313 {
return const_iterator(_Base::begin(),
this); }
316 cend() const noexcept
317 {
return const_iterator(_Base::end(),
this); }
319 const_reverse_iterator
320 crbegin() const noexcept
321 {
return const_reverse_iterator(end()); }
323 const_reverse_iterator
324 crend() const noexcept
325 {
return const_reverse_iterator(begin()); }
330 using _Base::max_size;
332 #if __cplusplus >= 201103L
334 resize(size_type __sz)
336 bool __realloc = this->_M_requires_reallocation(__sz);
337 if (__sz < this->size())
338 this->_M_invalidate_after_nth(__sz);
342 this->_M_update_guaranteed_capacity();
346 resize(size_type __sz,
const _Tp& __c)
348 bool __realloc = this->_M_requires_reallocation(__sz);
349 if (__sz < this->size())
350 this->_M_invalidate_after_nth(__sz);
351 _Base::resize(__sz, __c);
354 this->_M_update_guaranteed_capacity();
358 resize(size_type __sz, _Tp __c = _Tp())
360 bool __realloc = this->_M_requires_reallocation(__sz);
361 if (__sz < this->size())
362 this->_M_invalidate_after_nth(__sz);
363 _Base::resize(__sz, __c);
366 this->_M_update_guaranteed_capacity();
370 #if __cplusplus >= 201103L
374 if (_Base::_M_shrink_to_fit())
376 this->_M_guaranteed_capacity = _Base::capacity();
383 capacity() const _GLIBCXX_NOEXCEPT
385 #ifdef _GLIBCXX_DEBUG_PEDANTIC
386 return this->_M_guaranteed_capacity;
388 return _Base::capacity();
395 reserve(size_type __n)
397 bool __realloc = this->_M_requires_reallocation(__n);
399 if (__n > this->_M_guaranteed_capacity)
400 this->_M_guaranteed_capacity = __n;
407 operator[](size_type __n) _GLIBCXX_NOEXCEPT
409 __glibcxx_check_subscript(__n);
410 return _M_base()[__n];
414 operator[](size_type __n)
const _GLIBCXX_NOEXCEPT
416 __glibcxx_check_subscript(__n);
417 return _M_base()[__n];
423 front() _GLIBCXX_NOEXCEPT
425 __glibcxx_check_nonempty();
426 return _Base::front();
430 front() const _GLIBCXX_NOEXCEPT
432 __glibcxx_check_nonempty();
433 return _Base::front();
437 back() _GLIBCXX_NOEXCEPT
439 __glibcxx_check_nonempty();
440 return _Base::back();
444 back() const _GLIBCXX_NOEXCEPT
446 __glibcxx_check_nonempty();
447 return _Base::back();
456 push_back(
const _Tp& __x)
458 bool __realloc = this->_M_requires_reallocation(this->size() + 1);
459 _Base::push_back(__x);
462 this->_M_update_guaranteed_capacity();
465 #if __cplusplus >= 201103L
466 template<
typename _Up = _Tp>
467 typename __gnu_cxx::__enable_if<!std::__are_same<_Up, bool>::__value,
470 { emplace_back(std::move(__x)); }
472 template<
typename... _Args>
474 emplace_back(_Args&&... __args)
476 bool __realloc = this->_M_requires_reallocation(this->size() + 1);
477 _Base::emplace_back(std::forward<_Args>(__args)...);
480 this->_M_update_guaranteed_capacity();
485 pop_back() _GLIBCXX_NOEXCEPT
487 __glibcxx_check_nonempty();
492 #if __cplusplus >= 201103L
493 template<
typename... _Args>
495 emplace(const_iterator __position, _Args&&... __args)
498 bool __realloc = this->_M_requires_reallocation(this->size() + 1);
499 difference_type __offset = __position.base() - _Base::begin();
500 _Base_iterator __res = _Base::emplace(__position.base(),
501 std::forward<_Args>(__args)...);
505 this->_M_invalidate_after_nth(__offset);
506 this->_M_update_guaranteed_capacity();
507 return iterator(__res,
this);
512 #if __cplusplus >= 201103L
513 insert(const_iterator __position,
const _Tp& __x)
515 insert(iterator __position,
const _Tp& __x)
519 bool __realloc = this->_M_requires_reallocation(this->size() + 1);
520 difference_type __offset = __position.base() - _Base::begin();
521 _Base_iterator __res = _Base::insert(__position.base(), __x);
525 this->_M_invalidate_after_nth(__offset);
526 this->_M_update_guaranteed_capacity();
527 return iterator(__res,
this);
530 #if __cplusplus >= 201103L
531 template<
typename _Up = _Tp>
532 typename __gnu_cxx::__enable_if<!std::__are_same<_Up, bool>::__value,
534 insert(const_iterator __position, _Tp&& __x)
535 {
return emplace(__position, std::move(__x)); }
538 insert(const_iterator __position, initializer_list<value_type> __l)
539 {
return this->insert(__position, __l.begin(), __l.end()); }
542 #if __cplusplus >= 201103L
544 insert(const_iterator __position, size_type __n,
const _Tp& __x)
547 bool __realloc = this->_M_requires_reallocation(this->size() + __n);
548 difference_type __offset = __position.base() - _Base::cbegin();
549 _Base_iterator __res = _Base::insert(__position.base(), __n, __x);
553 this->_M_invalidate_after_nth(__offset);
554 this->_M_update_guaranteed_capacity();
555 return iterator(__res,
this);
559 insert(iterator __position, size_type __n,
const _Tp& __x)
562 bool __realloc = this->_M_requires_reallocation(this->size() + __n);
563 difference_type __offset = __position.base() - _Base::begin();
564 _Base::insert(__position.base(), __n, __x);
568 this->_M_invalidate_after_nth(__offset);
569 this->_M_update_guaranteed_capacity();
573 #if __cplusplus >= 201103L
574 template<
class _InputIterator,
575 typename = std::_RequireInputIter<_InputIterator>>
577 insert(const_iterator __position,
578 _InputIterator __first, _InputIterator __last)
585 _Base_iterator __old_begin = _M_base().begin();
586 difference_type __offset = __position.
base() - _Base::cbegin();
587 _Base_iterator __res = _Base::insert(__position.base(),
591 if (_M_base().begin() != __old_begin)
594 this->_M_invalidate_after_nth(__offset);
595 this->_M_update_guaranteed_capacity();
596 return iterator(__res,
this);
599 template<
class _InputIterator>
601 insert(iterator __position,
602 _InputIterator __first, _InputIterator __last)
609 _Base_iterator __old_begin = _M_base().begin();
610 difference_type __offset = __position.
base() - _Base::begin();
614 if (_M_base().begin() != __old_begin)
617 this->_M_invalidate_after_nth(__offset);
618 this->_M_update_guaranteed_capacity();
623 #if __cplusplus >= 201103L
624 erase(const_iterator __position)
626 erase(iterator __position)
630 difference_type __offset = __position.base() - _Base::begin();
631 _Base_iterator __res = _Base::erase(__position.base());
632 this->_M_invalidate_after_nth(__offset);
633 return iterator(__res,
this);
637 #if __cplusplus >= 201103L
638 erase(const_iterator __first, const_iterator __last)
640 erase(iterator __first, iterator __last)
647 if (__first.base() != __last.base())
649 difference_type __offset = __first.base() - _Base::begin();
650 _Base_iterator __res = _Base::erase(__first.base(),
652 this->_M_invalidate_after_nth(__offset);
653 return iterator(__res,
this);
656 #if __cplusplus >= 201103L
657 return begin() + (__first.base() - cbegin().
base());
665 #if __cplusplus >= 201103L
666 noexcept( noexcept(declval<_Base>().swap(__x)) )
671 std::swap(this->_M_guaranteed_capacity, __x._M_guaranteed_capacity);
675 clear() _GLIBCXX_NOEXCEPT
682 _M_base() _GLIBCXX_NOEXCEPT {
return *
this; }
685 _M_base() const _GLIBCXX_NOEXCEPT {
return *
this; }
689 _M_invalidate_after_nth(difference_type __n) _GLIBCXX_NOEXCEPT
696 template<
typename _Tp,
typename _Alloc>
698 operator==(
const vector<_Tp, _Alloc>& __lhs,
699 const vector<_Tp, _Alloc>& __rhs)
700 {
return __lhs._M_base() == __rhs._M_base(); }
702 template<
typename _Tp,
typename _Alloc>
704 operator!=(
const vector<_Tp, _Alloc>& __lhs,
705 const vector<_Tp, _Alloc>& __rhs)
706 {
return __lhs._M_base() != __rhs._M_base(); }
708 template<
typename _Tp,
typename _Alloc>
710 operator<(const vector<_Tp, _Alloc>& __lhs,
711 const vector<_Tp, _Alloc>& __rhs)
712 {
return __lhs._M_base() < __rhs._M_base(); }
714 template<
typename _Tp,
typename _Alloc>
716 operator<=(const vector<_Tp, _Alloc>& __lhs,
717 const vector<_Tp, _Alloc>& __rhs)
718 {
return __lhs._M_base() <= __rhs._M_base(); }
720 template<
typename _Tp,
typename _Alloc>
722 operator>=(
const vector<_Tp, _Alloc>& __lhs,
723 const vector<_Tp, _Alloc>& __rhs)
724 {
return __lhs._M_base() >= __rhs._M_base(); }
726 template<
typename _Tp,
typename _Alloc>
728 operator>(
const vector<_Tp, _Alloc>& __lhs,
729 const vector<_Tp, _Alloc>& __rhs)
730 {
return __lhs._M_base() > __rhs._M_base(); }
732 template<
typename _Tp,
typename _Alloc>
734 swap(vector<_Tp, _Alloc>& __lhs, vector<_Tp, _Alloc>& __rhs)
735 { __lhs.swap(__rhs); }
739 #if __cplusplus >= 201103L
742 template<
typename _Alloc>
743 struct hash<__debug::vector<bool, _Alloc>>
744 :
public __hash_base<size_t, __debug::vector<bool, _Alloc>>
757 template<
typename _Tp,
typename _Alloc>
758 struct _Is_contiguous_sequence<
std::__debug::vector<_Tp, _Alloc> >
762 template<
typename _Alloc>
763 struct _Is_contiguous_sequence<
std::__debug::vector<bool, _Alloc> >
Base class for constructing a safe sequence type that tracks iterators that reference it...
Class std::vector with safety/checking/debug instrumentation.
_Siter_base< _Iterator >::iterator_type __base(_Iterator __it)
Primary class template hash.
vector(const _Base &__x)
Construction from a normal-mode vector.
_Iterator & base() noexcept
Return the underlying iterator.
#define __glibcxx_check_erase(_Position)
void _M_invalidate_if(_Predicate __pred)
#define __glibcxx_check_erase_range(_First, _Last)
ISO C++ entities toplevel namespace is std.
void _M_invalidate_all() const
#define __glibcxx_check_insert(_Position)
#define __glibcxx_check_insert_range(_Position, _First, _Last)
Safe class dealing with some allocator dependent operations.
GNU debug classes for public use.
The standard allocator, as per [20.4].
Base class for Debug Mode vector.