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;
135 template<
typename _ItT,
typename _SeqT,
typename _CatT>
136 friend class ::__gnu_debug::_Safe_iterator;
143 _Base_ref(
const _Base& __r) : _M_ref(__r) { }
149 typedef typename _Base::reference reference;
150 typedef typename _Base::const_reference const_reference;
157 typedef typename _Base::size_type size_type;
158 typedef typename _Base::difference_type difference_type;
160 typedef _Tp value_type;
161 typedef _Allocator allocator_type;
162 typedef typename _Base::pointer pointer;
163 typedef typename _Base::const_pointer const_pointer;
169 #if __cplusplus < 201103L
170 vector() _GLIBCXX_NOEXCEPT
177 vector(
const _Allocator& __a) _GLIBCXX_NOEXCEPT
180 #if __cplusplus >= 201103L
182 vector(size_type __n,
const _Allocator& __a = _Allocator())
185 vector(size_type __n,
const _Tp& __value,
186 const _Allocator& __a = _Allocator())
187 :
_Base(__n, __value, __a) { }
190 vector(size_type __n,
const _Tp& __value = _Tp(),
191 const _Allocator& __a = _Allocator())
192 :
_Base(__n, __value, __a) { }
195 #if __cplusplus >= 201103L
196 template<
class _InputIterator,
197 typename = std::_RequireInputIter<_InputIterator>>
199 template<
class _InputIterator>
201 vector(_InputIterator __first, _InputIterator __last,
202 const _Allocator& __a = _Allocator())
204 __glibcxx_check_valid_constructor_range(__first, __last)),
207 #if __cplusplus < 201103L
211 ~
vector() _GLIBCXX_NOEXCEPT { }
217 :
_Base(__x, __a) { }
221 _Base(std::declval<_Base&&>()), std::declval<const allocator_type&>()))
227 const allocator_type& __a = allocator_type())
228 :
_Base(__l, __a) { }
235 :
_Base(__x._M_ref) { }
237 #if __cplusplus < 201103L
239 operator=(
const vector& __x)
241 this->_M_safe() = __x;
243 this->_M_update_guaranteed_capacity();
248 operator=(
const vector&) =
default;
251 operator=(
vector&&) =
default;
258 this->_M_update_guaranteed_capacity();
263 #if __cplusplus >= 201103L
264 template<
typename _InputIterator,
265 typename = std::_RequireInputIter<_InputIterator>>
267 template<
typename _InputIterator>
270 assign(_InputIterator __first, _InputIterator __last)
273 __glibcxx_check_valid_range2(__first, __last, __dist);
275 if (__dist.
second >= __gnu_debug::__dp_sign)
276 _Base::assign(__gnu_debug::__unsafe(__first),
277 __gnu_debug::__unsafe(__last));
279 _Base::assign(__first, __last);
282 this->_M_update_guaranteed_capacity();
286 assign(size_type __n,
const _Tp& __u)
288 _Base::assign(__n, __u);
290 this->_M_update_guaranteed_capacity();
293 #if __cplusplus >= 201103L
295 assign(initializer_list<value_type> __l)
299 this->_M_update_guaranteed_capacity();
303 using _Base::get_allocator;
307 begin() _GLIBCXX_NOEXCEPT
308 {
return iterator(_Base::begin(),
this); }
311 begin() const _GLIBCXX_NOEXCEPT
312 {
return const_iterator(_Base::begin(),
this); }
315 end() _GLIBCXX_NOEXCEPT
316 {
return iterator(_Base::end(),
this); }
319 end() const _GLIBCXX_NOEXCEPT
320 {
return const_iterator(_Base::end(),
this); }
323 rbegin() _GLIBCXX_NOEXCEPT
324 {
return reverse_iterator(end()); }
326 const_reverse_iterator
327 rbegin() const _GLIBCXX_NOEXCEPT
328 {
return const_reverse_iterator(end()); }
331 rend() _GLIBCXX_NOEXCEPT
332 {
return reverse_iterator(begin()); }
334 const_reverse_iterator
335 rend() const _GLIBCXX_NOEXCEPT
336 {
return const_reverse_iterator(begin()); }
338 #if __cplusplus >= 201103L
340 cbegin() const noexcept
341 {
return const_iterator(_Base::begin(),
this); }
344 cend() const noexcept
345 {
return const_iterator(_Base::end(),
this); }
347 const_reverse_iterator
348 crbegin() const noexcept
349 {
return const_reverse_iterator(end()); }
351 const_reverse_iterator
352 crend() const noexcept
353 {
return const_reverse_iterator(begin()); }
358 using _Base::max_size;
360 #if __cplusplus >= 201103L
362 resize(size_type __sz)
364 bool __realloc = this->_M_requires_reallocation(__sz);
365 if (__sz < this->
size())
366 this->_M_invalidate_after_nth(__sz);
370 this->_M_update_guaranteed_capacity();
374 resize(size_type __sz,
const _Tp& __c)
376 bool __realloc = this->_M_requires_reallocation(__sz);
377 if (__sz < this->
size())
378 this->_M_invalidate_after_nth(__sz);
379 _Base::resize(__sz, __c);
382 this->_M_update_guaranteed_capacity();
386 resize(size_type __sz, _Tp __c = _Tp())
388 bool __realloc = this->_M_requires_reallocation(__sz);
389 if (__sz < this->
size())
390 this->_M_invalidate_after_nth(__sz);
391 _Base::resize(__sz, __c);
394 this->_M_update_guaranteed_capacity();
398 #if __cplusplus >= 201103L
402 if (_Base::_M_shrink_to_fit())
404 this->_M_guaranteed_capacity = _Base::capacity();
411 capacity() const _GLIBCXX_NOEXCEPT
413 #ifdef _GLIBCXX_DEBUG_PEDANTIC
414 return this->_M_guaranteed_capacity;
416 return _Base::capacity();
423 reserve(size_type __n)
425 bool __realloc = this->_M_requires_reallocation(__n);
427 if (__n > this->_M_guaranteed_capacity)
428 this->_M_guaranteed_capacity = __n;
435 operator[](size_type __n) _GLIBCXX_NOEXCEPT
437 __glibcxx_check_subscript(__n);
438 return _M_base()[__n];
442 operator[](size_type __n)
const _GLIBCXX_NOEXCEPT
444 __glibcxx_check_subscript(__n);
445 return _M_base()[__n];
451 front() _GLIBCXX_NOEXCEPT
453 __glibcxx_check_nonempty();
454 return _Base::front();
458 front() const _GLIBCXX_NOEXCEPT
460 __glibcxx_check_nonempty();
461 return _Base::front();
465 back() _GLIBCXX_NOEXCEPT
467 __glibcxx_check_nonempty();
468 return _Base::back();
472 back() const _GLIBCXX_NOEXCEPT
474 __glibcxx_check_nonempty();
475 return _Base::back();
484 push_back(
const _Tp& __x)
486 bool __realloc = this->_M_requires_reallocation(this->
size() + 1);
487 _Base::push_back(__x);
490 this->_M_update_guaranteed_capacity();
493 #if __cplusplus >= 201103L
494 template<
typename _Up = _Tp>
495 typename __gnu_cxx::__enable_if<!std::__are_same<_Up, bool>::__value,
500 template<
typename... _Args>
501 #if __cplusplus > 201402L
506 emplace_back(_Args&&... __args)
508 bool __realloc = this->_M_requires_reallocation(this->
size() + 1);
509 _Base::emplace_back(std::forward<_Args>(__args)...);
512 this->_M_update_guaranteed_capacity();
513 #if __cplusplus > 201402L
520 pop_back() _GLIBCXX_NOEXCEPT
522 __glibcxx_check_nonempty();
527 #if __cplusplus >= 201103L
528 template<
typename... _Args>
530 emplace(const_iterator __position, _Args&&... __args)
533 bool __realloc = this->_M_requires_reallocation(this->
size() + 1);
534 difference_type __offset = __position.base() - _Base::cbegin();
535 _Base_iterator __res = _Base::emplace(__position.base(),
536 std::forward<_Args>(__args)...);
540 this->_M_invalidate_after_nth(__offset);
541 this->_M_update_guaranteed_capacity();
542 return { __res,
this };
547 #if __cplusplus >= 201103L
548 insert(const_iterator __position,
const _Tp& __x)
550 insert(iterator __position,
const _Tp& __x)
554 bool __realloc = this->_M_requires_reallocation(this->
size() + 1);
555 difference_type __offset = __position.base() - _Base::begin();
556 _Base_iterator __res = _Base::insert(__position.base(), __x);
560 this->_M_invalidate_after_nth(__offset);
561 this->_M_update_guaranteed_capacity();
562 return iterator(__res,
this);
565 #if __cplusplus >= 201103L
566 template<
typename _Up = _Tp>
567 typename __gnu_cxx::__enable_if<!std::__are_same<_Up, bool>::__value,
569 insert(const_iterator __position, _Tp&& __x)
570 {
return emplace(__position,
std::move(__x)); }
573 insert(const_iterator __position, initializer_list<value_type> __l)
574 {
return this->insert(__position, __l.begin(), __l.end()); }
577 #if __cplusplus >= 201103L
579 insert(const_iterator __position, size_type __n,
const _Tp& __x)
582 bool __realloc = this->_M_requires_reallocation(this->
size() + __n);
583 difference_type __offset = __position.base() - _Base::cbegin();
584 _Base_iterator __res = _Base::insert(__position.base(), __n, __x);
588 this->_M_invalidate_after_nth(__offset);
589 this->_M_update_guaranteed_capacity();
590 return { __res,
this };
594 insert(iterator __position, size_type __n,
const _Tp& __x)
597 bool __realloc = this->_M_requires_reallocation(this->
size() + __n);
598 difference_type __offset = __position.base() - _Base::begin();
599 _Base::insert(__position.base(), __n, __x);
603 this->_M_invalidate_after_nth(__offset);
604 this->_M_update_guaranteed_capacity();
608 #if __cplusplus >= 201103L
609 template<
class _InputIterator,
610 typename = std::_RequireInputIter<_InputIterator>>
612 insert(const_iterator __position,
613 _InputIterator __first, _InputIterator __last)
621 _Base_iterator __old_begin = _M_base().begin();
622 difference_type __offset = __position.base() - _Base::cbegin();
623 _Base_iterator __res;
624 if (__dist.
second >= __gnu_debug::__dp_sign)
625 __res = _Base::insert(__position.base(),
626 __gnu_debug::__unsafe(__first),
627 __gnu_debug::__unsafe(__last));
629 __res = _Base::insert(__position.base(), __first, __last);
631 if (_M_base().begin() != __old_begin)
634 this->_M_invalidate_after_nth(__offset);
635 this->_M_update_guaranteed_capacity();
636 return { __res,
this };
639 template<
class _InputIterator>
641 insert(iterator __position,
642 _InputIterator __first, _InputIterator __last)
650 _Base_iterator __old_begin = _M_base().begin();
651 difference_type __offset = __position.base() - _Base::begin();
652 if (__dist.
second >= __gnu_debug::__dp_sign)
653 _Base::insert(__position.base(), __gnu_debug::__unsafe(__first),
654 __gnu_debug::__unsafe(__last));
656 _Base::insert(__position.base(), __first, __last);
658 if (_M_base().begin() != __old_begin)
661 this->_M_invalidate_after_nth(__offset);
662 this->_M_update_guaranteed_capacity();
667 #if __cplusplus >= 201103L
668 erase(const_iterator __position)
670 erase(iterator __position)
674 difference_type __offset = __position.base() - _Base::begin();
675 _Base_iterator __res = _Base::erase(__position.base());
676 this->_M_invalidate_after_nth(__offset);
677 return iterator(__res,
this);
681 #if __cplusplus >= 201103L
682 erase(const_iterator __first, const_iterator __last)
684 erase(iterator __first, iterator __last)
691 if (__first.base() != __last.base())
693 difference_type __offset = __first.base() - _Base::begin();
694 _Base_iterator __res = _Base::erase(__first.base(),
696 this->_M_invalidate_after_nth(__offset);
697 return iterator(__res,
this);
700 #if __cplusplus >= 201103L
701 return { _Base::begin() + (__first.base() - _Base::cbegin()),
this };
709 _GLIBCXX_NOEXCEPT_IF( noexcept(declval<_Base&>().swap(__x)) )
713 std::swap(this->_M_guaranteed_capacity, __x._M_guaranteed_capacity);
717 clear() _GLIBCXX_NOEXCEPT
724 _M_base() _GLIBCXX_NOEXCEPT {
return *
this; }
727 _M_base() const _GLIBCXX_NOEXCEPT {
return *
this; }
731 _M_invalidate_after_nth(difference_type __n) _GLIBCXX_NOEXCEPT
738 template<
typename _Tp,
typename _Alloc>
740 operator==(
const vector<_Tp, _Alloc>& __lhs,
741 const vector<_Tp, _Alloc>& __rhs)
742 {
return __lhs._M_base() == __rhs._M_base(); }
744 #if __cpp_lib_three_way_comparison
745 template<
typename _Tp,
typename _Alloc>
746 constexpr __detail::__synth3way_t<_Tp>
747 operator<=>(
const vector<_Tp, _Alloc>& __x,
const vector<_Tp, _Alloc>& __y)
748 {
return __x._M_base() <=> __y._M_base(); }
750 template<
typename _Tp,
typename _Alloc>
752 operator!=(
const vector<_Tp, _Alloc>& __lhs,
753 const vector<_Tp, _Alloc>& __rhs)
754 {
return __lhs._M_base() != __rhs._M_base(); }
756 template<
typename _Tp,
typename _Alloc>
758 operator<(
const vector<_Tp, _Alloc>& __lhs,
759 const vector<_Tp, _Alloc>& __rhs)
760 {
return __lhs._M_base() < __rhs._M_base(); }
762 template<
typename _Tp,
typename _Alloc>
764 operator<=(
const vector<_Tp, _Alloc>& __lhs,
765 const vector<_Tp, _Alloc>& __rhs)
766 {
return __lhs._M_base() <= __rhs._M_base(); }
768 template<
typename _Tp,
typename _Alloc>
770 operator>=(
const vector<_Tp, _Alloc>& __lhs,
771 const vector<_Tp, _Alloc>& __rhs)
772 {
return __lhs._M_base() >= __rhs._M_base(); }
774 template<
typename _Tp,
typename _Alloc>
776 operator>(
const vector<_Tp, _Alloc>& __lhs,
777 const vector<_Tp, _Alloc>& __rhs)
778 {
return __lhs._M_base() > __rhs._M_base(); }
781 template<
typename _Tp,
typename _Alloc>
783 swap(vector<_Tp, _Alloc>& __lhs, vector<_Tp, _Alloc>& __rhs)
784 _GLIBCXX_NOEXCEPT_IF(noexcept(__lhs.swap(__rhs)))
785 { __lhs.swap(__rhs); }
787 #if __cpp_deduction_guides >= 201606
788 template<
typename _InputIterator,
typename _ValT
789 =
typename iterator_traits<_InputIterator>::value_type,
790 typename _Allocator = allocator<_ValT>,
791 typename = _RequireInputIter<_InputIterator>,
792 typename = _RequireAllocator<_Allocator>>
793 vector(_InputIterator, _InputIterator, _Allocator = _Allocator())
794 -> vector<_ValT, _Allocator>;
799 _GLIBCXX_BEGIN_NAMESPACE_VERSION
801 #if __cplusplus >= 201103L
804 template<
typename _Alloc>
806 :
public __hash_base<size_t, __debug::vector<bool, _Alloc>>
814 #if __cplusplus >= 201703L
815 namespace __detail::__variant
817 template<
typename>
struct _Never_valueless_alt;
821 template<
typename _Tp,
typename _Alloc>
822 struct _Never_valueless_alt<__debug::
vector<_Tp, _Alloc>>
828 _GLIBCXX_END_NAMESPACE_VERSION
833 template<
typename _Tp,
typename _Alloc>
834 struct _Is_contiguous_sequence<
std::__debug::vector<_Tp, _Alloc> >
838 template<
typename _Alloc>
839 struct _Is_contiguous_sequence<
std::__debug::vector<bool, _Alloc> >
#define __glibcxx_check_insert(_Position)
#define __glibcxx_check_erase_range(_First, _Last)
#define __glibcxx_check_erase(_Position)
#define __glibcxx_check_insert_range(_Position, _First, _Last, _Dist)
_T2 second
The second member.
constexpr std::remove_reference< _Tp >::type && move(_Tp &&__t) noexcept
Convert a value to an rvalue.
void swap(any &__x, any &__y) noexcept
Exchange the states of two any objects.
ISO C++ entities toplevel namespace is std.
constexpr auto empty(const _Container &__cont) noexcept(noexcept(__cont.empty())) -> decltype(__cont.empty())
Return whether a container is empty.
constexpr auto size(const _Container &__cont) noexcept(noexcept(__cont.size())) -> decltype(__cont.size())
Return the size of a container.
constexpr auto data(_Container &__cont) noexcept(noexcept(__cont.data())) -> decltype(__cont.data())
Return the data pointer of a container.
GNU debug classes for public use.
constexpr _Iterator __base(_Iterator __it)
Primary class template hash.
is_nothrow_move_assignable
The standard allocator, as per [20.4].
Struct holding two objects of arbitrary type.
A standard container which offers fixed time access to individual elements in any order.
Base class for constructing a safe sequence type that tracks iterators that reference it.
void _M_invalidate_if(_Predicate __pred)
void _M_invalidate_all() const
Safe class dealing with some allocator dependent operations.
Class std::vector with safety/checking/debug instrumentation.
vector(_Base_ref __x)
Construction from a normal-mode vector.
Base class for Debug Mode vector.