29 #ifndef _GLIBCXX_DEBUG_VECTOR
30 #define _GLIBCXX_DEBUG_VECTOR 1
32 #pragma GCC system_header
48 template<
typename _SafeSequence,
49 typename _BaseSequence>
52 typedef typename _BaseSequence::size_type size_type;
55 _M_seq()
const {
return *
static_cast<const _SafeSequence*
>(
this); }
59 : _M_guaranteed_capacity(0)
60 { _M_update_guaranteed_capacity(); }
63 : _M_guaranteed_capacity(0)
64 { _M_update_guaranteed_capacity(); }
67 : _M_guaranteed_capacity(__n)
70 #if __cplusplus >= 201103L
73 { __x._M_guaranteed_capacity = 0; }
78 _M_update_guaranteed_capacity();
85 _M_update_guaranteed_capacity();
86 __x._M_guaranteed_capacity = 0;
91 size_type _M_guaranteed_capacity;
94 _M_requires_reallocation(size_type __elements)
const _GLIBCXX_NOEXCEPT
95 {
return __elements > _M_seq().capacity(); }
98 _M_update_guaranteed_capacity() _GLIBCXX_NOEXCEPT
100 if (_M_seq().size() > _M_guaranteed_capacity)
101 _M_guaranteed_capacity = _M_seq().size();
106 namespace std _GLIBCXX_VISIBILITY(default)
111 template<
typename _Tp,
115 vector<_Tp, _Allocator>, _Allocator, __gnu_debug::_Safe_sequence>,
116 public _GLIBCXX_STD_C::vector<_Tp, _Allocator>,
118 vector<_Tp, _Allocator>,
119 _GLIBCXX_STD_C::vector<_Tp, _Allocator> >
121 typedef _GLIBCXX_STD_C::vector<_Tp, _Allocator>
_Base;
131 typedef typename _Base::reference reference;
132 typedef typename _Base::const_reference const_reference;
139 typedef typename _Base::size_type size_type;
140 typedef typename _Base::difference_type difference_type;
142 typedef _Tp value_type;
143 typedef _Allocator allocator_type;
144 typedef typename _Base::pointer pointer;
145 typedef typename _Base::const_pointer const_pointer;
151 #if __cplusplus < 201103L
152 vector() _GLIBCXX_NOEXCEPT
159 vector(
const _Allocator& __a) _GLIBCXX_NOEXCEPT
162 #if __cplusplus >= 201103L
164 vector(size_type __n,
const _Allocator& __a = _Allocator())
167 vector(size_type __n,
const _Tp& __value,
168 const _Allocator& __a = _Allocator())
169 :
_Base(__n, __value, __a) { }
172 vector(size_type __n,
const _Tp& __value = _Tp(),
173 const _Allocator& __a = _Allocator())
174 :
_Base(__n, __value, __a) { }
177 #if __cplusplus >= 201103L
178 template<
class _InputIterator,
179 typename = std::_RequireInputIter<_InputIterator>>
181 template<
class _InputIterator>
183 vector(_InputIterator __first, _InputIterator __last,
184 const _Allocator& __a = _Allocator())
185 :
_Base(__gnu_debug::__base(__gnu_debug::__check_valid_range(__first,
187 __gnu_debug::__base(__last), __a) { }
189 #if __cplusplus < 201103L
190 vector(
const vector& __x)
193 ~vector() _GLIBCXX_NOEXCEPT { }
195 vector(
const vector&) =
default;
196 vector(vector&&) =
default;
198 vector(
const vector& __x,
const allocator_type& __a)
199 :
_Base(__x, __a) { }
201 vector(vector&& __x,
const allocator_type& __a)
202 :
_Safe(std::move(__x._M_safe()), __a),
203 _Base(std::move(__x._M_base()), __a),
207 const allocator_type& __a = allocator_type())
208 :
_Base(__l, __a) { }
217 #if __cplusplus < 201103L
219 operator=(
const vector& __x)
221 this->_M_safe() = __x;
223 this->_M_update_guaranteed_capacity();
228 operator=(
const vector&) =
default;
231 operator=(vector&&) =
default;
237 this->_M_invalidate_all();
238 this->_M_update_guaranteed_capacity();
243 #if __cplusplus >= 201103L
244 template<
typename _InputIterator,
245 typename = std::_RequireInputIter<_InputIterator>>
247 template<
typename _InputIterator>
250 assign(_InputIterator __first, _InputIterator __last)
253 __glibcxx_check_valid_range2(__first, __last, __dist);
255 if (__dist.
second >= __gnu_debug::__dp_sign)
256 _Base::assign(__gnu_debug::__unsafe(__first),
257 __gnu_debug::__unsafe(__last));
259 _Base::assign(__first, __last);
261 this->_M_invalidate_all();
262 this->_M_update_guaranteed_capacity();
266 assign(size_type __n,
const _Tp& __u)
268 _Base::assign(__n, __u);
269 this->_M_invalidate_all();
270 this->_M_update_guaranteed_capacity();
273 #if __cplusplus >= 201103L
275 assign(initializer_list<value_type> __l)
278 this->_M_invalidate_all();
279 this->_M_update_guaranteed_capacity();
283 using _Base::get_allocator;
287 begin() _GLIBCXX_NOEXCEPT
288 {
return iterator(_Base::begin(),
this); }
291 begin() const _GLIBCXX_NOEXCEPT
292 {
return const_iterator(_Base::begin(),
this); }
295 end() _GLIBCXX_NOEXCEPT
296 {
return iterator(_Base::end(),
this); }
299 end() const _GLIBCXX_NOEXCEPT
300 {
return const_iterator(_Base::end(),
this); }
303 rbegin() _GLIBCXX_NOEXCEPT
304 {
return reverse_iterator(end()); }
306 const_reverse_iterator
307 rbegin() const _GLIBCXX_NOEXCEPT
308 {
return const_reverse_iterator(end()); }
311 rend() _GLIBCXX_NOEXCEPT
312 {
return reverse_iterator(begin()); }
314 const_reverse_iterator
315 rend() const _GLIBCXX_NOEXCEPT
316 {
return const_reverse_iterator(begin()); }
318 #if __cplusplus >= 201103L
320 cbegin() const noexcept
321 {
return const_iterator(_Base::begin(),
this); }
324 cend() const noexcept
325 {
return const_iterator(_Base::end(),
this); }
327 const_reverse_iterator
328 crbegin() const noexcept
329 {
return const_reverse_iterator(end()); }
331 const_reverse_iterator
332 crend() const noexcept
333 {
return const_reverse_iterator(begin()); }
338 using _Base::max_size;
340 #if __cplusplus >= 201103L
342 resize(size_type __sz)
344 bool __realloc = this->_M_requires_reallocation(__sz);
345 if (__sz < this->size())
346 this->_M_invalidate_after_nth(__sz);
349 this->_M_invalidate_all();
350 this->_M_update_guaranteed_capacity();
354 resize(size_type __sz,
const _Tp& __c)
356 bool __realloc = this->_M_requires_reallocation(__sz);
357 if (__sz < this->size())
358 this->_M_invalidate_after_nth(__sz);
359 _Base::resize(__sz, __c);
361 this->_M_invalidate_all();
362 this->_M_update_guaranteed_capacity();
366 resize(size_type __sz, _Tp __c = _Tp())
368 bool __realloc = this->_M_requires_reallocation(__sz);
369 if (__sz < this->size())
370 this->_M_invalidate_after_nth(__sz);
371 _Base::resize(__sz, __c);
373 this->_M_invalidate_all();
374 this->_M_update_guaranteed_capacity();
378 #if __cplusplus >= 201103L
382 if (_Base::_M_shrink_to_fit())
384 this->_M_guaranteed_capacity = _Base::capacity();
385 this->_M_invalidate_all();
391 capacity() const _GLIBCXX_NOEXCEPT
393 #ifdef _GLIBCXX_DEBUG_PEDANTIC
394 return this->_M_guaranteed_capacity;
396 return _Base::capacity();
403 reserve(size_type __n)
405 bool __realloc = this->_M_requires_reallocation(__n);
407 if (__n > this->_M_guaranteed_capacity)
408 this->_M_guaranteed_capacity = __n;
410 this->_M_invalidate_all();
415 operator[](size_type __n) _GLIBCXX_NOEXCEPT
417 __glibcxx_check_subscript(__n);
418 return _M_base()[__n];
422 operator[](size_type __n)
const _GLIBCXX_NOEXCEPT
424 __glibcxx_check_subscript(__n);
425 return _M_base()[__n];
431 front() _GLIBCXX_NOEXCEPT
433 __glibcxx_check_nonempty();
434 return _Base::front();
438 front() const _GLIBCXX_NOEXCEPT
440 __glibcxx_check_nonempty();
441 return _Base::front();
445 back() _GLIBCXX_NOEXCEPT
447 __glibcxx_check_nonempty();
448 return _Base::back();
452 back() const _GLIBCXX_NOEXCEPT
454 __glibcxx_check_nonempty();
455 return _Base::back();
464 push_back(
const _Tp& __x)
466 bool __realloc = this->_M_requires_reallocation(this->size() + 1);
467 _Base::push_back(__x);
469 this->_M_invalidate_all();
470 this->_M_update_guaranteed_capacity();
473 #if __cplusplus >= 201103L
474 template<
typename _Up = _Tp>
475 typename __gnu_cxx::__enable_if<!std::__are_same<_Up, bool>::__value,
478 { emplace_back(std::move(__x)); }
480 template<
typename... _Args>
481 #if __cplusplus > 201402L
486 emplace_back(_Args&&... __args)
488 bool __realloc = this->_M_requires_reallocation(this->size() + 1);
489 _Base::emplace_back(std::forward<_Args>(__args)...);
491 this->_M_invalidate_all();
492 this->_M_update_guaranteed_capacity();
493 #if __cplusplus > 201402L
500 pop_back() _GLIBCXX_NOEXCEPT
502 __glibcxx_check_nonempty();
507 #if __cplusplus >= 201103L
508 template<
typename... _Args>
510 emplace(const_iterator __position, _Args&&... __args)
513 bool __realloc = this->_M_requires_reallocation(this->size() + 1);
514 difference_type __offset = __position.base() - _Base::begin();
515 _Base_iterator __res = _Base::emplace(__position.base(),
516 std::forward<_Args>(__args)...);
518 this->_M_invalidate_all();
520 this->_M_invalidate_after_nth(__offset);
521 this->_M_update_guaranteed_capacity();
522 return iterator(__res,
this);
527 #if __cplusplus >= 201103L
528 insert(const_iterator __position,
const _Tp& __x)
530 insert(iterator __position,
const _Tp& __x)
534 bool __realloc = this->_M_requires_reallocation(this->size() + 1);
535 difference_type __offset = __position.base() - _Base::begin();
536 _Base_iterator __res = _Base::insert(__position.base(), __x);
538 this->_M_invalidate_all();
540 this->_M_invalidate_after_nth(__offset);
541 this->_M_update_guaranteed_capacity();
542 return iterator(__res,
this);
545 #if __cplusplus >= 201103L
546 template<
typename _Up = _Tp>
547 typename __gnu_cxx::__enable_if<!std::__are_same<_Up, bool>::__value,
549 insert(const_iterator __position, _Tp&& __x)
550 {
return emplace(__position, std::move(__x)); }
553 insert(const_iterator __position, initializer_list<value_type> __l)
554 {
return this->insert(__position, __l.begin(), __l.end()); }
557 #if __cplusplus >= 201103L
559 insert(const_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::cbegin();
564 _Base_iterator __res = _Base::insert(__position.base(), __n, __x);
566 this->_M_invalidate_all();
568 this->_M_invalidate_after_nth(__offset);
569 this->_M_update_guaranteed_capacity();
570 return iterator(__res,
this);
574 insert(iterator __position, size_type __n,
const _Tp& __x)
577 bool __realloc = this->_M_requires_reallocation(this->size() + __n);
578 difference_type __offset = __position.base() - _Base::begin();
579 _Base::insert(__position.base(), __n, __x);
581 this->_M_invalidate_all();
583 this->_M_invalidate_after_nth(__offset);
584 this->_M_update_guaranteed_capacity();
588 #if __cplusplus >= 201103L
589 template<
class _InputIterator,
590 typename = std::_RequireInputIter<_InputIterator>>
592 insert(const_iterator __position,
593 _InputIterator __first, _InputIterator __last)
601 _Base_iterator __old_begin = _M_base().begin();
602 difference_type __offset = __position.base() - _Base::cbegin();
603 _Base_iterator __res;
604 if (__dist.
second >= __gnu_debug::__dp_sign)
605 __res = _Base::insert(__position.base(),
606 __gnu_debug::__unsafe(__first),
607 __gnu_debug::__unsafe(__last));
609 __res = _Base::insert(__position.base(), __first, __last);
611 if (_M_base().begin() != __old_begin)
612 this->_M_invalidate_all();
614 this->_M_invalidate_after_nth(__offset);
615 this->_M_update_guaranteed_capacity();
616 return iterator(__res,
this);
619 template<
class _InputIterator>
621 insert(iterator __position,
622 _InputIterator __first, _InputIterator __last)
630 _Base_iterator __old_begin = _M_base().begin();
631 difference_type __offset = __position.base() - _Base::begin();
632 if (__dist.
second >= __gnu_debug::__dp_sign)
633 _Base::insert(__position.base(), __gnu_debug::__unsafe(__first),
634 __gnu_debug::__unsafe(__last));
636 _Base::insert(__position.base(), __first, __last);
638 if (_M_base().begin() != __old_begin)
639 this->_M_invalidate_all();
641 this->_M_invalidate_after_nth(__offset);
642 this->_M_update_guaranteed_capacity();
647 #if __cplusplus >= 201103L
648 erase(const_iterator __position)
650 erase(iterator __position)
654 difference_type __offset = __position.base() - _Base::begin();
655 _Base_iterator __res = _Base::erase(__position.base());
656 this->_M_invalidate_after_nth(__offset);
657 return iterator(__res,
this);
661 #if __cplusplus >= 201103L
662 erase(const_iterator __first, const_iterator __last)
664 erase(iterator __first, iterator __last)
671 if (__first.base() != __last.base())
673 difference_type __offset = __first.base() - _Base::begin();
674 _Base_iterator __res = _Base::erase(__first.base(),
676 this->_M_invalidate_after_nth(__offset);
677 return iterator(__res,
this);
680 #if __cplusplus >= 201103L
681 return begin() + (__first.base() - cbegin().
base());
689 _GLIBCXX_NOEXCEPT_IF( noexcept(declval<_Base&>().swap(__x)) )
693 std::swap(this->_M_guaranteed_capacity, __x._M_guaranteed_capacity);
697 clear() _GLIBCXX_NOEXCEPT
700 this->_M_invalidate_all();
704 _M_base() _GLIBCXX_NOEXCEPT {
return *
this; }
707 _M_base() const _GLIBCXX_NOEXCEPT {
return *
this; }
711 _M_invalidate_after_nth(difference_type __n) _GLIBCXX_NOEXCEPT
718 template<
typename _Tp,
typename _Alloc>
720 operator==(
const vector<_Tp, _Alloc>& __lhs,
721 const vector<_Tp, _Alloc>& __rhs)
722 {
return __lhs._M_base() == __rhs._M_base(); }
724 template<
typename _Tp,
typename _Alloc>
726 operator!=(
const vector<_Tp, _Alloc>& __lhs,
727 const vector<_Tp, _Alloc>& __rhs)
728 {
return __lhs._M_base() != __rhs._M_base(); }
730 template<
typename _Tp,
typename _Alloc>
732 operator<(const vector<_Tp, _Alloc>& __lhs,
733 const vector<_Tp, _Alloc>& __rhs)
734 {
return __lhs._M_base() < __rhs._M_base(); }
736 template<
typename _Tp,
typename _Alloc>
738 operator<=(const vector<_Tp, _Alloc>& __lhs,
739 const vector<_Tp, _Alloc>& __rhs)
740 {
return __lhs._M_base() <= __rhs._M_base(); }
742 template<
typename _Tp,
typename _Alloc>
744 operator>=(
const vector<_Tp, _Alloc>& __lhs,
745 const vector<_Tp, _Alloc>& __rhs)
746 {
return __lhs._M_base() >= __rhs._M_base(); }
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 template<
typename _Tp,
typename _Alloc>
756 swap(vector<_Tp, _Alloc>& __lhs, vector<_Tp, _Alloc>& __rhs)
757 _GLIBCXX_NOEXCEPT_IF(
noexcept(__lhs.swap(__rhs)))
758 { __lhs.swap(__rhs); }
760 #if __cpp_deduction_guides >= 201606
761 template<
typename _InputIterator,
typename _ValT
762 =
typename iterator_traits<_InputIterator>::value_type,
763 typename _Allocator = allocator<_ValT>,
764 typename = _RequireInputIter<_InputIterator>,
765 typename = _RequireAllocator<_Allocator>>
766 vector(_InputIterator, _InputIterator, _Allocator = _Allocator())
767 -> vector<_ValT, _Allocator>;
772 #if __cplusplus >= 201103L
773 _GLIBCXX_BEGIN_NAMESPACE_VERSION
777 template<
typename _Alloc>
778 struct hash<__debug::vector<bool, _Alloc>>
779 :
public __hash_base<size_t, __debug::vector<bool, _Alloc>>
786 _GLIBCXX_END_NAMESPACE_VERSION
791 namespace __gnu_debug
793 template<
typename _Tp,
typename _Alloc>
794 struct _Is_contiguous_sequence<std::__debug::vector<_Tp, _Alloc> >
798 template<
typename _Alloc>
799 struct _Is_contiguous_sequence<std::__debug::vector<bool, _Alloc> >
void _M_invalidate_if(_Predicate __pred)
Safe class dealing with some allocator dependent operations.
_Iterator & base() noexcept
Return the underlying iterator.
#define __glibcxx_check_insert_range(_Position, _First, _Last, _Dist)
enable_if< ::__array_traits< _Tp, _Nm >::_Is_swappable::value >::type noexcept(noexcept(__one.swap(__two)))
swap
Base class for Debug Mode vector.
Struct holding two objects of arbitrary type.
The standard allocator, as per [20.4].
Base class for constructing a safe sequence type that tracks iterators that reference it...
Class std::vector with safety/checking/debug instrumentation.
_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)