29 #ifndef _GLIBCXX_DEBUG_VECTOR
30 #define _GLIBCXX_DEBUG_VECTOR 1
32 #pragma GCC system_header
35 namespace std _GLIBCXX_VISIBILITY(default) {
namespace __debug {
36 template<
typename _Tp,
typename _Allocator>
class vector;
53 template<
typename _SafeSequence,
54 typename _BaseSequence>
57 typedef typename _BaseSequence::size_type size_type;
60 _M_seq()
const {
return *
static_cast<const _SafeSequence*
>(
this); }
64 : _M_guaranteed_capacity(0)
65 { _M_update_guaranteed_capacity(); }
68 : _M_guaranteed_capacity(0)
69 { _M_update_guaranteed_capacity(); }
72 : _M_guaranteed_capacity(__n)
75 #if __cplusplus >= 201103L
78 { __x._M_guaranteed_capacity = 0; }
83 _M_update_guaranteed_capacity();
90 _M_update_guaranteed_capacity();
91 __x._M_guaranteed_capacity = 0;
96 size_type _M_guaranteed_capacity;
99 _M_requires_reallocation(size_type __elements)
const _GLIBCXX_NOEXCEPT
100 {
return __elements > _M_seq().capacity(); }
103 _M_update_guaranteed_capacity() _GLIBCXX_NOEXCEPT
105 if (_M_seq().size() > _M_guaranteed_capacity)
106 _M_guaranteed_capacity = _M_seq().size();
111 namespace std _GLIBCXX_VISIBILITY(default)
116 template<
typename _Tp,
120 vector<_Tp, _Allocator>, _Allocator, __gnu_debug::_Safe_sequence>,
121 public _GLIBCXX_STD_C::vector<_Tp, _Allocator>,
123 vector<_Tp, _Allocator>,
124 _GLIBCXX_STD_C::vector<_Tp, _Allocator> >
126 typedef _GLIBCXX_STD_C::vector<_Tp, _Allocator> _Base;
131 typedef typename _Base::iterator _Base_iterator;
132 typedef typename _Base::const_iterator _Base_const_iterator;
135 template<
typename _ItT,
typename _SeqT,
typename _CatT>
136 friend class ::__gnu_debug::_Safe_iterator;
139 typedef typename _Base::reference reference;
140 typedef typename _Base::const_reference const_reference;
143 _Base_iterator, vector> iterator;
145 _Base_const_iterator, vector> const_iterator;
147 typedef typename _Base::size_type size_type;
148 typedef typename _Base::difference_type difference_type;
150 typedef _Tp value_type;
151 typedef _Allocator allocator_type;
152 typedef typename _Base::pointer pointer;
153 typedef typename _Base::const_pointer const_pointer;
159 #if __cplusplus < 201103L
160 vector() _GLIBCXX_NOEXCEPT
167 vector(
const _Allocator& __a) _GLIBCXX_NOEXCEPT
170 #if __cplusplus >= 201103L
172 vector(size_type __n,
const _Allocator& __a = _Allocator())
173 : _Base(__n, __a), _Safe_vector(__n) { }
175 vector(size_type __n,
const _Tp& __value,
176 const _Allocator& __a = _Allocator())
177 : _Base(__n, __value, __a) { }
180 vector(size_type __n,
const _Tp& __value = _Tp(),
181 const _Allocator& __a = _Allocator())
182 : _Base(__n, __value, __a) { }
185 #if __cplusplus >= 201103L
186 template<
class _InputIterator,
187 typename = std::_RequireInputIter<_InputIterator>>
189 template<
class _InputIterator>
191 vector(_InputIterator __first, _InputIterator __last,
192 const _Allocator& __a = _Allocator())
193 : _Base(__gnu_debug::
__base(
194 __glibcxx_check_valid_constructor_range(__first, __last)),
195 __gnu_debug::
__base(__last), __a) { }
197 #if __cplusplus < 201103L
198 vector(
const vector& __x)
201 ~vector() _GLIBCXX_NOEXCEPT { }
203 vector(
const vector&) =
default;
204 vector(vector&&) =
default;
206 vector(
const vector& __x,
const allocator_type& __a)
207 : _Base(__x, __a) { }
209 vector(vector&& __x,
const allocator_type& __a)
211 _Base(std::declval<_Base&&>()), std::declval<const allocator_type&>()) )
212 : _Safe(std::move(__x._M_safe()), __a),
213 _Base(std::move(__x._M_base()), __a),
214 _Safe_vector(std::move(__x)) { }
216 vector(initializer_list<value_type> __l,
217 const allocator_type& __a = allocator_type())
218 : _Base(__l, __a) { }
227 #if __cplusplus < 201103L
229 operator=(
const vector& __x)
231 this->_M_safe() = __x;
233 this->_M_update_guaranteed_capacity();
238 operator=(
const vector&) =
default;
241 operator=(
vector&&) =
default;
247 this->_M_invalidate_all();
248 this->_M_update_guaranteed_capacity();
253 #if __cplusplus >= 201103L
254 template<
typename _InputIterator,
255 typename = std::_RequireInputIter<_InputIterator>>
257 template<
typename _InputIterator>
260 assign(_InputIterator __first, _InputIterator __last)
263 __glibcxx_check_valid_range2(__first, __last, __dist);
265 if (__dist.
second >= __gnu_debug::__dp_sign)
266 _Base::assign(__gnu_debug::__unsafe(__first),
267 __gnu_debug::__unsafe(__last));
269 _Base::assign(__first, __last);
271 this->_M_invalidate_all();
272 this->_M_update_guaranteed_capacity();
276 assign(size_type __n,
const _Tp& __u)
278 _Base::assign(__n, __u);
279 this->_M_invalidate_all();
280 this->_M_update_guaranteed_capacity();
283 #if __cplusplus >= 201103L
285 assign(initializer_list<value_type> __l)
288 this->_M_invalidate_all();
289 this->_M_update_guaranteed_capacity();
293 using _Base::get_allocator;
297 begin() _GLIBCXX_NOEXCEPT
298 {
return iterator(_Base::begin(),
this); }
301 begin() const _GLIBCXX_NOEXCEPT
302 {
return const_iterator(_Base::begin(),
this); }
305 end() _GLIBCXX_NOEXCEPT
306 {
return iterator(_Base::end(),
this); }
309 end() const _GLIBCXX_NOEXCEPT
310 {
return const_iterator(_Base::end(),
this); }
313 rbegin() _GLIBCXX_NOEXCEPT
314 {
return reverse_iterator(end()); }
316 const_reverse_iterator
317 rbegin() const _GLIBCXX_NOEXCEPT
318 {
return const_reverse_iterator(end()); }
321 rend() _GLIBCXX_NOEXCEPT
322 {
return reverse_iterator(begin()); }
324 const_reverse_iterator
325 rend() const _GLIBCXX_NOEXCEPT
326 {
return const_reverse_iterator(begin()); }
328 #if __cplusplus >= 201103L
330 cbegin() const noexcept
331 {
return const_iterator(_Base::begin(),
this); }
334 cend() const noexcept
335 {
return const_iterator(_Base::end(),
this); }
337 const_reverse_iterator
338 crbegin() const noexcept
339 {
return const_reverse_iterator(end()); }
341 const_reverse_iterator
342 crend() const noexcept
343 {
return const_reverse_iterator(begin()); }
348 using _Base::max_size;
350 #if __cplusplus >= 201103L
352 resize(size_type __sz)
354 bool __realloc = this->_M_requires_reallocation(__sz);
355 if (__sz < this->size())
356 this->_M_invalidate_after_nth(__sz);
359 this->_M_invalidate_all();
360 this->_M_update_guaranteed_capacity();
364 resize(size_type __sz,
const _Tp& __c)
366 bool __realloc = this->_M_requires_reallocation(__sz);
367 if (__sz < this->size())
368 this->_M_invalidate_after_nth(__sz);
369 _Base::resize(__sz, __c);
371 this->_M_invalidate_all();
372 this->_M_update_guaranteed_capacity();
376 resize(size_type __sz, _Tp __c = _Tp())
378 bool __realloc = this->_M_requires_reallocation(__sz);
379 if (__sz < this->size())
380 this->_M_invalidate_after_nth(__sz);
381 _Base::resize(__sz, __c);
383 this->_M_invalidate_all();
384 this->_M_update_guaranteed_capacity();
388 #if __cplusplus >= 201103L
392 if (_Base::_M_shrink_to_fit())
394 this->_M_guaranteed_capacity = _Base::capacity();
395 this->_M_invalidate_all();
401 capacity() const _GLIBCXX_NOEXCEPT
403 #ifdef _GLIBCXX_DEBUG_PEDANTIC
404 return this->_M_guaranteed_capacity;
406 return _Base::capacity();
413 reserve(size_type __n)
415 bool __realloc = this->_M_requires_reallocation(__n);
417 if (__n > this->_M_guaranteed_capacity)
418 this->_M_guaranteed_capacity = __n;
420 this->_M_invalidate_all();
425 operator[](size_type __n) _GLIBCXX_NOEXCEPT
427 __glibcxx_check_subscript(__n);
428 return _M_base()[__n];
432 operator[](size_type __n)
const _GLIBCXX_NOEXCEPT
434 __glibcxx_check_subscript(__n);
435 return _M_base()[__n];
441 front() _GLIBCXX_NOEXCEPT
443 __glibcxx_check_nonempty();
444 return _Base::front();
448 front() const _GLIBCXX_NOEXCEPT
450 __glibcxx_check_nonempty();
451 return _Base::front();
455 back() _GLIBCXX_NOEXCEPT
457 __glibcxx_check_nonempty();
458 return _Base::back();
462 back() const _GLIBCXX_NOEXCEPT
464 __glibcxx_check_nonempty();
465 return _Base::back();
474 push_back(
const _Tp& __x)
476 bool __realloc = this->_M_requires_reallocation(this->size() + 1);
477 _Base::push_back(__x);
479 this->_M_invalidate_all();
480 this->_M_update_guaranteed_capacity();
483 #if __cplusplus >= 201103L
484 template<
typename _Up = _Tp>
485 typename __gnu_cxx::__enable_if<!std::__are_same<_Up, bool>::__value,
488 { emplace_back(std::move(__x)); }
490 template<
typename... _Args>
491 #if __cplusplus > 201402L
496 emplace_back(_Args&&... __args)
498 bool __realloc = this->_M_requires_reallocation(this->size() + 1);
499 _Base::emplace_back(std::forward<_Args>(__args)...);
501 this->_M_invalidate_all();
502 this->_M_update_guaranteed_capacity();
503 #if __cplusplus > 201402L
510 pop_back() _GLIBCXX_NOEXCEPT
512 __glibcxx_check_nonempty();
517 #if __cplusplus >= 201103L
518 template<
typename... _Args>
520 emplace(const_iterator __position, _Args&&... __args)
523 bool __realloc = this->_M_requires_reallocation(this->size() + 1);
524 difference_type __offset = __position.base() - _Base::cbegin();
525 _Base_iterator __res = _Base::emplace(__position.base(),
526 std::forward<_Args>(__args)...);
528 this->_M_invalidate_all();
530 this->_M_invalidate_after_nth(__offset);
531 this->_M_update_guaranteed_capacity();
532 return { __res,
this };
537 #if __cplusplus >= 201103L
538 insert(const_iterator __position,
const _Tp& __x)
540 insert(iterator __position,
const _Tp& __x)
544 bool __realloc = this->_M_requires_reallocation(this->size() + 1);
545 difference_type __offset = __position.base() - _Base::begin();
546 _Base_iterator __res = _Base::insert(__position.base(), __x);
548 this->_M_invalidate_all();
550 this->_M_invalidate_after_nth(__offset);
551 this->_M_update_guaranteed_capacity();
552 return iterator(__res,
this);
555 #if __cplusplus >= 201103L
556 template<
typename _Up = _Tp>
557 typename __gnu_cxx::__enable_if<!std::__are_same<_Up, bool>::__value,
559 insert(const_iterator __position, _Tp&& __x)
560 {
return emplace(__position, std::move(__x)); }
563 insert(const_iterator __position, initializer_list<value_type> __l)
564 {
return this->insert(__position, __l.begin(), __l.end()); }
567 #if __cplusplus >= 201103L
569 insert(const_iterator __position, size_type __n,
const _Tp& __x)
572 bool __realloc = this->_M_requires_reallocation(this->size() + __n);
573 difference_type __offset = __position.base() - _Base::cbegin();
574 _Base_iterator __res = _Base::insert(__position.base(), __n, __x);
576 this->_M_invalidate_all();
578 this->_M_invalidate_after_nth(__offset);
579 this->_M_update_guaranteed_capacity();
580 return { __res,
this };
584 insert(iterator __position, size_type __n,
const _Tp& __x)
587 bool __realloc = this->_M_requires_reallocation(this->size() + __n);
588 difference_type __offset = __position.base() - _Base::begin();
589 _Base::insert(__position.base(), __n, __x);
591 this->_M_invalidate_all();
593 this->_M_invalidate_after_nth(__offset);
594 this->_M_update_guaranteed_capacity();
598 #if __cplusplus >= 201103L
599 template<
class _InputIterator,
600 typename = std::_RequireInputIter<_InputIterator>>
602 insert(const_iterator __position,
603 _InputIterator __first, _InputIterator __last)
611 _Base_iterator __old_begin = _M_base().begin();
612 difference_type __offset = __position.base() - _Base::cbegin();
613 _Base_iterator __res;
614 if (__dist.
second >= __gnu_debug::__dp_sign)
615 __res = _Base::insert(__position.base(),
616 __gnu_debug::__unsafe(__first),
617 __gnu_debug::__unsafe(__last));
619 __res = _Base::insert(__position.base(), __first, __last);
621 if (_M_base().begin() != __old_begin)
622 this->_M_invalidate_all();
624 this->_M_invalidate_after_nth(__offset);
625 this->_M_update_guaranteed_capacity();
626 return { __res,
this };
629 template<
class _InputIterator>
631 insert(iterator __position,
632 _InputIterator __first, _InputIterator __last)
640 _Base_iterator __old_begin = _M_base().begin();
641 difference_type __offset = __position.base() - _Base::begin();
642 if (__dist.
second >= __gnu_debug::__dp_sign)
643 _Base::insert(__position.base(), __gnu_debug::__unsafe(__first),
644 __gnu_debug::__unsafe(__last));
646 _Base::insert(__position.base(), __first, __last);
648 if (_M_base().begin() != __old_begin)
649 this->_M_invalidate_all();
651 this->_M_invalidate_after_nth(__offset);
652 this->_M_update_guaranteed_capacity();
657 #if __cplusplus >= 201103L
658 erase(const_iterator __position)
660 erase(iterator __position)
664 difference_type __offset = __position.base() - _Base::begin();
665 _Base_iterator __res = _Base::erase(__position.base());
666 this->_M_invalidate_after_nth(__offset);
667 return iterator(__res,
this);
671 #if __cplusplus >= 201103L
672 erase(const_iterator __first, const_iterator __last)
674 erase(iterator __first, iterator __last)
681 if (__first.base() != __last.base())
683 difference_type __offset = __first.base() - _Base::begin();
684 _Base_iterator __res = _Base::erase(__first.base(),
686 this->_M_invalidate_after_nth(__offset);
687 return iterator(__res,
this);
690 #if __cplusplus >= 201103L
691 return { _Base::begin() + (__first.base() - _Base::cbegin()),
this };
699 _GLIBCXX_NOEXCEPT_IF( noexcept(declval<_Base&>().swap(__x)) )
703 std::swap(this->_M_guaranteed_capacity, __x._M_guaranteed_capacity);
707 clear() _GLIBCXX_NOEXCEPT
710 this->_M_invalidate_all();
714 _M_base() _GLIBCXX_NOEXCEPT {
return *
this; }
717 _M_base() const _GLIBCXX_NOEXCEPT {
return *
this; }
721 _M_invalidate_after_nth(difference_type __n) _GLIBCXX_NOEXCEPT
728 template<
typename _Tp,
typename _Alloc>
730 operator==(
const vector<_Tp, _Alloc>& __lhs,
731 const vector<_Tp, _Alloc>& __rhs)
732 {
return __lhs._M_base() == __rhs._M_base(); }
734 template<
typename _Tp,
typename _Alloc>
736 operator!=(
const vector<_Tp, _Alloc>& __lhs,
737 const vector<_Tp, _Alloc>& __rhs)
738 {
return __lhs._M_base() != __rhs._M_base(); }
740 template<
typename _Tp,
typename _Alloc>
742 operator<(const vector<_Tp, _Alloc>& __lhs,
743 const vector<_Tp, _Alloc>& __rhs)
744 {
return __lhs._M_base() < __rhs._M_base(); }
746 template<
typename _Tp,
typename _Alloc>
748 operator<=(const vector<_Tp, _Alloc>& __lhs,
749 const vector<_Tp, _Alloc>& __rhs)
750 {
return __lhs._M_base() <= __rhs._M_base(); }
752 template<
typename _Tp,
typename _Alloc>
754 operator>=(
const vector<_Tp, _Alloc>& __lhs,
755 const vector<_Tp, _Alloc>& __rhs)
756 {
return __lhs._M_base() >= __rhs._M_base(); }
758 template<
typename _Tp,
typename _Alloc>
760 operator>(
const vector<_Tp, _Alloc>& __lhs,
761 const vector<_Tp, _Alloc>& __rhs)
762 {
return __lhs._M_base() > __rhs._M_base(); }
764 template<
typename _Tp,
typename _Alloc>
766 swap(vector<_Tp, _Alloc>& __lhs, vector<_Tp, _Alloc>& __rhs)
767 _GLIBCXX_NOEXCEPT_IF(noexcept(__lhs.swap(__rhs)))
768 { __lhs.swap(__rhs); }
770 #if __cpp_deduction_guides >= 201606
771 template<
typename _InputIterator,
typename _ValT
772 =
typename iterator_traits<_InputIterator>::value_type,
773 typename _Allocator = allocator<_ValT>,
774 typename = _RequireInputIter<_InputIterator>,
775 typename = _RequireAllocator<_Allocator>>
776 vector(_InputIterator, _InputIterator, _Allocator = _Allocator())
777 -> vector<_ValT, _Allocator>;
782 _GLIBCXX_BEGIN_NAMESPACE_VERSION
784 #if __cplusplus >= 201103L
787 template<
typename _Alloc>
789 :
public __hash_base<size_t, __debug::vector<bool, _Alloc>>
797 template<
typename _Iterator,
typename _Container,
typename _Sequence>
800 __gnu_cxx::__normal_iterator<_Iterator, _Container>,
802 {
return std::__niter_base(__it.base()); }
804 #if __cplusplus >= 201703L
805 namespace __detail::__variant
807 template<
typename>
struct _Never_valueless_alt;
811 template<
typename _Tp,
typename _Alloc>
812 struct _Never_valueless_alt<__debug::vector<_Tp, _Alloc>>
818 _GLIBCXX_END_NAMESPACE_VERSION
821 namespace __gnu_debug
823 template<
typename _Tp,
typename _Alloc>
824 struct _Is_contiguous_sequence<std::__debug::vector<_Tp, _Alloc> >
828 template<
typename _Alloc>
829 struct _Is_contiguous_sequence<std::__debug::vector<bool, _Alloc> >
void _M_invalidate_if(_Predicate __pred)
Safe class dealing with some allocator dependent operations.
#define __glibcxx_check_insert_range(_Position, _First, _Last, _Dist)
is_nothrow_move_assignable
Base class for Debug Mode vector.
Struct holding two objects of arbitrary type.
enable_if< ::__array_traits< _Tp, _Nm >::_Is_swappable::value >::type noexcept(noexcept(__one.swap(__two)))
swap
The standard allocator, as per [20.4].
Base class for constructing a safe sequence type that tracks iterators that reference it...
_Iterator __base(_Iterator __it)
Class std::vector with safety/checking/debug instrumentation.
Random-access iterators support a superset of bidirectional iterator operations.
_T2 second
first is a copy of the first object
Primary class template hash.
#define __glibcxx_check_erase_range(_First, _Last)
#define __glibcxx_check_insert(_Position)
vector(const _Base &__x)
Construction from a normal-mode vector.
#define __glibcxx_check_erase(_Position)
A standard container which offers fixed time access to individual elements in any order...