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;
52 template<
typename _SafeSequence,
53 typename _BaseSequence>
56 typedef typename _BaseSequence::size_type size_type;
59 _M_seq()
const {
return *
static_cast<const _SafeSequence*
>(
this); }
63 : _M_guaranteed_capacity(0)
64 { _M_update_guaranteed_capacity(); }
67 : _M_guaranteed_capacity(0)
68 { _M_update_guaranteed_capacity(); }
71 : _M_guaranteed_capacity(__n)
77 _M_update_guaranteed_capacity();
81 #if __cplusplus >= 201103L
84 { __x._M_guaranteed_capacity = 0; }
89 _M_update_guaranteed_capacity();
90 __x._M_guaranteed_capacity = 0;
95 size_type _M_guaranteed_capacity;
98 _M_requires_reallocation(size_type __elements)
const _GLIBCXX_NOEXCEPT
99 {
return __elements > _M_seq().capacity(); }
102 _M_update_guaranteed_capacity() _GLIBCXX_NOEXCEPT
104 if (_M_seq().size() > _M_guaranteed_capacity)
105 _M_guaranteed_capacity = _M_seq().size();
110 namespace std _GLIBCXX_VISIBILITY(default)
115 template<
typename _Tp,
119 vector<_Tp, _Allocator>, _Allocator, __gnu_debug::_Safe_sequence>,
120 public _GLIBCXX_STD_C::vector<_Tp, _Allocator>,
122 vector<_Tp, _Allocator>,
123 _GLIBCXX_STD_C::vector<_Tp, _Allocator> >
125 typedef _GLIBCXX_STD_C::vector<_Tp, _Allocator> _Base;
130 typedef typename _Base::iterator _Base_iterator;
131 typedef typename _Base::const_iterator _Base_const_iterator;
134 template<
typename _ItT,
typename _SeqT,
typename _CatT>
135 friend class ::__gnu_debug::_Safe_iterator;
142 _Base_ref(
const _Base& __r) : _M_ref(__r) { }
148 typedef typename _Base::reference reference;
149 typedef typename _Base::const_reference const_reference;
152 _Base_iterator, vector> iterator;
154 _Base_const_iterator, vector> const_iterator;
156 typedef typename _Base::size_type size_type;
157 typedef typename _Base::difference_type difference_type;
159 typedef _Tp value_type;
160 typedef _Allocator allocator_type;
161 typedef typename _Base::pointer pointer;
162 typedef typename _Base::const_pointer const_pointer;
168 #if __cplusplus < 201103L
169 vector() _GLIBCXX_NOEXCEPT
176 vector(
const _Allocator& __a) _GLIBCXX_NOEXCEPT
179 #if __cplusplus >= 201103L
181 vector(size_type __n,
const _Allocator& __a = _Allocator())
182 : _Base(__n, __a), _Safe_vector(__n) { }
184 vector(size_type __n,
const __type_identity_t<_Tp>& __value,
185 const _Allocator& __a = _Allocator())
186 : _Base(__n, __value, __a) { }
189 vector(size_type __n,
const _Tp& __value = _Tp(),
190 const _Allocator& __a = _Allocator())
191 : _Base(__n, __value, __a) { }
194 #if __cplusplus >= 201103L
195 template<
class _InputIterator,
196 typename = std::_RequireInputIter<_InputIterator>>
198 template<
class _InputIterator>
200 vector(_InputIterator __first, _InputIterator __last,
201 const _Allocator& __a = _Allocator())
202 : _Base(__gnu_debug::
__base(
203 __glibcxx_check_valid_constructor_range(__first, __last)),
204 __gnu_debug::
__base(__last), __a) { }
206 #if __cplusplus < 201103L
207 vector(
const vector& __x)
210 ~vector() _GLIBCXX_NOEXCEPT { }
212 vector(
const vector&) =
default;
213 vector(vector&&) =
default;
215 vector(
const vector& __x,
const __type_identity_t<allocator_type>& __a)
216 : _Base(__x, __a) { }
218 vector(vector&& __x,
const __type_identity_t<allocator_type>& __a)
221 _Base,
const allocator_type&>::value )
222 : _Safe(std::
move(__x), __a),
223 _Base(std::
move(__x), __a),
224 _Safe_vector(std::
move(__x)) { }
226 vector(initializer_list<value_type> __l,
227 const allocator_type& __a = allocator_type())
228 : _Base(__l, __a) { }
235 :
_Base(__x._M_ref) { }
237 #if __cplusplus >= 201103L
239 operator=(
const vector&) =
default;
242 operator=(
vector&&) =
default;
247 _Base::operator=(__l);
248 this->_M_invalidate_all();
249 this->_M_update_guaranteed_capacity();
254 #if __cplusplus >= 201103L
255 template<
typename _InputIterator,
256 typename = std::_RequireInputIter<_InputIterator>>
258 template<
typename _InputIterator>
261 assign(_InputIterator __first, _InputIterator __last)
264 __glibcxx_check_valid_range2(__first, __last, __dist);
266 if (__dist.
second >= __gnu_debug::__dp_sign)
267 _Base::assign(__gnu_debug::__unsafe(__first),
268 __gnu_debug::__unsafe(__last));
270 _Base::assign(__first, __last);
272 this->_M_invalidate_all();
273 this->_M_update_guaranteed_capacity();
277 assign(size_type __n,
const _Tp& __u)
279 _Base::assign(__n, __u);
280 this->_M_invalidate_all();
281 this->_M_update_guaranteed_capacity();
284 #if __cplusplus >= 201103L
286 assign(initializer_list<value_type> __l)
289 this->_M_invalidate_all();
290 this->_M_update_guaranteed_capacity();
294 using _Base::get_allocator;
299 begin() _GLIBCXX_NOEXCEPT
300 {
return iterator(_Base::begin(),
this); }
304 begin() const _GLIBCXX_NOEXCEPT
305 {
return const_iterator(_Base::begin(),
this); }
309 end() _GLIBCXX_NOEXCEPT
310 {
return iterator(_Base::end(),
this); }
314 end() const _GLIBCXX_NOEXCEPT
315 {
return const_iterator(_Base::end(),
this); }
319 rbegin() _GLIBCXX_NOEXCEPT
320 {
return reverse_iterator(end()); }
323 const_reverse_iterator
324 rbegin() const _GLIBCXX_NOEXCEPT
325 {
return const_reverse_iterator(end()); }
329 rend() _GLIBCXX_NOEXCEPT
330 {
return reverse_iterator(begin()); }
333 const_reverse_iterator
334 rend() const _GLIBCXX_NOEXCEPT
335 {
return const_reverse_iterator(begin()); }
337 #if __cplusplus >= 201103L
340 cbegin() const noexcept
341 {
return const_iterator(_Base::begin(),
this); }
345 cend() const noexcept
346 {
return const_iterator(_Base::end(),
this); }
349 const_reverse_iterator
350 crbegin() const noexcept
351 {
return const_reverse_iterator(end()); }
354 const_reverse_iterator
355 crend() const noexcept
356 {
return const_reverse_iterator(begin()); }
361 using _Base::max_size;
363 #if __cplusplus >= 201103L
365 resize(size_type __sz)
367 bool __realloc = this->_M_requires_reallocation(__sz);
368 if (__sz < this->
size())
369 this->_M_invalidate_after_nth(__sz);
372 this->_M_invalidate_all();
373 this->_M_update_guaranteed_capacity();
377 resize(size_type __sz,
const _Tp& __c)
379 bool __realloc = this->_M_requires_reallocation(__sz);
380 if (__sz < this->
size())
381 this->_M_invalidate_after_nth(__sz);
382 _Base::resize(__sz, __c);
384 this->_M_invalidate_all();
385 this->_M_update_guaranteed_capacity();
389 resize(size_type __sz, _Tp __c = _Tp())
391 bool __realloc = this->_M_requires_reallocation(__sz);
392 if (__sz < this->
size())
393 this->_M_invalidate_after_nth(__sz);
394 _Base::resize(__sz, __c);
396 this->_M_invalidate_all();
397 this->_M_update_guaranteed_capacity();
401 #if __cplusplus >= 201103L
405 if (_Base::_M_shrink_to_fit())
407 this->_M_guaranteed_capacity = _Base::capacity();
408 this->_M_invalidate_all();
415 capacity() const _GLIBCXX_NOEXCEPT
417 #ifdef _GLIBCXX_DEBUG_PEDANTIC
418 return this->_M_guaranteed_capacity;
420 return _Base::capacity();
427 reserve(size_type __n)
429 bool __realloc = this->_M_requires_reallocation(__n);
431 if (__n > this->_M_guaranteed_capacity)
432 this->_M_guaranteed_capacity = __n;
434 this->_M_invalidate_all();
440 operator[](size_type __n) _GLIBCXX_NOEXCEPT
442 __glibcxx_check_subscript(__n);
443 return _Base::operator[](__n);
448 operator[](size_type __n)
const _GLIBCXX_NOEXCEPT
450 __glibcxx_check_subscript(__n);
451 return _Base::operator[](__n);
458 front() _GLIBCXX_NOEXCEPT
460 __glibcxx_check_nonempty();
461 return _Base::front();
466 front() const _GLIBCXX_NOEXCEPT
468 __glibcxx_check_nonempty();
469 return _Base::front();
474 back() _GLIBCXX_NOEXCEPT
476 __glibcxx_check_nonempty();
477 return _Base::back();
482 back() const _GLIBCXX_NOEXCEPT
484 __glibcxx_check_nonempty();
485 return _Base::back();
494 push_back(
const _Tp& __x)
496 bool __realloc = this->_M_requires_reallocation(this->
size() + 1);
497 _Base::push_back(__x);
499 this->_M_invalidate_all();
500 this->_M_update_guaranteed_capacity();
503 #if __cplusplus >= 201103L
504 template<
typename _Up = _Tp>
505 typename __gnu_cxx::__enable_if<!std::__are_same<_Up, bool>::__value,
510 template<
typename... _Args>
511 #if __cplusplus > 201402L
516 emplace_back(_Args&&... __args)
518 bool __realloc = this->_M_requires_reallocation(this->
size() + 1);
519 _Base::emplace_back(std::forward<_Args>(__args)...);
521 this->_M_invalidate_all();
522 this->_M_update_guaranteed_capacity();
523 #if __cplusplus > 201402L
530 pop_back() _GLIBCXX_NOEXCEPT
532 __glibcxx_check_nonempty();
537 #if __cplusplus >= 201103L
538 template<
typename... _Args>
540 emplace(const_iterator __position, _Args&&... __args)
543 bool __realloc = this->_M_requires_reallocation(this->
size() + 1);
544 difference_type __offset = __position.base() - _Base::cbegin();
545 _Base_iterator __res = _Base::emplace(__position.base(),
546 std::forward<_Args>(__args)...);
548 this->_M_invalidate_all();
550 this->_M_invalidate_after_nth(__offset);
551 this->_M_update_guaranteed_capacity();
552 return { __res,
this };
557 #if __cplusplus >= 201103L
558 insert(const_iterator __position,
const _Tp& __x)
560 insert(iterator __position,
const _Tp& __x)
564 bool __realloc = this->_M_requires_reallocation(this->
size() + 1);
565 difference_type __offset = __position.base() - _Base::begin();
566 _Base_iterator __res = _Base::insert(__position.base(), __x);
568 this->_M_invalidate_all();
570 this->_M_invalidate_after_nth(__offset);
571 this->_M_update_guaranteed_capacity();
572 return iterator(__res,
this);
575 #if __cplusplus >= 201103L
576 template<
typename _Up = _Tp>
577 typename __gnu_cxx::__enable_if<!std::__are_same<_Up, bool>::__value,
579 insert(const_iterator __position, _Tp&& __x)
580 {
return emplace(__position,
std::move(__x)); }
583 insert(const_iterator __position, initializer_list<value_type> __l)
584 {
return this->insert(__position, __l.begin(), __l.end()); }
587 #if __cplusplus >= 201103L
589 insert(const_iterator __position, size_type __n,
const _Tp& __x)
592 bool __realloc = this->_M_requires_reallocation(this->
size() + __n);
593 difference_type __offset = __position.base() - _Base::cbegin();
594 _Base_iterator __res = _Base::insert(__position.base(), __n, __x);
596 this->_M_invalidate_all();
598 this->_M_invalidate_after_nth(__offset);
599 this->_M_update_guaranteed_capacity();
600 return { __res,
this };
604 insert(iterator __position, size_type __n,
const _Tp& __x)
607 bool __realloc = this->_M_requires_reallocation(this->
size() + __n);
608 difference_type __offset = __position.base() - _Base::begin();
609 _Base::insert(__position.base(), __n, __x);
611 this->_M_invalidate_all();
613 this->_M_invalidate_after_nth(__offset);
614 this->_M_update_guaranteed_capacity();
618 #if __cplusplus >= 201103L
619 template<
class _InputIterator,
620 typename = std::_RequireInputIter<_InputIterator>>
622 insert(const_iterator __position,
623 _InputIterator __first, _InputIterator __last)
631 _Base_iterator __old_begin = _M_base().begin();
632 difference_type __offset = __position.base() - _Base::cbegin();
633 _Base_iterator __res;
634 if (__dist.
second >= __gnu_debug::__dp_sign)
635 __res = _Base::insert(__position.base(),
636 __gnu_debug::__unsafe(__first),
637 __gnu_debug::__unsafe(__last));
639 __res = _Base::insert(__position.base(), __first, __last);
641 if (_M_base().begin() != __old_begin)
642 this->_M_invalidate_all();
644 this->_M_invalidate_after_nth(__offset);
645 this->_M_update_guaranteed_capacity();
646 return { __res,
this };
649 template<
class _InputIterator>
651 insert(iterator __position,
652 _InputIterator __first, _InputIterator __last)
660 _Base_iterator __old_begin = _M_base().begin();
661 difference_type __offset = __position.base() - _Base::begin();
662 if (__dist.
second >= __gnu_debug::__dp_sign)
663 _Base::insert(__position.base(), __gnu_debug::__unsafe(__first),
664 __gnu_debug::__unsafe(__last));
666 _Base::insert(__position.base(), __first, __last);
668 if (_M_base().begin() != __old_begin)
669 this->_M_invalidate_all();
671 this->_M_invalidate_after_nth(__offset);
672 this->_M_update_guaranteed_capacity();
677 #if __cplusplus >= 201103L
678 erase(const_iterator __position)
680 erase(iterator __position)
684 difference_type __offset = __position.base() - _Base::begin();
685 _Base_iterator __res = _Base::erase(__position.base());
686 this->_M_invalidate_after_nth(__offset);
687 return iterator(__res,
this);
691 #if __cplusplus >= 201103L
692 erase(const_iterator __first, const_iterator __last)
694 erase(iterator __first, iterator __last)
701 if (__first.base() != __last.base())
703 difference_type __offset = __first.base() - _Base::begin();
704 _Base_iterator __res = _Base::erase(__first.base(),
706 this->_M_invalidate_after_nth(__offset);
707 return iterator(__res,
this);
710 #if __cplusplus >= 201103L
711 return { _Base::begin() + (__first.base() - _Base::cbegin()),
this };
719 _GLIBCXX_NOEXCEPT_IF( noexcept(declval<_Base&>().swap(__x)) )
723 std::swap(this->_M_guaranteed_capacity, __x._M_guaranteed_capacity);
727 clear() _GLIBCXX_NOEXCEPT
730 this->_M_invalidate_all();
734 _M_base() _GLIBCXX_NOEXCEPT {
return *
this; }
737 _M_base() const _GLIBCXX_NOEXCEPT {
return *
this; }
741 _M_invalidate_after_nth(difference_type __n) _GLIBCXX_NOEXCEPT
748 template<
typename _Tp,
typename _Alloc>
750 operator==(
const vector<_Tp, _Alloc>& __lhs,
751 const vector<_Tp, _Alloc>& __rhs)
752 {
return __lhs._M_base() == __rhs._M_base(); }
754 #if __cpp_lib_three_way_comparison
755 template<
typename _Tp,
typename _Alloc>
756 constexpr __detail::__synth3way_t<_Tp>
757 operator<=>(
const vector<_Tp, _Alloc>& __x,
const vector<_Tp, _Alloc>& __y)
758 {
return __x._M_base() <=> __y._M_base(); }
760 template<
typename _Tp,
typename _Alloc>
762 operator!=(
const vector<_Tp, _Alloc>& __lhs,
763 const vector<_Tp, _Alloc>& __rhs)
764 {
return __lhs._M_base() != __rhs._M_base(); }
766 template<
typename _Tp,
typename _Alloc>
768 operator<(const vector<_Tp, _Alloc>& __lhs,
769 const vector<_Tp, _Alloc>& __rhs)
770 {
return __lhs._M_base() < __rhs._M_base(); }
772 template<
typename _Tp,
typename _Alloc>
774 operator<=(const vector<_Tp, _Alloc>& __lhs,
775 const vector<_Tp, _Alloc>& __rhs)
776 {
return __lhs._M_base() <= __rhs._M_base(); }
778 template<
typename _Tp,
typename _Alloc>
780 operator>=(
const vector<_Tp, _Alloc>& __lhs,
781 const vector<_Tp, _Alloc>& __rhs)
782 {
return __lhs._M_base() >= __rhs._M_base(); }
784 template<
typename _Tp,
typename _Alloc>
786 operator>(
const vector<_Tp, _Alloc>& __lhs,
787 const vector<_Tp, _Alloc>& __rhs)
788 {
return __lhs._M_base() > __rhs._M_base(); }
789 #endif // three-way comparison
791 template<
typename _Tp,
typename _Alloc>
793 swap(vector<_Tp, _Alloc>& __lhs, vector<_Tp, _Alloc>& __rhs)
794 _GLIBCXX_NOEXCEPT_IF(noexcept(__lhs.swap(__rhs)))
795 { __lhs.swap(__rhs); }
797 #if __cpp_deduction_guides >= 201606
798 template<
typename _InputIterator,
typename _ValT
799 =
typename iterator_traits<_InputIterator>::value_type,
800 typename _Allocator = allocator<_ValT>,
801 typename = _RequireInputIter<_InputIterator>,
802 typename = _RequireAllocator<_Allocator>>
803 vector(_InputIterator, _InputIterator, _Allocator = _Allocator())
804 -> vector<_ValT, _Allocator>;
806 template<
typename _Tp,
typename _Allocator = allocator<_Tp>,
807 typename = _RequireAllocator<_Allocator>>
808 vector(
size_t, _Tp, _Allocator = _Allocator())
809 -> vector<_Tp, _Allocator>;
814 _GLIBCXX_BEGIN_NAMESPACE_VERSION
816 #if __cplusplus >= 201103L
819 template<
typename _Alloc>
821 :
public __hash_base<size_t, __debug::vector<bool, _Alloc>>
829 #if __cplusplus >= 201703L
830 namespace __detail::__variant
832 template<
typename>
struct _Never_valueless_alt;
836 template<
typename _Tp,
typename _Alloc>
837 struct _Never_valueless_alt<__debug::
vector<_Tp, _Alloc>>
843 _GLIBCXX_END_NAMESPACE_VERSION
846 namespace __gnu_debug
848 template<
typename _Tp,
typename _Alloc>
849 struct _Is_contiguous_sequence<std::__debug::vector<_Tp, _Alloc> >
853 template<
typename _Alloc>
854 struct _Is_contiguous_sequence<std::__debug::vector<bool, _Alloc> >
#define __glibcxx_check_erase(_Position)
is_nothrow_move_assignable
void _M_invalidate_if(_Predicate __pred)
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
Base class for constructing a safe sequence type that tracks iterators that reference it...
Class std::vector with safety/checking/debug instrumentation.
The standard allocator, as per C++03 [20.4.1].
constexpr auto size(const _Container &__cont) noexcept(noexcept(__cont.size())) -> decltype(__cont.size())
Return the size of a container.
#define __glibcxx_check_erase_range(_First, _Last)
Struct holding two objects of arbitrary type.
constexpr _Iterator __base(_Iterator __it)
#define __glibcxx_check_insert(_Position)
Safe class dealing with some allocator dependent operations.
Primary class template hash.
_T2 second
The second member.
#define __glibcxx_check_insert_range(_Position, _First, _Last, _Dist)
A standard container which offers fixed time access to individual elements in any order...
vector(_Base_ref __x)
Construction from a normal-mode vector.
Base class for Debug Mode vector.