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())
183 : _Base(__gnu_debug::__base(__gnu_debug::__check_valid_range(__first,
185 __gnu_debug::__base(__last), __a) { }
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;
235 this->_M_invalidate_all();
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)
251 __glibcxx_check_valid_range2(__first, __last, __dist);
253 if (__dist.
second >= __gnu_debug::__dp_sign)
254 _Base::assign(__gnu_debug::__unsafe(__first),
255 __gnu_debug::__unsafe(__last));
257 _Base::assign(__first, __last);
259 this->_M_invalidate_all();
260 this->_M_update_guaranteed_capacity();
264 assign(size_type __n,
const _Tp& __u)
266 _Base::assign(__n, __u);
267 this->_M_invalidate_all();
268 this->_M_update_guaranteed_capacity();
271 #if __cplusplus >= 201103L 276 this->_M_invalidate_all();
277 this->_M_update_guaranteed_capacity();
281 using _Base::get_allocator;
285 begin() _GLIBCXX_NOEXCEPT
289 begin()
const _GLIBCXX_NOEXCEPT
293 end() _GLIBCXX_NOEXCEPT
297 end()
const _GLIBCXX_NOEXCEPT
298 {
return const_iterator(
_Base::end(),
this); }
301 rbegin() _GLIBCXX_NOEXCEPT
302 {
return reverse_iterator(
end()); }
304 const_reverse_iterator
305 rbegin()
const _GLIBCXX_NOEXCEPT
306 {
return const_reverse_iterator(
end()); }
309 rend() _GLIBCXX_NOEXCEPT
310 {
return reverse_iterator(
begin()); }
312 const_reverse_iterator
313 rend()
const _GLIBCXX_NOEXCEPT
314 {
return const_reverse_iterator(
begin()); }
316 #if __cplusplus >= 201103L 322 cend()
const noexcept
323 {
return const_iterator(
_Base::end(),
this); }
325 const_reverse_iterator
327 {
return const_reverse_iterator(
end()); }
329 const_reverse_iterator
330 crend()
const noexcept
331 {
return const_reverse_iterator(
begin()); }
336 using _Base::max_size;
338 #if __cplusplus >= 201103L 340 resize(size_type __sz)
342 bool __realloc = this->_M_requires_reallocation(__sz);
343 if (__sz < this->size())
344 this->_M_invalidate_after_nth(__sz);
347 this->_M_invalidate_all();
348 this->_M_update_guaranteed_capacity();
352 resize(size_type __sz,
const _Tp& __c)
354 bool __realloc = this->_M_requires_reallocation(__sz);
355 if (__sz < this->size())
356 this->_M_invalidate_after_nth(__sz);
357 _Base::resize(__sz, __c);
359 this->_M_invalidate_all();
360 this->_M_update_guaranteed_capacity();
364 resize(size_type __sz, _Tp __c = _Tp())
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 #if __cplusplus >= 201103L 380 if (_Base::_M_shrink_to_fit())
382 this->_M_guaranteed_capacity = _Base::capacity();
383 this->_M_invalidate_all();
389 capacity()
const _GLIBCXX_NOEXCEPT
391 #ifdef _GLIBCXX_DEBUG_PEDANTIC 392 return this->_M_guaranteed_capacity;
394 return _Base::capacity();
401 reserve(size_type __n)
403 bool __realloc = this->_M_requires_reallocation(__n);
405 if (__n > this->_M_guaranteed_capacity)
406 this->_M_guaranteed_capacity = __n;
408 this->_M_invalidate_all();
413 operator[](size_type __n) _GLIBCXX_NOEXCEPT
415 __glibcxx_check_subscript(__n);
416 return _M_base()[__n];
420 operator[](size_type __n)
const _GLIBCXX_NOEXCEPT
422 __glibcxx_check_subscript(__n);
423 return _M_base()[__n];
429 front() _GLIBCXX_NOEXCEPT
431 __glibcxx_check_nonempty();
432 return _Base::front();
436 front()
const _GLIBCXX_NOEXCEPT
438 __glibcxx_check_nonempty();
439 return _Base::front();
443 back() _GLIBCXX_NOEXCEPT
445 __glibcxx_check_nonempty();
446 return _Base::back();
450 back()
const _GLIBCXX_NOEXCEPT
452 __glibcxx_check_nonempty();
453 return _Base::back();
462 push_back(
const _Tp& __x)
464 bool __realloc = this->_M_requires_reallocation(this->size() + 1);
465 _Base::push_back(__x);
467 this->_M_invalidate_all();
468 this->_M_update_guaranteed_capacity();
471 #if __cplusplus >= 201103L 472 template<
typename _Up = _Tp>
473 typename __gnu_cxx::__enable_if<!std::__are_same<_Up, bool>::__value,
476 { emplace_back(std::move(__x)); }
478 template<
typename... _Args>
480 emplace_back(_Args&&... __args)
482 bool __realloc = this->_M_requires_reallocation(this->size() + 1);
483 _Base::emplace_back(std::forward<_Args>(__args)...);
485 this->_M_invalidate_all();
486 this->_M_update_guaranteed_capacity();
491 pop_back() _GLIBCXX_NOEXCEPT
493 __glibcxx_check_nonempty();
494 this->_M_invalidate_if(_Equal(--
_Base::end()));
498 #if __cplusplus >= 201103L 499 template<
typename... _Args>
501 emplace(const_iterator __position, _Args&&... __args)
504 bool __realloc = this->_M_requires_reallocation(this->size() + 1);
506 _Base_iterator __res = _Base::emplace(__position.
base(),
507 std::forward<_Args>(__args)...);
509 this->_M_invalidate_all();
511 this->_M_invalidate_after_nth(__offset);
512 this->_M_update_guaranteed_capacity();
513 return iterator(__res,
this);
518 #if __cplusplus >= 201103L 519 insert(const_iterator __position,
const _Tp& __x)
521 insert(iterator __position,
const _Tp& __x)
525 bool __realloc = this->_M_requires_reallocation(this->size() + 1);
527 _Base_iterator __res = _Base::insert(__position.
base(), __x);
529 this->_M_invalidate_all();
531 this->_M_invalidate_after_nth(__offset);
532 this->_M_update_guaranteed_capacity();
533 return iterator(__res,
this);
536 #if __cplusplus >= 201103L 537 template<
typename _Up = _Tp>
538 typename __gnu_cxx::__enable_if<!std::__are_same<_Up, bool>::__value,
540 insert(const_iterator __position, _Tp&& __x)
541 {
return emplace(__position, std::move(__x)); }
545 {
return this->insert(__position, __l.begin(), __l.end()); }
548 #if __cplusplus >= 201103L 550 insert(const_iterator __position, size_type __n,
const _Tp& __x)
553 bool __realloc = this->_M_requires_reallocation(this->size() + __n);
555 _Base_iterator __res = _Base::insert(__position.
base(), __n, __x);
557 this->_M_invalidate_all();
559 this->_M_invalidate_after_nth(__offset);
560 this->_M_update_guaranteed_capacity();
561 return iterator(__res,
this);
565 insert(iterator __position, size_type __n,
const _Tp& __x)
568 bool __realloc = this->_M_requires_reallocation(this->size() + __n);
570 _Base::insert(__position.
base(), __n, __x);
572 this->_M_invalidate_all();
574 this->_M_invalidate_after_nth(__offset);
575 this->_M_update_guaranteed_capacity();
579 #if __cplusplus >= 201103L 580 template<
class _InputIterator,
581 typename = std::_RequireInputIter<_InputIterator>>
583 insert(const_iterator __position,
584 _InputIterator __first, _InputIterator __last)
592 _Base_iterator __old_begin = _M_base().begin();
594 _Base_iterator __res;
595 if (__dist.
second >= __gnu_debug::__dp_sign)
596 __res = _Base::insert(__position.
base(),
597 __gnu_debug::__unsafe(__first),
598 __gnu_debug::__unsafe(__last));
600 __res = _Base::insert(__position.
base(), __first, __last);
602 if (_M_base().begin() != __old_begin)
603 this->_M_invalidate_all();
605 this->_M_invalidate_after_nth(__offset);
606 this->_M_update_guaranteed_capacity();
607 return iterator(__res,
this);
610 template<
class _InputIterator>
612 insert(iterator __position,
613 _InputIterator __first, _InputIterator __last)
621 _Base_iterator __old_begin = _M_base().begin();
623 if (__dist.
second >= __gnu_debug::__dp_sign)
624 _Base::insert(__position.
base(), __gnu_debug::__unsafe(__first),
625 __gnu_debug::__unsafe(__last));
627 _Base::insert(__position.
base(), __first, __last);
629 if (_M_base().begin() != __old_begin)
630 this->_M_invalidate_all();
632 this->_M_invalidate_after_nth(__offset);
633 this->_M_update_guaranteed_capacity();
638 #if __cplusplus >= 201103L 639 erase(const_iterator __position)
641 erase(iterator __position)
646 _Base_iterator __res = _Base::erase(__position.
base());
647 this->_M_invalidate_after_nth(__offset);
648 return iterator(__res,
this);
652 #if __cplusplus >= 201103L 653 erase(const_iterator __first, const_iterator __last)
655 erase(iterator __first, iterator __last)
662 if (__first.
base() != __last.
base())
665 _Base_iterator __res = _Base::erase(__first.
base(),
667 this->_M_invalidate_after_nth(__offset);
668 return iterator(__res,
this);
671 #if __cplusplus >= 201103L 680 _GLIBCXX_NOEXCEPT_IF( noexcept(declval<_Base&>().swap(__x)) )
684 std::swap(this->_M_guaranteed_capacity, __x._M_guaranteed_capacity);
688 clear() _GLIBCXX_NOEXCEPT
691 this->_M_invalidate_all();
695 _M_base() _GLIBCXX_NOEXCEPT {
return *
this; }
698 _M_base()
const _GLIBCXX_NOEXCEPT {
return *
this; }
702 _M_invalidate_after_nth(difference_type __n) _GLIBCXX_NOEXCEPT
705 this->_M_invalidate_if(_After_nth(__n,
_Base::begin()));
709 template<
typename _Tp,
typename _Alloc>
713 {
return __lhs._M_base() == __rhs._M_base(); }
715 template<
typename _Tp,
typename _Alloc>
719 {
return __lhs._M_base() != __rhs._M_base(); }
721 template<
typename _Tp,
typename _Alloc>
723 operator<(const vector<_Tp, _Alloc>& __lhs,
725 {
return __lhs._M_base() < __rhs._M_base(); }
727 template<
typename _Tp,
typename _Alloc>
729 operator<=(const vector<_Tp, _Alloc>& __lhs,
731 {
return __lhs._M_base() <= __rhs._M_base(); }
733 template<
typename _Tp,
typename _Alloc>
737 {
return __lhs._M_base() >= __rhs._M_base(); }
739 template<
typename _Tp,
typename _Alloc>
743 {
return __lhs._M_base() > __rhs._M_base(); }
745 template<
typename _Tp,
typename _Alloc>
748 _GLIBCXX_NOEXCEPT_IF(noexcept(__lhs.swap(__rhs)))
749 { __lhs.swap(__rhs); }
753 #if __cplusplus >= 201103L 756 template<
typename _Alloc>
758 :
public __hash_base<size_t, __debug::vector<bool, _Alloc>>
770 template<
typename _Tp,
typename _Alloc>
775 template<
typename _Alloc>
The standard allocator, as per [20.4].
GNU debug classes for public use.
auto crbegin(const _Container &__cont) -> decltype(std::rbegin(__cont))
Return a reverse iterator pointing to the last element of the const container.
auto rbegin(_Container &__cont) -> decltype(__cont.rbegin())
Return a reverse iterator pointing to the last element of the container.
Base class for constructing a safe sequence type that tracks iterators that reference it...
auto crend(const _Container &__cont) -> decltype(std::rend(__cont))
Return a reverse iterator pointing one past the first element of the const container.
vector(const _Base &__x)
Construction from a normal-mode vector.
#define __glibcxx_check_erase_range(_First, _Last)
constexpr const _Tp * begin(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to the first element of the initializer_list.
Base class for Debug Mode vector.
Safe class dealing with some allocator dependent operations.
constexpr auto cend(const _Container &__cont) noexcept(noexcept(std::end(__cont))) -> decltype(std::end(__cont))
Return an iterator pointing to one past the last element of the const container.
auto rend(_Container &__cont) -> decltype(__cont.rend())
Return a reverse iterator pointing one past the first element of the container.
#define __glibcxx_check_erase(_Position)
constexpr auto cbegin(const _Container &__cont) noexcept(noexcept(std::begin(__cont))) -> decltype(std::begin(__cont))
Return an iterator pointing to the first element of the const container.
ISO C++ entities toplevel namespace is std.
A standard container which offers fixed time access to individual elements in any order...
_Iterator & base() noexcept
Return the underlying iterator.
Primary class template hash.
constexpr const _Tp * end(initializer_list< _Tp > __ils) noexcept
Return an iterator pointing to one past the last element of the initializer_list. ...
#define __glibcxx_check_insert_range(_Position, _First, _Last, _Dist)
#define __glibcxx_check_insert(_Position)
Class std::vector with safety/checking/debug instrumentation.
Struct holding two objects of arbitrary type.
_T2 second
first is a copy of the first object