30 #ifndef _GLIBCXX_DEBUG_VECTOR
31 #define _GLIBCXX_DEBUG_VECTOR 1
38 namespace std _GLIBCXX_VISIBILITY(default)
43 template<
typename _Tp,
46 :
public _GLIBCXX_STD_C::vector<_Tp, _Allocator>,
49 typedef _GLIBCXX_STD_C::vector<_Tp, _Allocator>
_Base;
55 #ifdef __GXX_EXPERIMENTAL_CXX0X__
60 typedef typename _Base::reference reference;
61 typedef typename _Base::const_reference const_reference;
68 typedef typename _Base::size_type size_type;
69 typedef typename _Base::difference_type difference_type;
71 typedef _Tp value_type;
72 typedef _Allocator allocator_type;
73 typedef typename _Base::pointer pointer;
74 typedef typename _Base::const_pointer const_pointer;
80 vector(
const _Allocator& __a = _Allocator())
81 :
_Base(__a), _M_guaranteed_capacity(0) { }
83 #ifdef __GXX_EXPERIMENTAL_CXX0X__
86 :
_Base(__n), _M_guaranteed_capacity(__n) { }
88 vector(size_type __n,
const _Tp& __value,
89 const _Allocator& __a = _Allocator())
90 :
_Base(__n, __value, __a), _M_guaranteed_capacity(__n) { }
93 vector(size_type __n,
const _Tp& __value = _Tp(),
94 const _Allocator& __a = _Allocator())
95 :
_Base(__n, __value, __a), _M_guaranteed_capacity(__n) { }
98 template<
class _InputIterator>
99 vector(_InputIterator __first, _InputIterator __last,
100 const _Allocator& __a = _Allocator())
104 _M_guaranteed_capacity(0)
105 { _M_update_guaranteed_capacity(); }
108 :
_Base(__x), _M_guaranteed_capacity(__x.size()) { }
112 :
_Base(__x), _M_guaranteed_capacity(__x.
size()) { }
114 #ifdef __GXX_EXPERIMENTAL_CXX0X__
116 : _Base(std::move(__x)),
117 _M_guaranteed_capacity(this->
size())
120 __x._M_guaranteed_capacity = 0;
124 : _Base(__x, __a), _M_guaranteed_capacity(__x.
size()) { }
126 vector(vector&& __x,
const allocator_type& __a)
127 : _Base(std::move(__x), __a),
128 _M_guaranteed_capacity(this->
size())
131 __x._M_guaranteed_capacity = 0;
134 vector(initializer_list<value_type> __l,
135 const allocator_type& __a = allocator_type())
137 _M_guaranteed_capacity(__l.
size()) { }
140 ~vector() _GLIBCXX_NOEXCEPT { }
143 operator=(
const vector& __x)
145 static_cast<_Base&
>(*this) = __x;
147 _M_update_guaranteed_capacity();
151 #ifdef __GXX_EXPERIMENTAL_CXX0X__
153 operator=(vector&& __x) noexcept(_Alloc_traits::_S_nothrow_move())
155 _Base::operator=(std::move(__x));
157 _M_update_guaranteed_capacity();
159 __x._M_guaranteed_capacity = 0;
164 operator=(initializer_list<value_type> __l)
166 static_cast<_Base&
>(*this) = __l;
168 _M_update_guaranteed_capacity();
173 template<
typename _InputIterator>
175 assign(_InputIterator __first, _InputIterator __last)
177 __glibcxx_check_valid_range(__first, __last);
181 _M_update_guaranteed_capacity();
185 assign(size_type __n,
const _Tp& __u)
187 _Base::assign(__n, __u);
189 _M_update_guaranteed_capacity();
192 #ifdef __GXX_EXPERIMENTAL_CXX0X__
194 assign(initializer_list<value_type> __l)
198 _M_update_guaranteed_capacity();
202 using _Base::get_allocator;
206 begin() _GLIBCXX_NOEXCEPT
207 {
return iterator(_Base::begin(),
this); }
210 begin() const _GLIBCXX_NOEXCEPT
211 {
return const_iterator(_Base::begin(),
this); }
214 end() _GLIBCXX_NOEXCEPT
215 {
return iterator(_Base::end(),
this); }
218 end() const _GLIBCXX_NOEXCEPT
219 {
return const_iterator(_Base::end(),
this); }
222 rbegin() _GLIBCXX_NOEXCEPT
223 {
return reverse_iterator(end()); }
225 const_reverse_iterator
226 rbegin() const _GLIBCXX_NOEXCEPT
227 {
return const_reverse_iterator(end()); }
230 rend() _GLIBCXX_NOEXCEPT
231 {
return reverse_iterator(begin()); }
233 const_reverse_iterator
234 rend() const _GLIBCXX_NOEXCEPT
235 {
return const_reverse_iterator(begin()); }
237 #ifdef __GXX_EXPERIMENTAL_CXX0X__
239 cbegin() const noexcept
240 {
return const_iterator(_Base::begin(),
this); }
243 cend() const noexcept
244 {
return const_iterator(_Base::end(),
this); }
246 const_reverse_iterator
247 crbegin() const noexcept
248 {
return const_reverse_iterator(end()); }
250 const_reverse_iterator
251 crend() const noexcept
252 {
return const_reverse_iterator(begin()); }
257 using _Base::max_size;
259 #ifdef __GXX_EXPERIMENTAL_CXX0X__
261 resize(size_type __sz)
263 bool __realloc = _M_requires_reallocation(__sz);
264 if (__sz < this->
size())
265 this->_M_invalidate_after_nth(__sz);
269 _M_update_guaranteed_capacity();
273 resize(size_type __sz,
const _Tp& __c)
275 bool __realloc = _M_requires_reallocation(__sz);
276 if (__sz < this->
size())
277 this->_M_invalidate_after_nth(__sz);
278 _Base::resize(__sz, __c);
281 _M_update_guaranteed_capacity();
285 resize(size_type __sz, _Tp __c = _Tp())
287 bool __realloc = _M_requires_reallocation(__sz);
288 if (__sz < this->
size())
289 this->_M_invalidate_after_nth(__sz);
290 _Base::resize(__sz, __c);
293 _M_update_guaranteed_capacity();
297 #ifdef __GXX_EXPERIMENTAL_CXX0X__
301 if (_Base::_M_shrink_to_fit())
303 _M_guaranteed_capacity = _Base::capacity();
310 capacity() const _GLIBCXX_NOEXCEPT
312 #ifdef _GLIBCXX_DEBUG_PEDANTIC
313 return _M_guaranteed_capacity;
315 return _Base::capacity();
322 reserve(size_type __n)
324 bool __realloc = _M_requires_reallocation(__n);
326 if (__n > _M_guaranteed_capacity)
327 _M_guaranteed_capacity = __n;
334 operator[](size_type __n)
336 __glibcxx_check_subscript(__n);
337 return _M_base()[__n];
341 operator[](size_type __n)
const
343 __glibcxx_check_subscript(__n);
344 return _M_base()[__n];
352 __glibcxx_check_nonempty();
353 return _Base::front();
359 __glibcxx_check_nonempty();
360 return _Base::front();
366 __glibcxx_check_nonempty();
367 return _Base::back();
373 __glibcxx_check_nonempty();
374 return _Base::back();
383 push_back(
const _Tp& __x)
385 bool __realloc = _M_requires_reallocation(this->
size() + 1);
386 _Base::push_back(__x);
389 _M_update_guaranteed_capacity();
392 #ifdef __GXX_EXPERIMENTAL_CXX0X__
393 template<
typename _Up = _Tp>
394 typename __gnu_cxx::__enable_if<!std::__are_same<_Up, bool>::__value,
397 { emplace_back(std::move(__x)); }
399 template<
typename... _Args>
401 emplace_back(_Args&&... __args)
403 bool __realloc = _M_requires_reallocation(this->
size() + 1);
404 _Base::emplace_back(std::forward<_Args>(__args)...);
407 _M_update_guaranteed_capacity();
414 __glibcxx_check_nonempty();
419 #ifdef __GXX_EXPERIMENTAL_CXX0X__
420 template<
typename... _Args>
422 emplace(iterator __position, _Args&&... __args)
425 bool __realloc = _M_requires_reallocation(this->
size() + 1);
426 difference_type __offset = __position.base() - _Base::begin();
427 _Base_iterator __res = _Base::emplace(__position.base(),
428 std::forward<_Args>(__args)...);
432 this->_M_invalidate_after_nth(__offset);
433 _M_update_guaranteed_capacity();
434 return iterator(__res,
this);
439 insert(iterator __position,
const _Tp& __x)
442 bool __realloc = _M_requires_reallocation(this->
size() + 1);
443 difference_type __offset = __position.base() - _Base::begin();
444 _Base_iterator __res = _Base::insert(__position.base(), __x);
448 this->_M_invalidate_after_nth(__offset);
449 _M_update_guaranteed_capacity();
450 return iterator(__res,
this);
453 #ifdef __GXX_EXPERIMENTAL_CXX0X__
454 template<
typename _Up = _Tp>
455 typename __gnu_cxx::__enable_if<!std::__are_same<_Up, bool>::__value,
457 insert(iterator __position, _Tp&& __x)
458 {
return emplace(__position, std::move(__x)); }
461 insert(iterator __position, initializer_list<value_type> __l)
462 { this->insert(__position, __l.begin(), __l.end()); }
466 insert(iterator __position, size_type __n,
const _Tp& __x)
469 bool __realloc = _M_requires_reallocation(this->
size() + __n);
470 difference_type __offset = __position.base() - _Base::begin();
471 _Base::insert(__position.base(), __n, __x);
475 this->_M_invalidate_after_nth(__offset);
476 _M_update_guaranteed_capacity();
479 template<
class _InputIterator>
481 insert(iterator __position,
482 _InputIterator __first, _InputIterator __last)
489 _Base_iterator __old_begin = _M_base().begin();
490 difference_type __offset = __position.base() - _Base::begin();
494 if (_M_base().begin() != __old_begin)
497 this->_M_invalidate_after_nth(__offset);
498 _M_update_guaranteed_capacity();
502 erase(iterator __position)
505 difference_type __offset = __position.base() - _Base::begin();
506 _Base_iterator __res = _Base::erase(__position.base());
507 this->_M_invalidate_after_nth(__offset);
508 return iterator(__res,
this);
512 erase(iterator __first, iterator __last)
518 if (__first.base() != __last.base())
520 difference_type __offset = __first.base() - _Base::begin();
521 _Base_iterator __res = _Base::erase(__first.base(),
523 this->_M_invalidate_after_nth(__offset);
524 return iterator(__res,
this);
532 #ifdef __GXX_EXPERIMENTAL_CXX0X__
533 noexcept(_Alloc_traits::_S_nothrow_swap())
538 std::swap(_M_guaranteed_capacity, __x._M_guaranteed_capacity);
542 clear() _GLIBCXX_NOEXCEPT
546 _M_guaranteed_capacity = 0;
550 _M_base() _GLIBCXX_NOEXCEPT {
return *
this; }
553 _M_base() const _GLIBCXX_NOEXCEPT {
return *
this; }
556 size_type _M_guaranteed_capacity;
559 _M_requires_reallocation(size_type __elements)
560 {
return __elements > this->capacity(); }
563 _M_update_guaranteed_capacity()
565 if (this->
size() > _M_guaranteed_capacity)
566 _M_guaranteed_capacity = this->
size();
570 _M_invalidate_after_nth(difference_type __n)
577 template<
typename _Tp,
typename _Alloc>
579 operator==(
const vector<_Tp, _Alloc>& __lhs,
580 const vector<_Tp, _Alloc>& __rhs)
581 {
return __lhs._M_base() == __rhs._M_base(); }
583 template<
typename _Tp,
typename _Alloc>
585 operator!=(
const vector<_Tp, _Alloc>& __lhs,
586 const vector<_Tp, _Alloc>& __rhs)
587 {
return __lhs._M_base() != __rhs._M_base(); }
589 template<
typename _Tp,
typename _Alloc>
591 operator<(const vector<_Tp, _Alloc>& __lhs,
592 const vector<_Tp, _Alloc>& __rhs)
593 {
return __lhs._M_base() < __rhs._M_base(); }
595 template<
typename _Tp,
typename _Alloc>
597 operator<=(const vector<_Tp, _Alloc>& __lhs,
598 const vector<_Tp, _Alloc>& __rhs)
599 {
return __lhs._M_base() <= __rhs._M_base(); }
601 template<
typename _Tp,
typename _Alloc>
603 operator>=(
const vector<_Tp, _Alloc>& __lhs,
604 const vector<_Tp, _Alloc>& __rhs)
605 {
return __lhs._M_base() >= __rhs._M_base(); }
607 template<
typename _Tp,
typename _Alloc>
609 operator>(
const vector<_Tp, _Alloc>& __lhs,
610 const vector<_Tp, _Alloc>& __rhs)
611 {
return __lhs._M_base() > __rhs._M_base(); }
613 template<
typename _Tp,
typename _Alloc>
615 swap(vector<_Tp, _Alloc>& __lhs, vector<_Tp, _Alloc>& __rhs)
616 { __lhs.swap(__rhs); }
620 #ifdef __GXX_EXPERIMENTAL_CXX0X__
623 template<
typename _Alloc>
625 :
public __hash_base<size_t, __debug::vector<bool, _Alloc>>
_Siter_base< _Iterator >::iterator_type __base(_Iterator __it)
Class std::vector with safety/checking/debug instrumentation.
The standard allocator, as per [20.4].
#define __glibcxx_check_erase_range(_First, _Last)
void _M_swap(_Safe_sequence_base &__x)
void _M_invalidate_if(_Predicate __pred)
Uniform interface to C++98 and C++0x allocators.
#define __glibcxx_check_erase(_Position)
void _M_invalidate_all() const
#define __glibcxx_check_insert_range(_Position, _First, _Last)
#define __glibcxx_check_insert(_Position)
Base class for constructing a safe sequence type that tracks iterators that reference it...
Primary class template hash.
constexpr size_t size() const _GLIBCXX_NOEXCEPT
Returns the total number of bits.
vector(const _Base &__x)
Construction from a release-mode vector.
A standard container which offers fixed time access to individual elements in any order...