59 namespace std _GLIBCXX_VISIBILITY(default)
61 _GLIBCXX_BEGIN_NAMESPACE_VERSION
62 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
64 template<
typename _Tp,
typename _Alloc>
69 if (__n > this->max_size())
70 __throw_length_error(__N(
"vector::reserve"));
71 if (this->capacity() < __n)
73 const size_type __old_size = size();
74 pointer __tmp = _M_allocate_and_copy(__n,
75 _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(this->_M_impl._M_start),
76 _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(this->_M_impl._M_finish));
77 _GLIBCXX_ASAN_ANNOTATE_REINIT;
78 std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
79 _M_get_Tp_allocator());
80 _M_deallocate(this->_M_impl._M_start,
81 this->_M_impl._M_end_of_storage
82 - this->_M_impl._M_start);
83 this->_M_impl._M_start = __tmp;
84 this->_M_impl._M_finish = __tmp + __old_size;
85 this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n;
89 #if __cplusplus >= 201103L 90 template<
typename _Tp,
typename _Alloc>
91 template<
typename... _Args>
92 #if __cplusplus > 201402L 93 typename vector<_Tp, _Alloc>::reference
100 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
102 _GLIBCXX_ASAN_ANNOTATE_GROW(1);
103 _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
104 std::forward<_Args>(__args)...);
105 ++this->_M_impl._M_finish;
106 _GLIBCXX_ASAN_ANNOTATE_GREW(1);
109 _M_realloc_insert(
end(), std::forward<_Args>(__args)...);
110 #if __cplusplus > 201402L 116 template<
typename _Tp,
typename _Alloc>
117 typename vector<_Tp, _Alloc>::iterator
119 #if __cplusplus >= 201103L 122 insert(iterator __position,
const value_type& __x)
125 const size_type __n = __position -
begin();
126 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
127 if (__position ==
end())
129 _GLIBCXX_ASAN_ANNOTATE_GROW(1);
130 _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish,
132 ++this->_M_impl._M_finish;
133 _GLIBCXX_ASAN_ANNOTATE_GREW(1);
137 #if __cplusplus >= 201103L 138 const auto __pos =
begin() + (__position -
cbegin());
141 _Temporary_value __x_copy(
this, __x);
142 _M_insert_aux(__pos, std::move(__x_copy._M_val()));
144 _M_insert_aux(__position, __x);
148 #if __cplusplus >= 201103L 149 _M_realloc_insert(
begin() + (__position -
cbegin()), __x);
151 _M_realloc_insert(__position, __x);
154 return iterator(this->_M_impl._M_start + __n);
157 template<
typename _Tp,
typename _Alloc>
158 typename vector<_Tp, _Alloc>::iterator
162 if (__position + 1 !=
end())
163 _GLIBCXX_MOVE3(__position + 1,
end(), __position);
164 --this->_M_impl._M_finish;
165 _Alloc_traits::destroy(this->_M_impl, this->_M_impl._M_finish);
166 _GLIBCXX_ASAN_ANNOTATE_SHRINK(1);
170 template<
typename _Tp,
typename _Alloc>
171 typename vector<_Tp, _Alloc>::iterator
173 _M_erase(iterator __first, iterator __last)
175 if (__first != __last)
178 _GLIBCXX_MOVE3(__last,
end(), __first);
179 _M_erase_at_end(__first.base() + (
end() - __last));
184 template<
typename _Tp,
typename _Alloc>
191 _GLIBCXX_ASAN_ANNOTATE_REINIT;
192 #if __cplusplus >= 201103L 193 if (_Alloc_traits::_S_propagate_on_copy_assign())
195 if (!_Alloc_traits::_S_always_equal()
196 && _M_get_Tp_allocator() != __x._M_get_Tp_allocator())
200 _M_deallocate(this->_M_impl._M_start,
201 this->_M_impl._M_end_of_storage
202 - this->_M_impl._M_start);
203 this->_M_impl._M_start =
nullptr;
204 this->_M_impl._M_finish =
nullptr;
205 this->_M_impl._M_end_of_storage =
nullptr;
207 std::__alloc_on_copy(_M_get_Tp_allocator(),
208 __x._M_get_Tp_allocator());
211 const size_type __xlen = __x.
size();
212 if (__xlen > capacity())