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;
57 typedef typename _Base::reference reference;
58 typedef typename _Base::const_reference const_reference;
65 typedef typename _Base::size_type size_type;
66 typedef typename _Base::difference_type difference_type;
68 typedef _Tp value_type;
69 typedef _Allocator allocator_type;
70 typedef typename _Base::pointer pointer;
71 typedef typename _Base::const_pointer const_pointer;
77 vector(
const _Allocator& __a = _Allocator())
78 :
_Base(__a), _M_guaranteed_capacity(0) { }
80 #ifdef __GXX_EXPERIMENTAL_CXX0X__
83 :
_Base(__n), _M_guaranteed_capacity(__n) { }
85 vector(size_type __n,
const _Tp& __value,
86 const _Allocator& __a = _Allocator())
87 :
_Base(__n, __value, __a), _M_guaranteed_capacity(__n) { }
90 vector(size_type __n,
const _Tp& __value = _Tp(),
91 const _Allocator& __a = _Allocator())
92 :
_Base(__n, __value, __a), _M_guaranteed_capacity(__n) { }
95 template<
class _InputIterator>
96 vector(_InputIterator __first, _InputIterator __last,
97 const _Allocator& __a = _Allocator())
101 _M_guaranteed_capacity(0)
102 { _M_update_guaranteed_capacity(); }
111 #ifdef __GXX_EXPERIMENTAL_CXX0X__
113 : _Base(std::move(__x)), _Safe_base(),
114 _M_guaranteed_capacity(this->
size())
117 __x._M_guaranteed_capacity = 0;
121 const allocator_type& __a = allocator_type())
122 : _Base(__l, __a), _Safe_base(),
123 _M_guaranteed_capacity(__l.
size()) { }
129 operator=(
const vector& __x)
131 static_cast<_Base&
>(*this) = __x;
133 _M_update_guaranteed_capacity();
137 #ifdef __GXX_EXPERIMENTAL_CXX0X__
139 operator=(vector&& __x)
149 operator=(initializer_list<value_type> __l)
151 static_cast<_Base&
>(*this) = __l;
153 _M_update_guaranteed_capacity();
158 template<
typename _InputIterator>
160 assign(_InputIterator __first, _InputIterator __last)
162 __glibcxx_check_valid_range(__first, __last);
166 _M_update_guaranteed_capacity();
170 assign(size_type __n,
const _Tp& __u)
172 _Base::assign(__n, __u);
174 _M_update_guaranteed_capacity();
177 #ifdef __GXX_EXPERIMENTAL_CXX0X__
179 assign(initializer_list<value_type> __l)
183 _M_update_guaranteed_capacity();
187 using _Base::get_allocator;
192 {
return iterator(_Base::begin(),
this); }
196 {
return const_iterator(_Base::begin(),
this); }
200 {
return iterator(_Base::end(),
this); }
204 {
return const_iterator(_Base::end(),
this); }
208 {
return reverse_iterator(end()); }
210 const_reverse_iterator
212 {
return const_reverse_iterator(end()); }
216 {
return reverse_iterator(begin()); }
218 const_reverse_iterator
220 {
return const_reverse_iterator(begin()); }
222 #ifdef __GXX_EXPERIMENTAL_CXX0X__
225 {
return const_iterator(_Base::begin(),
this); }
229 {
return const_iterator(_Base::end(),
this); }
231 const_reverse_iterator
233 {
return const_reverse_iterator(end()); }
235 const_reverse_iterator
237 {
return const_reverse_iterator(begin()); }
242 using _Base::max_size;
244 #ifdef __GXX_EXPERIMENTAL_CXX0X__
246 resize(size_type __sz)
248 bool __realloc = _M_requires_reallocation(__sz);
249 if (__sz < this->
size())
250 this->_M_invalidate_after_nth(__sz);
254 _M_update_guaranteed_capacity();
258 resize(size_type __sz,
const _Tp& __c)
260 bool __realloc = _M_requires_reallocation(__sz);
261 if (__sz < this->
size())
262 this->_M_invalidate_after_nth(__sz);
263 _Base::resize(__sz, __c);
266 _M_update_guaranteed_capacity();
270 resize(size_type __sz, _Tp __c = _Tp())
272 bool __realloc = _M_requires_reallocation(__sz);
273 if (__sz < this->
size())
274 this->_M_invalidate_after_nth(__sz);
275 _Base::resize(__sz, __c);
278 _M_update_guaranteed_capacity();
282 #ifdef __GXX_EXPERIMENTAL_CXX0X__
283 using _Base::shrink_to_fit;
289 #ifdef _GLIBCXX_DEBUG_PEDANTIC
290 return _M_guaranteed_capacity;
292 return _Base::capacity();
299 reserve(size_type __n)
301 bool __realloc = _M_requires_reallocation(__n);
303 if (__n > _M_guaranteed_capacity)
304 _M_guaranteed_capacity = __n;
311 operator[](size_type __n)
313 __glibcxx_check_subscript(__n);
314 return _M_base()[__n];
318 operator[](size_type __n)
const
320 __glibcxx_check_subscript(__n);
321 return _M_base()[__n];
329 __glibcxx_check_nonempty();
330 return _Base::front();
336 __glibcxx_check_nonempty();
337 return _Base::front();
343 __glibcxx_check_nonempty();
344 return _Base::back();
350 __glibcxx_check_nonempty();
351 return _Base::back();
360 push_back(
const _Tp& __x)
362 bool __realloc = _M_requires_reallocation(this->
size() + 1);
363 _Base::push_back(__x);
366 _M_update_guaranteed_capacity();
369 #ifdef __GXX_EXPERIMENTAL_CXX0X__
370 template<
typename _Up = _Tp>
371 typename __gnu_cxx::__enable_if<!std::__are_same<_Up, bool>::__value,
374 { emplace_back(std::move(__x)); }
376 template<
typename... _Args>
378 emplace_back(_Args&&... __args)
380 bool __realloc = _M_requires_reallocation(this->
size() + 1);
381 _Base::emplace_back(std::forward<_Args>(__args)...);
384 _M_update_guaranteed_capacity();
391 __glibcxx_check_nonempty();
396 #ifdef __GXX_EXPERIMENTAL_CXX0X__
397 template<
typename... _Args>
399 emplace(iterator __position, _Args&&... __args)
402 bool __realloc = _M_requires_reallocation(this->
size() + 1);
403 difference_type __offset = __position.base() - _Base::begin();
404 _Base_iterator __res = _Base::emplace(__position.base(),
405 std::forward<_Args>(__args)...);
409 this->_M_invalidate_after_nth(__offset);
410 _M_update_guaranteed_capacity();
411 return iterator(__res,
this);
416 insert(iterator __position,
const _Tp& __x)
419 bool __realloc = _M_requires_reallocation(this->
size() + 1);
420 difference_type __offset = __position.base() - _Base::begin();
421 _Base_iterator __res = _Base::insert(__position.base(), __x);
425 this->_M_invalidate_after_nth(__offset);
426 _M_update_guaranteed_capacity();
427 return iterator(__res,
this);
430 #ifdef __GXX_EXPERIMENTAL_CXX0X__
431 template<
typename _Up = _Tp>
432 typename __gnu_cxx::__enable_if<!std::__are_same<_Up, bool>::__value,
434 insert(iterator __position, _Tp&& __x)
435 {
return emplace(__position, std::move(__x)); }
438 insert(iterator __position, initializer_list<value_type> __l)
439 { this->insert(__position, __l.begin(), __l.end()); }
443 insert(iterator __position, size_type __n,
const _Tp& __x)
446 bool __realloc = _M_requires_reallocation(this->
size() + __n);
447 difference_type __offset = __position.base() - _Base::begin();
448 _Base::insert(__position.base(), __n, __x);
452 this->_M_invalidate_after_nth(__offset);
453 _M_update_guaranteed_capacity();
456 template<
class _InputIterator>
458 insert(iterator __position,
459 _InputIterator __first, _InputIterator __last)
466 _Base_iterator __old_begin = _M_base().begin();
467 difference_type __offset = __position.base() - _Base::begin();
471 if (_M_base().begin() != __old_begin)
474 this->_M_invalidate_after_nth(__offset);
475 _M_update_guaranteed_capacity();
479 erase(iterator __position)
482 difference_type __offset = __position.base() - _Base::begin();
483 _Base_iterator __res = _Base::erase(__position.base());
484 this->_M_invalidate_after_nth(__offset);
485 return iterator(__res,
this);
489 erase(iterator __first, iterator __last)
495 if (__first.base() != __last.base())
497 difference_type __offset = __first.base() - _Base::begin();
498 _Base_iterator __res = _Base::erase(__first.base(),
500 this->_M_invalidate_after_nth(__offset);
501 return iterator(__res,
this);
512 std::swap(_M_guaranteed_capacity, __x._M_guaranteed_capacity);
520 _M_guaranteed_capacity = 0;
524 _M_base() {
return *
this; }
527 _M_base()
const {
return *
this; }
530 size_type _M_guaranteed_capacity;
533 _M_requires_reallocation(size_type __elements)
534 {
return __elements > this->capacity(); }
537 _M_update_guaranteed_capacity()
539 if (this->
size() > _M_guaranteed_capacity)
540 _M_guaranteed_capacity = this->
size();
544 _M_invalidate_after_nth(difference_type __n)
551 template<
typename _Tp,
typename _Alloc>
553 operator==(
const vector<_Tp, _Alloc>& __lhs,
554 const vector<_Tp, _Alloc>& __rhs)
555 {
return __lhs._M_base() == __rhs._M_base(); }
557 template<
typename _Tp,
typename _Alloc>
559 operator!=(
const vector<_Tp, _Alloc>& __lhs,
560 const vector<_Tp, _Alloc>& __rhs)
561 {
return __lhs._M_base() != __rhs._M_base(); }
563 template<
typename _Tp,
typename _Alloc>
565 operator<(const vector<_Tp, _Alloc>& __lhs,
566 const vector<_Tp, _Alloc>& __rhs)
567 {
return __lhs._M_base() < __rhs._M_base(); }
569 template<
typename _Tp,
typename _Alloc>
571 operator<=(const vector<_Tp, _Alloc>& __lhs,
572 const vector<_Tp, _Alloc>& __rhs)
573 {
return __lhs._M_base() <= __rhs._M_base(); }
575 template<
typename _Tp,
typename _Alloc>
577 operator>=(
const vector<_Tp, _Alloc>& __lhs,
578 const vector<_Tp, _Alloc>& __rhs)
579 {
return __lhs._M_base() >= __rhs._M_base(); }
581 template<
typename _Tp,
typename _Alloc>
583 operator>(
const vector<_Tp, _Alloc>& __lhs,
584 const vector<_Tp, _Alloc>& __rhs)
585 {
return __lhs._M_base() > __rhs._M_base(); }
587 template<
typename _Tp,
typename _Alloc>
589 swap(vector<_Tp, _Alloc>& __lhs, vector<_Tp, _Alloc>& __rhs)
590 { __lhs.swap(__rhs); }
594 #ifdef __GXX_EXPERIMENTAL_CXX0X__
597 template<
typename _Alloc>
599 :
public __hash_base<size_t, __debug::vector<bool, _Alloc>>