29 #ifndef _GLIBCXX_DEBUG_VECTOR
30 #define _GLIBCXX_DEBUG_VECTOR 1
43 template<
typename _SafeSequence,
44 typename _BaseSequence>
47 typedef typename _BaseSequence::size_type size_type;
50 _M_seq()
const {
return *
static_cast<const _SafeSequence*
>(
this); }
54 : _M_guaranteed_capacity(0)
55 { _M_update_guaranteed_capacity(); }
58 : _M_guaranteed_capacity(0)
59 { _M_update_guaranteed_capacity(); }
62 : _M_guaranteed_capacity(__n)
65 #if __cplusplus >= 201103L
68 { __x._M_guaranteed_capacity = 0; }
73 _M_update_guaranteed_capacity();
80 _M_update_guaranteed_capacity();
81 __x._M_guaranteed_capacity = 0;
86 size_type _M_guaranteed_capacity;
89 _M_requires_reallocation(size_type __elements)
const _GLIBCXX_NOEXCEPT
90 {
return __elements > _M_seq().capacity(); }
93 _M_update_guaranteed_capacity() _GLIBCXX_NOEXCEPT
95 if (_M_seq().
size() > _M_guaranteed_capacity)
96 _M_guaranteed_capacity = _M_seq().size();
101 namespace std _GLIBCXX_VISIBILITY(default)
106 template<
typename _Tp,
110 vector<_Tp, _Allocator>, _Allocator, __gnu_debug::_Safe_sequence>,
111 public _GLIBCXX_STD_C::vector<_Tp, _Allocator>,
113 vector<_Tp, _Allocator>,
114 _GLIBCXX_STD_C::vector<_Tp, _Allocator> >
116 typedef _GLIBCXX_STD_C::vector<_Tp, _Allocator>
_Base;
126 typedef typename _Base::reference reference;
127 typedef typename _Base::const_reference const_reference;
134 typedef typename _Base::size_type size_type;
135 typedef typename _Base::difference_type difference_type;
137 typedef _Tp value_type;
138 typedef _Allocator allocator_type;
139 typedef typename _Base::pointer pointer;
140 typedef typename _Base::const_pointer const_pointer;
146 #if __cplusplus < 201103L
147 vector() _GLIBCXX_NOEXCEPT
154 vector(
const _Allocator& __a) _GLIBCXX_NOEXCEPT
157 #if __cplusplus >= 201103L
159 vector(size_type __n,
const _Allocator& __a = _Allocator())
162 vector(size_type __n,
const _Tp& __value,
163 const _Allocator& __a = _Allocator())
164 :
_Base(__n, __value, __a) { }
167 vector(size_type __n,
const _Tp& __value = _Tp(),
168 const _Allocator& __a = _Allocator())
169 :
_Base(__n, __value, __a) { }
172 #if __cplusplus >= 201103L
173 template<
class _InputIterator,
174 typename = std::_RequireInputIter<_InputIterator>>
176 template<
class _InputIterator>
178 vector(_InputIterator __first, _InputIterator __last,
179 const _Allocator& __a = _Allocator())
184 #if __cplusplus < 201103L
185 vector(
const vector& __x)
188 ~vector() _GLIBCXX_NOEXCEPT { }
190 vector(
const vector&) =
default;
191 vector(vector&&) =
default;
193 vector(
const vector& __x,
const allocator_type& __a)
194 :
_Base(__x, __a) { }
196 vector(vector&& __x,
const allocator_type& __a)
197 :
_Safe(std::move(__x._M_safe()), __a),
198 _Base(std::move(__x._M_base()), __a),
202 const allocator_type& __a = allocator_type())
203 :
_Base(__l, __a) { }
212 #if __cplusplus < 201103L
214 operator=(
const vector& __x)
216 this->_M_safe() = __x;
218 this->_M_update_guaranteed_capacity();
223 operator=(
const vector&) =
default;
226 operator=(vector&&) =
default;
232 this->_M_invalidate_all();
233 this->_M_update_guaranteed_capacity();
238 #if __cplusplus >= 201103L
239 template<
typename _InputIterator,
240 typename = std::_RequireInputIter<_InputIterator>>
242 template<
typename _InputIterator>
245 assign(_InputIterator __first, _InputIterator __last)
247 __glibcxx_check_valid_range(__first, __last);
250 this->_M_invalidate_all();
251 this->_M_update_guaranteed_capacity();
255 assign(size_type __n,
const _Tp& __u)
257 _Base::assign(__n, __u);
258 this->_M_invalidate_all();
259 this->_M_update_guaranteed_capacity();
262 #if __cplusplus >= 201103L
264 assign(initializer_list<value_type> __l)
267 this->_M_invalidate_all();
268 this->_M_update_guaranteed_capacity();
272 using _Base::get_allocator;
276 begin() _GLIBCXX_NOEXCEPT
277 {
return iterator(_Base::begin(),
this); }
280 begin() const _GLIBCXX_NOEXCEPT
281 {
return const_iterator(_Base::begin(),
this); }
284 end() _GLIBCXX_NOEXCEPT
285 {
return iterator(_Base::end(),
this); }
288 end() const _GLIBCXX_NOEXCEPT
289 {
return const_iterator(_Base::end(),
this); }
292 rbegin() _GLIBCXX_NOEXCEPT
293 {
return reverse_iterator(end()); }
295 const_reverse_iterator
296 rbegin() const _GLIBCXX_NOEXCEPT
297 {
return const_reverse_iterator(end()); }
300 rend() _GLIBCXX_NOEXCEPT
301 {
return reverse_iterator(begin()); }
303 const_reverse_iterator
304 rend() const _GLIBCXX_NOEXCEPT
305 {
return const_reverse_iterator(begin()); }
307 #if __cplusplus >= 201103L
309 cbegin() const noexcept
310 {
return const_iterator(_Base::begin(),
this); }
313 cend() const noexcept
314 {
return const_iterator(_Base::end(),
this); }
316 const_reverse_iterator
317 crbegin() const noexcept
318 {
return const_reverse_iterator(end()); }
320 const_reverse_iterator
321 crend() const noexcept
322 {
return const_reverse_iterator(begin()); }
327 using _Base::max_size;
329 #if __cplusplus >= 201103L
331 resize(size_type __sz)
333 bool __realloc = this->_M_requires_reallocation(__sz);
334 if (__sz < this->
size())
335 this->_M_invalidate_after_nth(__sz);
338 this->_M_invalidate_all();
339 this->_M_update_guaranteed_capacity();
343 resize(size_type __sz,
const _Tp& __c)
345 bool __realloc = this->_M_requires_reallocation(__sz);
346 if (__sz < this->
size())
347 this->_M_invalidate_after_nth(__sz);
348 _Base::resize(__sz, __c);
350 this->_M_invalidate_all();
351 this->_M_update_guaranteed_capacity();
355 resize(size_type __sz, _Tp __c = _Tp())
357 bool __realloc = this->_M_requires_reallocation(__sz);
358 if (__sz < this->
size())
359 this->_M_invalidate_after_nth(__sz);
360 _Base::resize(__sz, __c);
362 this->_M_invalidate_all();
363 this->_M_update_guaranteed_capacity();
367 #if __cplusplus >= 201103L
371 if (_Base::_M_shrink_to_fit())
373 this->_M_guaranteed_capacity = _Base::capacity();
374 this->_M_invalidate_all();
380 capacity() const _GLIBCXX_NOEXCEPT
382 #ifdef _GLIBCXX_DEBUG_PEDANTIC
383 return this->_M_guaranteed_capacity;
385 return _Base::capacity();
392 reserve(size_type __n)
394 bool __realloc = this->_M_requires_reallocation(__n);
396 if (__n > this->_M_guaranteed_capacity)
397 this->_M_guaranteed_capacity = __n;
399 this->_M_invalidate_all();
404 operator[](size_type __n) _GLIBCXX_NOEXCEPT
406 __glibcxx_check_subscript(__n);
407 return _M_base()[__n];
411 operator[](size_type __n)
const _GLIBCXX_NOEXCEPT
413 __glibcxx_check_subscript(__n);
414 return _M_base()[__n];
420 front() _GLIBCXX_NOEXCEPT
422 __glibcxx_check_nonempty();
423 return _Base::front();
427 front() const _GLIBCXX_NOEXCEPT
429 __glibcxx_check_nonempty();
430 return _Base::front();
434 back() _GLIBCXX_NOEXCEPT
436 __glibcxx_check_nonempty();
437 return _Base::back();
441 back() const _GLIBCXX_NOEXCEPT
443 __glibcxx_check_nonempty();
444 return _Base::back();
453 push_back(
const _Tp& __x)
455 bool __realloc = this->_M_requires_reallocation(this->
size() + 1);
456 _Base::push_back(__x);
458 this->_M_invalidate_all();
459 this->_M_update_guaranteed_capacity();
462 #if __cplusplus >= 201103L
463 template<
typename _Up = _Tp>
464 typename __gnu_cxx::__enable_if<!std::__are_same<_Up, bool>::__value,
467 { emplace_back(std::move(__x)); }
469 template<
typename... _Args>
471 emplace_back(_Args&&... __args)
473 bool __realloc = this->_M_requires_reallocation(this->
size() + 1);
474 _Base::emplace_back(std::forward<_Args>(__args)...);
476 this->_M_invalidate_all();
477 this->_M_update_guaranteed_capacity();
482 pop_back() _GLIBCXX_NOEXCEPT
484 __glibcxx_check_nonempty();
489 #if __cplusplus >= 201103L
490 template<
typename... _Args>
492 emplace(const_iterator __position, _Args&&... __args)
495 bool __realloc = this->_M_requires_reallocation(this->
size() + 1);
496 difference_type __offset = __position.base() - _Base::begin();
497 _Base_iterator __res = _Base::emplace(__position.base(),
498 std::forward<_Args>(__args)...);
500 this->_M_invalidate_all();
502 this->_M_invalidate_after_nth(__offset);
503 this->_M_update_guaranteed_capacity();
504 return iterator(__res,
this);
509 #if __cplusplus >= 201103L
510 insert(const_iterator __position,
const _Tp& __x)
512 insert(iterator __position,
const _Tp& __x)
516 bool __realloc = this->_M_requires_reallocation(this->
size() + 1);
517 difference_type __offset = __position.base() - _Base::begin();
518 _Base_iterator __res = _Base::insert(__position.base(), __x);
520 this->_M_invalidate_all();
522 this->_M_invalidate_after_nth(__offset);
523 this->_M_update_guaranteed_capacity();
524 return iterator(__res,
this);
527 #if __cplusplus >= 201103L
528 template<
typename _Up = _Tp>
529 typename __gnu_cxx::__enable_if<!std::__are_same<_Up, bool>::__value,
531 insert(const_iterator __position, _Tp&& __x)
532 {
return emplace(__position, std::move(__x)); }
535 insert(const_iterator __position, initializer_list<value_type> __l)
536 {
return this->insert(__position, __l.begin(), __l.end()); }
539 #if __cplusplus >= 201103L
541 insert(const_iterator __position, size_type __n,
const _Tp& __x)
544 bool __realloc = this->_M_requires_reallocation(this->
size() + __n);
545 difference_type __offset = __position.base() - _Base::cbegin();
546 _Base_iterator __res = _Base::insert(__position.base(), __n, __x);
548 this->_M_invalidate_all();
550 this->_M_invalidate_after_nth(__offset);
551 this->_M_update_guaranteed_capacity();
552 return iterator(__res,
this);
556 insert(iterator __position, size_type __n,
const _Tp& __x)
559 bool __realloc = this->_M_requires_reallocation(this->
size() + __n);
560 difference_type __offset = __position.base() - _Base::begin();
561 _Base::insert(__position.base(), __n, __x);
563 this->_M_invalidate_all();
565 this->_M_invalidate_after_nth(__offset);
566 this->_M_update_guaranteed_capacity();
570 #if __cplusplus >= 201103L
571 template<
class _InputIterator,
572 typename = std::_RequireInputIter<_InputIterator>>
574 insert(const_iterator __position,
575 _InputIterator __first, _InputIterator __last)
582 _Base_iterator __old_begin = _M_base().begin();
583 difference_type __offset = __position.base() - _Base::cbegin();
584 _Base_iterator __res = _Base::insert(__position.base(),
588 if (_M_base().begin() != __old_begin)
589 this->_M_invalidate_all();
591 this->_M_invalidate_after_nth(__offset);
592 this->_M_update_guaranteed_capacity();
593 return iterator(__res,
this);
596 template<
class _InputIterator>
598 insert(iterator __position,
599 _InputIterator __first, _InputIterator __last)
606 _Base_iterator __old_begin = _M_base().begin();
607 difference_type __offset = __position.base() - _Base::begin();
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();
620 #if __cplusplus >= 201103L
621 erase(const_iterator __position)
623 erase(iterator __position)
627 difference_type __offset = __position.base() - _Base::begin();
628 _Base_iterator __res = _Base::erase(__position.base());
629 this->_M_invalidate_after_nth(__offset);
630 return iterator(__res,
this);
634 #if __cplusplus >= 201103L
635 erase(const_iterator __first, const_iterator __last)
637 erase(iterator __first, iterator __last)
644 if (__first.base() != __last.base())
646 difference_type __offset = __first.base() - _Base::begin();
647 _Base_iterator __res = _Base::erase(__first.base(),
649 this->_M_invalidate_after_nth(__offset);
650 return iterator(__res,
this);
653 #if __cplusplus >= 201103L
654 return begin() + (__first.base() - cbegin().
base());
662 #if __cplusplus >= 201103L
663 noexcept( noexcept(declval<_Base>().
swap(__x)) )
668 std::swap(this->_M_guaranteed_capacity, __x._M_guaranteed_capacity);
672 clear() _GLIBCXX_NOEXCEPT
675 this->_M_invalidate_all();
679 _M_base() _GLIBCXX_NOEXCEPT {
return *
this; }
682 _M_base() const _GLIBCXX_NOEXCEPT {
return *
this; }
686 _M_invalidate_after_nth(difference_type __n) _GLIBCXX_NOEXCEPT
693 template<
typename _Tp,
typename _Alloc>
695 operator==(
const vector<_Tp, _Alloc>& __lhs,
696 const vector<_Tp, _Alloc>& __rhs)
697 {
return __lhs._M_base() == __rhs._M_base(); }
699 template<
typename _Tp,
typename _Alloc>
701 operator!=(
const vector<_Tp, _Alloc>& __lhs,
702 const vector<_Tp, _Alloc>& __rhs)
703 {
return __lhs._M_base() != __rhs._M_base(); }
705 template<
typename _Tp,
typename _Alloc>
707 operator<(const vector<_Tp, _Alloc>& __lhs,
708 const vector<_Tp, _Alloc>& __rhs)
709 {
return __lhs._M_base() < __rhs._M_base(); }
711 template<
typename _Tp,
typename _Alloc>
713 operator<=(const vector<_Tp, _Alloc>& __lhs,
714 const vector<_Tp, _Alloc>& __rhs)
715 {
return __lhs._M_base() <= __rhs._M_base(); }
717 template<
typename _Tp,
typename _Alloc>
719 operator>=(
const vector<_Tp, _Alloc>& __lhs,
720 const vector<_Tp, _Alloc>& __rhs)
721 {
return __lhs._M_base() >= __rhs._M_base(); }
723 template<
typename _Tp,
typename _Alloc>
725 operator>(
const vector<_Tp, _Alloc>& __lhs,
726 const vector<_Tp, _Alloc>& __rhs)
727 {
return __lhs._M_base() > __rhs._M_base(); }
729 template<
typename _Tp,
typename _Alloc>
731 swap(vector<_Tp, _Alloc>& __lhs, vector<_Tp, _Alloc>& __rhs)
732 { __lhs.swap(__rhs); }
736 #if __cplusplus >= 201103L
739 template<
typename _Alloc>
740 struct hash<__debug::vector<bool, _Alloc>>
741 :
public __hash_base<size_t, __debug::vector<bool, _Alloc>>
752 namespace __gnu_debug
754 template<
typename _Tp,
typename _Alloc>
755 struct _Is_contiguous_sequence<std::__debug::vector<_Tp, _Alloc> >
759 template<
typename _Alloc>
760 struct _Is_contiguous_sequence<std::__debug::vector<bool, _Alloc> >
void swap(basic_filebuf< _CharT, _Traits > &__x, basic_filebuf< _CharT, _Traits > &__y)
Swap specialization for filebufs.
#define __glibcxx_check_insert(_Position)
Primary class template hash.
#define __glibcxx_check_erase(_Position)
The standard allocator, as per [20.4].
void _M_invalidate_if(_Predicate __pred)
Special vector safe base class to add a guaranteed capacity information useful to detect code relying...
_Iterator & base() noexcept
Return the underlying iterator.
#define __glibcxx_check_insert_range(_Position, _First, _Last)
vector(const _Base &__x)
Construction from a normal-mode vector.
_Siter_base< _Iterator >::iterator_type __base(_Iterator __it)
Base class for constructing a safe sequence type that tracks iterators that reference it...
Class std::vector with safety/checking/debug instrumentation.
#define __glibcxx_check_erase_range(_First, _Last)
constexpr size_t size() const noexcept
Returns the total number of bits.
Safe class dealing with some allocator dependent operations.