138fd1498Szrj // Vector implementation (out of line) -*- C++ -*- 238fd1498Szrj 338fd1498Szrj // Copyright (C) 2001-2018 Free Software Foundation, Inc. 438fd1498Szrj // 538fd1498Szrj // This file is part of the GNU ISO C++ Library. This library is free 638fd1498Szrj // software; you can redistribute it and/or modify it under the 738fd1498Szrj // terms of the GNU General Public License as published by the 838fd1498Szrj // Free Software Foundation; either version 3, or (at your option) 938fd1498Szrj // any later version. 1038fd1498Szrj 1138fd1498Szrj // This library is distributed in the hope that it will be useful, 1238fd1498Szrj // but WITHOUT ANY WARRANTY; without even the implied warranty of 1338fd1498Szrj // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1438fd1498Szrj // GNU General Public License for more details. 1538fd1498Szrj 1638fd1498Szrj // Under Section 7 of GPL version 3, you are granted additional 1738fd1498Szrj // permissions described in the GCC Runtime Library Exception, version 1838fd1498Szrj // 3.1, as published by the Free Software Foundation. 1938fd1498Szrj 2038fd1498Szrj // You should have received a copy of the GNU General Public License and 2138fd1498Szrj // a copy of the GCC Runtime Library Exception along with this program; 2238fd1498Szrj // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 2338fd1498Szrj // <http://www.gnu.org/licenses/>. 2438fd1498Szrj 2538fd1498Szrj /* 2638fd1498Szrj * 2738fd1498Szrj * Copyright (c) 1994 2838fd1498Szrj * Hewlett-Packard Company 2938fd1498Szrj * 3038fd1498Szrj * Permission to use, copy, modify, distribute and sell this software 3138fd1498Szrj * and its documentation for any purpose is hereby granted without fee, 3238fd1498Szrj * provided that the above copyright notice appear in all copies and 3338fd1498Szrj * that both that copyright notice and this permission notice appear 3438fd1498Szrj * in supporting documentation. Hewlett-Packard Company makes no 3538fd1498Szrj * representations about the suitability of this software for any 3638fd1498Szrj * purpose. It is provided "as is" without express or implied warranty. 3738fd1498Szrj * 3838fd1498Szrj * 3938fd1498Szrj * Copyright (c) 1996 4038fd1498Szrj * Silicon Graphics Computer Systems, Inc. 4138fd1498Szrj * 4238fd1498Szrj * Permission to use, copy, modify, distribute and sell this software 4338fd1498Szrj * and its documentation for any purpose is hereby granted without fee, 4438fd1498Szrj * provided that the above copyright notice appear in all copies and 4538fd1498Szrj * that both that copyright notice and this permission notice appear 4638fd1498Szrj * in supporting documentation. Silicon Graphics makes no 4738fd1498Szrj * representations about the suitability of this software for any 4838fd1498Szrj * purpose. It is provided "as is" without express or implied warranty. 4938fd1498Szrj */ 5038fd1498Szrj 5138fd1498Szrj /** @file bits/vector.tcc 5238fd1498Szrj * This is an internal header file, included by other library headers. 5338fd1498Szrj * Do not attempt to use it directly. @headername{vector} 5438fd1498Szrj */ 5538fd1498Szrj 5638fd1498Szrj #ifndef _VECTOR_TCC 5738fd1498Szrj #define _VECTOR_TCC 1 5838fd1498Szrj 5938fd1498Szrj namespace std _GLIBCXX_VISIBILITY(default) 6038fd1498Szrj { 6138fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_VERSION 6238fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_CONTAINER 6338fd1498Szrj 6438fd1498Szrj template<typename _Tp, typename _Alloc> 6538fd1498Szrj void 6638fd1498Szrj vector<_Tp, _Alloc>:: reserve(size_type __n)6738fd1498Szrj reserve(size_type __n) 6838fd1498Szrj { 6938fd1498Szrj if (__n > this->max_size()) 7038fd1498Szrj __throw_length_error(__N("vector::reserve")); 7138fd1498Szrj if (this->capacity() < __n) 7238fd1498Szrj { 7338fd1498Szrj const size_type __old_size = size(); 7438fd1498Szrj pointer __tmp = _M_allocate_and_copy(__n, 7538fd1498Szrj _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(this->_M_impl._M_start), 7638fd1498Szrj _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(this->_M_impl._M_finish)); 7738fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_REINIT; 7838fd1498Szrj std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish, 7938fd1498Szrj _M_get_Tp_allocator()); 8038fd1498Szrj _M_deallocate(this->_M_impl._M_start, 8138fd1498Szrj this->_M_impl._M_end_of_storage 8238fd1498Szrj - this->_M_impl._M_start); 8338fd1498Szrj this->_M_impl._M_start = __tmp; 8438fd1498Szrj this->_M_impl._M_finish = __tmp + __old_size; 8538fd1498Szrj this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n; 8638fd1498Szrj } 8738fd1498Szrj } 8838fd1498Szrj 8938fd1498Szrj #if __cplusplus >= 201103L 9038fd1498Szrj template<typename _Tp, typename _Alloc> 9138fd1498Szrj template<typename... _Args> 9238fd1498Szrj #if __cplusplus > 201402L 9338fd1498Szrj typename vector<_Tp, _Alloc>::reference 9438fd1498Szrj #else 9538fd1498Szrj void 9638fd1498Szrj #endif 9738fd1498Szrj vector<_Tp, _Alloc>:: emplace_back(_Args &&...__args)9838fd1498Szrj emplace_back(_Args&&... __args) 9938fd1498Szrj { 10038fd1498Szrj if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage) 10138fd1498Szrj { 10238fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GROW(1); 10338fd1498Szrj _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish, 10438fd1498Szrj std::forward<_Args>(__args)...); 10538fd1498Szrj ++this->_M_impl._M_finish; 10638fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GREW(1); 10738fd1498Szrj } 10838fd1498Szrj else 10938fd1498Szrj _M_realloc_insert(end(), std::forward<_Args>(__args)...); 11038fd1498Szrj #if __cplusplus > 201402L 11138fd1498Szrj return back(); 11238fd1498Szrj #endif 11338fd1498Szrj } 11438fd1498Szrj #endif 11538fd1498Szrj 11638fd1498Szrj template<typename _Tp, typename _Alloc> 11738fd1498Szrj typename vector<_Tp, _Alloc>::iterator 11838fd1498Szrj vector<_Tp, _Alloc>:: 11938fd1498Szrj #if __cplusplus >= 201103L insert(const_iterator __position,const value_type & __x)12038fd1498Szrj insert(const_iterator __position, const value_type& __x) 12138fd1498Szrj #else 12238fd1498Szrj insert(iterator __position, const value_type& __x) 12338fd1498Szrj #endif 12438fd1498Szrj { 12538fd1498Szrj const size_type __n = __position - begin(); 12638fd1498Szrj if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage) 12738fd1498Szrj if (__position == end()) 12838fd1498Szrj { 12938fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GROW(1); 13038fd1498Szrj _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish, 13138fd1498Szrj __x); 13238fd1498Szrj ++this->_M_impl._M_finish; 13338fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GREW(1); 13438fd1498Szrj } 13538fd1498Szrj else 13638fd1498Szrj { 13738fd1498Szrj #if __cplusplus >= 201103L 13838fd1498Szrj const auto __pos = begin() + (__position - cbegin()); 13938fd1498Szrj // __x could be an existing element of this vector, so make a 14038fd1498Szrj // copy of it before _M_insert_aux moves elements around. 14138fd1498Szrj _Temporary_value __x_copy(this, __x); 14238fd1498Szrj _M_insert_aux(__pos, std::move(__x_copy._M_val())); 14338fd1498Szrj #else 14438fd1498Szrj _M_insert_aux(__position, __x); 14538fd1498Szrj #endif 14638fd1498Szrj } 14738fd1498Szrj else 14838fd1498Szrj #if __cplusplus >= 201103L 14938fd1498Szrj _M_realloc_insert(begin() + (__position - cbegin()), __x); 15038fd1498Szrj #else 15138fd1498Szrj _M_realloc_insert(__position, __x); 15238fd1498Szrj #endif 15338fd1498Szrj 15438fd1498Szrj return iterator(this->_M_impl._M_start + __n); 15538fd1498Szrj } 15638fd1498Szrj 15738fd1498Szrj template<typename _Tp, typename _Alloc> 15838fd1498Szrj typename vector<_Tp, _Alloc>::iterator 15938fd1498Szrj vector<_Tp, _Alloc>:: _M_erase(iterator __position)16038fd1498Szrj _M_erase(iterator __position) 16138fd1498Szrj { 16238fd1498Szrj if (__position + 1 != end()) 16338fd1498Szrj _GLIBCXX_MOVE3(__position + 1, end(), __position); 16438fd1498Szrj --this->_M_impl._M_finish; 16538fd1498Szrj _Alloc_traits::destroy(this->_M_impl, this->_M_impl._M_finish); 16638fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_SHRINK(1); 16738fd1498Szrj return __position; 16838fd1498Szrj } 16938fd1498Szrj 17038fd1498Szrj template<typename _Tp, typename _Alloc> 17138fd1498Szrj typename vector<_Tp, _Alloc>::iterator 17238fd1498Szrj vector<_Tp, _Alloc>:: _M_erase(iterator __first,iterator __last)17338fd1498Szrj _M_erase(iterator __first, iterator __last) 17438fd1498Szrj { 17538fd1498Szrj if (__first != __last) 17638fd1498Szrj { 17738fd1498Szrj if (__last != end()) 17838fd1498Szrj _GLIBCXX_MOVE3(__last, end(), __first); 17938fd1498Szrj _M_erase_at_end(__first.base() + (end() - __last)); 18038fd1498Szrj } 18138fd1498Szrj return __first; 18238fd1498Szrj } 18338fd1498Szrj 18438fd1498Szrj template<typename _Tp, typename _Alloc> 18538fd1498Szrj vector<_Tp, _Alloc>& 18638fd1498Szrj vector<_Tp, _Alloc>:: operator =(const vector<_Tp,_Alloc> & __x)18738fd1498Szrj operator=(const vector<_Tp, _Alloc>& __x) 18838fd1498Szrj { 18938fd1498Szrj if (&__x != this) 19038fd1498Szrj { 19138fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_REINIT; 19238fd1498Szrj #if __cplusplus >= 201103L 19338fd1498Szrj if (_Alloc_traits::_S_propagate_on_copy_assign()) 19438fd1498Szrj { 19538fd1498Szrj if (!_Alloc_traits::_S_always_equal() 19638fd1498Szrj && _M_get_Tp_allocator() != __x._M_get_Tp_allocator()) 19738fd1498Szrj { 19838fd1498Szrj // replacement allocator cannot free existing storage 19938fd1498Szrj this->clear(); 20038fd1498Szrj _M_deallocate(this->_M_impl._M_start, 20138fd1498Szrj this->_M_impl._M_end_of_storage 20238fd1498Szrj - this->_M_impl._M_start); 20338fd1498Szrj this->_M_impl._M_start = nullptr; 20438fd1498Szrj this->_M_impl._M_finish = nullptr; 20538fd1498Szrj this->_M_impl._M_end_of_storage = nullptr; 20638fd1498Szrj } 20738fd1498Szrj std::__alloc_on_copy(_M_get_Tp_allocator(), 20838fd1498Szrj __x._M_get_Tp_allocator()); 20938fd1498Szrj } 21038fd1498Szrj #endif 21138fd1498Szrj const size_type __xlen = __x.size(); 21238fd1498Szrj if (__xlen > capacity()) 21338fd1498Szrj { 21438fd1498Szrj pointer __tmp = _M_allocate_and_copy(__xlen, __x.begin(), 21538fd1498Szrj __x.end()); 21638fd1498Szrj std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish, 21738fd1498Szrj _M_get_Tp_allocator()); 21838fd1498Szrj _M_deallocate(this->_M_impl._M_start, 21938fd1498Szrj this->_M_impl._M_end_of_storage 22038fd1498Szrj - this->_M_impl._M_start); 22138fd1498Szrj this->_M_impl._M_start = __tmp; 22238fd1498Szrj this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __xlen; 22338fd1498Szrj } 22438fd1498Szrj else if (size() >= __xlen) 22538fd1498Szrj { 22638fd1498Szrj std::_Destroy(std::copy(__x.begin(), __x.end(), begin()), 22738fd1498Szrj end(), _M_get_Tp_allocator()); 22838fd1498Szrj } 22938fd1498Szrj else 23038fd1498Szrj { 23138fd1498Szrj std::copy(__x._M_impl._M_start, __x._M_impl._M_start + size(), 23238fd1498Szrj this->_M_impl._M_start); 23338fd1498Szrj std::__uninitialized_copy_a(__x._M_impl._M_start + size(), 23438fd1498Szrj __x._M_impl._M_finish, 23538fd1498Szrj this->_M_impl._M_finish, 23638fd1498Szrj _M_get_Tp_allocator()); 23738fd1498Szrj } 23838fd1498Szrj this->_M_impl._M_finish = this->_M_impl._M_start + __xlen; 23938fd1498Szrj } 24038fd1498Szrj return *this; 24138fd1498Szrj } 24238fd1498Szrj 24338fd1498Szrj template<typename _Tp, typename _Alloc> 24438fd1498Szrj void 24538fd1498Szrj vector<_Tp, _Alloc>:: _M_fill_assign(size_t __n,const value_type & __val)24638fd1498Szrj _M_fill_assign(size_t __n, const value_type& __val) 24738fd1498Szrj { 24838fd1498Szrj if (__n > capacity()) 24938fd1498Szrj { 25038fd1498Szrj vector __tmp(__n, __val, _M_get_Tp_allocator()); 25138fd1498Szrj __tmp._M_impl._M_swap_data(this->_M_impl); 25238fd1498Szrj } 25338fd1498Szrj else if (__n > size()) 25438fd1498Szrj { 25538fd1498Szrj std::fill(begin(), end(), __val); 25638fd1498Szrj const size_type __add = __n - size(); 25738fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GROW(__add); 25838fd1498Szrj this->_M_impl._M_finish = 25938fd1498Szrj std::__uninitialized_fill_n_a(this->_M_impl._M_finish, 26038fd1498Szrj __add, __val, _M_get_Tp_allocator()); 26138fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GREW(__add); 26238fd1498Szrj } 26338fd1498Szrj else 26438fd1498Szrj _M_erase_at_end(std::fill_n(this->_M_impl._M_start, __n, __val)); 26538fd1498Szrj } 26638fd1498Szrj 26738fd1498Szrj template<typename _Tp, typename _Alloc> 26838fd1498Szrj template<typename _InputIterator> 26938fd1498Szrj void 27038fd1498Szrj vector<_Tp, _Alloc>:: _M_assign_aux(_InputIterator __first,_InputIterator __last,std::input_iterator_tag)27138fd1498Szrj _M_assign_aux(_InputIterator __first, _InputIterator __last, 27238fd1498Szrj std::input_iterator_tag) 27338fd1498Szrj { 27438fd1498Szrj pointer __cur(this->_M_impl._M_start); 27538fd1498Szrj for (; __first != __last && __cur != this->_M_impl._M_finish; 27638fd1498Szrj ++__cur, ++__first) 27738fd1498Szrj *__cur = *__first; 27838fd1498Szrj if (__first == __last) 27938fd1498Szrj _M_erase_at_end(__cur); 28038fd1498Szrj else 28138fd1498Szrj _M_range_insert(end(), __first, __last, 28238fd1498Szrj std::__iterator_category(__first)); 28338fd1498Szrj } 28438fd1498Szrj 28538fd1498Szrj template<typename _Tp, typename _Alloc> 28638fd1498Szrj template<typename _ForwardIterator> 28738fd1498Szrj void 28838fd1498Szrj vector<_Tp, _Alloc>:: _M_assign_aux(_ForwardIterator __first,_ForwardIterator __last,std::forward_iterator_tag)28938fd1498Szrj _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last, 29038fd1498Szrj std::forward_iterator_tag) 29138fd1498Szrj { 29238fd1498Szrj const size_type __len = std::distance(__first, __last); 29338fd1498Szrj 29438fd1498Szrj if (__len > capacity()) 29538fd1498Szrj { 29638fd1498Szrj pointer __tmp(_M_allocate_and_copy(__len, __first, __last)); 29738fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_REINIT; 29838fd1498Szrj std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish, 29938fd1498Szrj _M_get_Tp_allocator()); 30038fd1498Szrj _M_deallocate(this->_M_impl._M_start, 30138fd1498Szrj this->_M_impl._M_end_of_storage 30238fd1498Szrj - this->_M_impl._M_start); 30338fd1498Szrj this->_M_impl._M_start = __tmp; 30438fd1498Szrj this->_M_impl._M_finish = this->_M_impl._M_start + __len; 30538fd1498Szrj this->_M_impl._M_end_of_storage = this->_M_impl._M_finish; 30638fd1498Szrj } 30738fd1498Szrj else if (size() >= __len) 30838fd1498Szrj _M_erase_at_end(std::copy(__first, __last, this->_M_impl._M_start)); 30938fd1498Szrj else 31038fd1498Szrj { 31138fd1498Szrj _ForwardIterator __mid = __first; 31238fd1498Szrj std::advance(__mid, size()); 31338fd1498Szrj std::copy(__first, __mid, this->_M_impl._M_start); 31438fd1498Szrj const size_type __attribute__((__unused__)) __n = __len - size(); 31538fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GROW(__n); 31638fd1498Szrj this->_M_impl._M_finish = 31738fd1498Szrj std::__uninitialized_copy_a(__mid, __last, 31838fd1498Szrj this->_M_impl._M_finish, 31938fd1498Szrj _M_get_Tp_allocator()); 32038fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GREW(__n); 32138fd1498Szrj } 32238fd1498Szrj } 32338fd1498Szrj 32438fd1498Szrj #if __cplusplus >= 201103L 32538fd1498Szrj template<typename _Tp, typename _Alloc> 32638fd1498Szrj auto 32738fd1498Szrj vector<_Tp, _Alloc>:: _M_insert_rval(const_iterator __position,value_type && __v)32838fd1498Szrj _M_insert_rval(const_iterator __position, value_type&& __v) -> iterator 32938fd1498Szrj { 33038fd1498Szrj const auto __n = __position - cbegin(); 33138fd1498Szrj if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage) 33238fd1498Szrj if (__position == cend()) 33338fd1498Szrj { 33438fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GROW(1); 33538fd1498Szrj _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish, 33638fd1498Szrj std::move(__v)); 33738fd1498Szrj ++this->_M_impl._M_finish; 33838fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GREW(1); 33938fd1498Szrj } 34038fd1498Szrj else 34138fd1498Szrj _M_insert_aux(begin() + __n, std::move(__v)); 34238fd1498Szrj else 34338fd1498Szrj _M_realloc_insert(begin() + __n, std::move(__v)); 34438fd1498Szrj 34538fd1498Szrj return iterator(this->_M_impl._M_start + __n); 34638fd1498Szrj } 34738fd1498Szrj 34838fd1498Szrj template<typename _Tp, typename _Alloc> 34938fd1498Szrj template<typename... _Args> 35038fd1498Szrj auto 35138fd1498Szrj vector<_Tp, _Alloc>:: _M_emplace_aux(const_iterator __position,_Args &&...__args)35238fd1498Szrj _M_emplace_aux(const_iterator __position, _Args&&... __args) 35338fd1498Szrj -> iterator 35438fd1498Szrj { 35538fd1498Szrj const auto __n = __position - cbegin(); 35638fd1498Szrj if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage) 35738fd1498Szrj if (__position == cend()) 35838fd1498Szrj { 35938fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GROW(1); 36038fd1498Szrj _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish, 36138fd1498Szrj std::forward<_Args>(__args)...); 36238fd1498Szrj ++this->_M_impl._M_finish; 36338fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GREW(1); 36438fd1498Szrj } 36538fd1498Szrj else 36638fd1498Szrj { 36738fd1498Szrj // We need to construct a temporary because something in __args... 36838fd1498Szrj // could alias one of the elements of the container and so we 36938fd1498Szrj // need to use it before _M_insert_aux moves elements around. 37038fd1498Szrj _Temporary_value __tmp(this, std::forward<_Args>(__args)...); 37138fd1498Szrj _M_insert_aux(begin() + __n, std::move(__tmp._M_val())); 37238fd1498Szrj } 37338fd1498Szrj else 37438fd1498Szrj _M_realloc_insert(begin() + __n, std::forward<_Args>(__args)...); 37538fd1498Szrj 37638fd1498Szrj return iterator(this->_M_impl._M_start + __n); 37738fd1498Szrj } 37838fd1498Szrj 37938fd1498Szrj template<typename _Tp, typename _Alloc> 38038fd1498Szrj template<typename _Arg> 38138fd1498Szrj void 38238fd1498Szrj vector<_Tp, _Alloc>:: _M_insert_aux(iterator __position,_Arg && __arg)38338fd1498Szrj _M_insert_aux(iterator __position, _Arg&& __arg) 38438fd1498Szrj #else 38538fd1498Szrj template<typename _Tp, typename _Alloc> 38638fd1498Szrj void 38738fd1498Szrj vector<_Tp, _Alloc>:: 38838fd1498Szrj _M_insert_aux(iterator __position, const _Tp& __x) 38938fd1498Szrj #endif 39038fd1498Szrj { 39138fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GROW(1); 39238fd1498Szrj _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish, 39338fd1498Szrj _GLIBCXX_MOVE(*(this->_M_impl._M_finish - 1))); 39438fd1498Szrj ++this->_M_impl._M_finish; 39538fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GREW(1); 39638fd1498Szrj #if __cplusplus < 201103L 39738fd1498Szrj _Tp __x_copy = __x; 39838fd1498Szrj #endif 39938fd1498Szrj _GLIBCXX_MOVE_BACKWARD3(__position.base(), 40038fd1498Szrj this->_M_impl._M_finish - 2, 40138fd1498Szrj this->_M_impl._M_finish - 1); 40238fd1498Szrj #if __cplusplus < 201103L 40338fd1498Szrj *__position = __x_copy; 40438fd1498Szrj #else 40538fd1498Szrj *__position = std::forward<_Arg>(__arg); 40638fd1498Szrj #endif 40738fd1498Szrj } 40838fd1498Szrj 40938fd1498Szrj #if __cplusplus >= 201103L 41038fd1498Szrj template<typename _Tp, typename _Alloc> 41138fd1498Szrj template<typename... _Args> 41238fd1498Szrj void 41338fd1498Szrj vector<_Tp, _Alloc>:: _M_realloc_insert(iterator __position,_Args &&...__args)41438fd1498Szrj _M_realloc_insert(iterator __position, _Args&&... __args) 41538fd1498Szrj #else 41638fd1498Szrj template<typename _Tp, typename _Alloc> 41738fd1498Szrj void 41838fd1498Szrj vector<_Tp, _Alloc>:: 41938fd1498Szrj _M_realloc_insert(iterator __position, const _Tp& __x) 42038fd1498Szrj #endif 42138fd1498Szrj { 42238fd1498Szrj const size_type __len = 42338fd1498Szrj _M_check_len(size_type(1), "vector::_M_realloc_insert"); 42438fd1498Szrj pointer __old_start = this->_M_impl._M_start; 42538fd1498Szrj pointer __old_finish = this->_M_impl._M_finish; 42638fd1498Szrj const size_type __elems_before = __position - begin(); 42738fd1498Szrj pointer __new_start(this->_M_allocate(__len)); 42838fd1498Szrj pointer __new_finish(__new_start); 42938fd1498Szrj __try 43038fd1498Szrj { 43138fd1498Szrj // The order of the three operations is dictated by the C++11 43238fd1498Szrj // case, where the moves could alter a new element belonging 43338fd1498Szrj // to the existing vector. This is an issue only for callers 43438fd1498Szrj // taking the element by lvalue ref (see last bullet of C++11 43538fd1498Szrj // [res.on.arguments]). 43638fd1498Szrj _Alloc_traits::construct(this->_M_impl, 43738fd1498Szrj __new_start + __elems_before, 43838fd1498Szrj #if __cplusplus >= 201103L 43938fd1498Szrj std::forward<_Args>(__args)...); 44038fd1498Szrj #else 44138fd1498Szrj __x); 44238fd1498Szrj #endif 44338fd1498Szrj __new_finish = pointer(); 44438fd1498Szrj 44538fd1498Szrj __new_finish 44638fd1498Szrj = std::__uninitialized_move_if_noexcept_a 44738fd1498Szrj (__old_start, __position.base(), 44838fd1498Szrj __new_start, _M_get_Tp_allocator()); 44938fd1498Szrj 45038fd1498Szrj ++__new_finish; 45138fd1498Szrj 45238fd1498Szrj __new_finish 45338fd1498Szrj = std::__uninitialized_move_if_noexcept_a 45438fd1498Szrj (__position.base(), __old_finish, 45538fd1498Szrj __new_finish, _M_get_Tp_allocator()); 45638fd1498Szrj } 45738fd1498Szrj __catch(...) 45838fd1498Szrj { 45938fd1498Szrj if (!__new_finish) 46038fd1498Szrj _Alloc_traits::destroy(this->_M_impl, 46138fd1498Szrj __new_start + __elems_before); 46238fd1498Szrj else 46338fd1498Szrj std::_Destroy(__new_start, __new_finish, _M_get_Tp_allocator()); 46438fd1498Szrj _M_deallocate(__new_start, __len); 46538fd1498Szrj __throw_exception_again; 46638fd1498Szrj } 46738fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_REINIT; 46838fd1498Szrj std::_Destroy(__old_start, __old_finish, _M_get_Tp_allocator()); 46938fd1498Szrj _M_deallocate(__old_start, 47038fd1498Szrj this->_M_impl._M_end_of_storage - __old_start); 47138fd1498Szrj this->_M_impl._M_start = __new_start; 47238fd1498Szrj this->_M_impl._M_finish = __new_finish; 47338fd1498Szrj this->_M_impl._M_end_of_storage = __new_start + __len; 47438fd1498Szrj } 47538fd1498Szrj 47638fd1498Szrj template<typename _Tp, typename _Alloc> 47738fd1498Szrj void 47838fd1498Szrj vector<_Tp, _Alloc>:: _M_fill_insert(iterator __position,size_type __n,const value_type & __x)47938fd1498Szrj _M_fill_insert(iterator __position, size_type __n, const value_type& __x) 48038fd1498Szrj { 48138fd1498Szrj if (__n != 0) 48238fd1498Szrj { 48338fd1498Szrj if (size_type(this->_M_impl._M_end_of_storage 48438fd1498Szrj - this->_M_impl._M_finish) >= __n) 48538fd1498Szrj { 48638fd1498Szrj #if __cplusplus < 201103L 48738fd1498Szrj value_type __x_copy = __x; 48838fd1498Szrj #else 48938fd1498Szrj _Temporary_value __tmp(this, __x); 49038fd1498Szrj value_type& __x_copy = __tmp._M_val(); 49138fd1498Szrj #endif 49238fd1498Szrj const size_type __elems_after = end() - __position; 49338fd1498Szrj pointer __old_finish(this->_M_impl._M_finish); 49438fd1498Szrj if (__elems_after > __n) 49538fd1498Szrj { 49638fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GROW(__n); 49738fd1498Szrj std::__uninitialized_move_a(this->_M_impl._M_finish - __n, 49838fd1498Szrj this->_M_impl._M_finish, 49938fd1498Szrj this->_M_impl._M_finish, 50038fd1498Szrj _M_get_Tp_allocator()); 50138fd1498Szrj this->_M_impl._M_finish += __n; 50238fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GREW(__n); 50338fd1498Szrj _GLIBCXX_MOVE_BACKWARD3(__position.base(), 50438fd1498Szrj __old_finish - __n, __old_finish); 50538fd1498Szrj std::fill(__position.base(), __position.base() + __n, 50638fd1498Szrj __x_copy); 50738fd1498Szrj } 50838fd1498Szrj else 50938fd1498Szrj { 51038fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GROW(__n); 51138fd1498Szrj this->_M_impl._M_finish = 51238fd1498Szrj std::__uninitialized_fill_n_a(this->_M_impl._M_finish, 51338fd1498Szrj __n - __elems_after, 51438fd1498Szrj __x_copy, 51538fd1498Szrj _M_get_Tp_allocator()); 51638fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GREW(__n - __elems_after); 51738fd1498Szrj std::__uninitialized_move_a(__position.base(), __old_finish, 51838fd1498Szrj this->_M_impl._M_finish, 51938fd1498Szrj _M_get_Tp_allocator()); 52038fd1498Szrj this->_M_impl._M_finish += __elems_after; 52138fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GREW(__elems_after); 52238fd1498Szrj std::fill(__position.base(), __old_finish, __x_copy); 52338fd1498Szrj } 52438fd1498Szrj } 52538fd1498Szrj else 52638fd1498Szrj { 52738fd1498Szrj const size_type __len = 52838fd1498Szrj _M_check_len(__n, "vector::_M_fill_insert"); 52938fd1498Szrj const size_type __elems_before = __position - begin(); 53038fd1498Szrj pointer __new_start(this->_M_allocate(__len)); 53138fd1498Szrj pointer __new_finish(__new_start); 53238fd1498Szrj __try 53338fd1498Szrj { 53438fd1498Szrj // See _M_realloc_insert above. 53538fd1498Szrj std::__uninitialized_fill_n_a(__new_start + __elems_before, 53638fd1498Szrj __n, __x, 53738fd1498Szrj _M_get_Tp_allocator()); 53838fd1498Szrj __new_finish = pointer(); 53938fd1498Szrj 54038fd1498Szrj __new_finish 54138fd1498Szrj = std::__uninitialized_move_if_noexcept_a 54238fd1498Szrj (this->_M_impl._M_start, __position.base(), 54338fd1498Szrj __new_start, _M_get_Tp_allocator()); 54438fd1498Szrj 54538fd1498Szrj __new_finish += __n; 54638fd1498Szrj 54738fd1498Szrj __new_finish 54838fd1498Szrj = std::__uninitialized_move_if_noexcept_a 54938fd1498Szrj (__position.base(), this->_M_impl._M_finish, 55038fd1498Szrj __new_finish, _M_get_Tp_allocator()); 55138fd1498Szrj } 55238fd1498Szrj __catch(...) 55338fd1498Szrj { 55438fd1498Szrj if (!__new_finish) 55538fd1498Szrj std::_Destroy(__new_start + __elems_before, 55638fd1498Szrj __new_start + __elems_before + __n, 55738fd1498Szrj _M_get_Tp_allocator()); 55838fd1498Szrj else 55938fd1498Szrj std::_Destroy(__new_start, __new_finish, 56038fd1498Szrj _M_get_Tp_allocator()); 56138fd1498Szrj _M_deallocate(__new_start, __len); 56238fd1498Szrj __throw_exception_again; 56338fd1498Szrj } 56438fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_REINIT; 56538fd1498Szrj std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish, 56638fd1498Szrj _M_get_Tp_allocator()); 56738fd1498Szrj _M_deallocate(this->_M_impl._M_start, 56838fd1498Szrj this->_M_impl._M_end_of_storage 56938fd1498Szrj - this->_M_impl._M_start); 57038fd1498Szrj this->_M_impl._M_start = __new_start; 57138fd1498Szrj this->_M_impl._M_finish = __new_finish; 57238fd1498Szrj this->_M_impl._M_end_of_storage = __new_start + __len; 57338fd1498Szrj } 57438fd1498Szrj } 57538fd1498Szrj } 57638fd1498Szrj 57738fd1498Szrj #if __cplusplus >= 201103L 57838fd1498Szrj template<typename _Tp, typename _Alloc> 57938fd1498Szrj void 58038fd1498Szrj vector<_Tp, _Alloc>:: _M_default_append(size_type __n)58138fd1498Szrj _M_default_append(size_type __n) 58238fd1498Szrj { 58338fd1498Szrj if (__n != 0) 58438fd1498Szrj { 585*58e805e6Szrj const size_type __size = size(); 58638fd1498Szrj size_type __navail = size_type(this->_M_impl._M_end_of_storage 58738fd1498Szrj - this->_M_impl._M_finish); 58838fd1498Szrj 58938fd1498Szrj if (__size > max_size() || __navail > max_size() - __size) 59038fd1498Szrj __builtin_unreachable(); 59138fd1498Szrj 59238fd1498Szrj if (__navail >= __n) 59338fd1498Szrj { 59438fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GROW(__n); 59538fd1498Szrj this->_M_impl._M_finish = 59638fd1498Szrj std::__uninitialized_default_n_a(this->_M_impl._M_finish, 59738fd1498Szrj __n, _M_get_Tp_allocator()); 59838fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GREW(__n); 59938fd1498Szrj } 60038fd1498Szrj else 60138fd1498Szrj { 60238fd1498Szrj const size_type __len = 60338fd1498Szrj _M_check_len(__n, "vector::_M_default_append"); 60438fd1498Szrj pointer __new_start(this->_M_allocate(__len)); 605*58e805e6Szrj pointer __destroy_from = pointer(); 60638fd1498Szrj __try 60738fd1498Szrj { 608*58e805e6Szrj std::__uninitialized_default_n_a(__new_start + __size, 609*58e805e6Szrj __n, _M_get_Tp_allocator()); 610*58e805e6Szrj __destroy_from = __new_start + __size; 611*58e805e6Szrj std::__uninitialized_move_if_noexcept_a( 612*58e805e6Szrj this->_M_impl._M_start, this->_M_impl._M_finish, 61338fd1498Szrj __new_start, _M_get_Tp_allocator()); 61438fd1498Szrj } 61538fd1498Szrj __catch(...) 61638fd1498Szrj { 617*58e805e6Szrj if (__destroy_from) 618*58e805e6Szrj std::_Destroy(__destroy_from, __destroy_from + __n, 61938fd1498Szrj _M_get_Tp_allocator()); 62038fd1498Szrj _M_deallocate(__new_start, __len); 62138fd1498Szrj __throw_exception_again; 62238fd1498Szrj } 62338fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_REINIT; 62438fd1498Szrj std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish, 62538fd1498Szrj _M_get_Tp_allocator()); 62638fd1498Szrj _M_deallocate(this->_M_impl._M_start, 62738fd1498Szrj this->_M_impl._M_end_of_storage 62838fd1498Szrj - this->_M_impl._M_start); 62938fd1498Szrj this->_M_impl._M_start = __new_start; 630*58e805e6Szrj this->_M_impl._M_finish = __new_start + __size + __n; 63138fd1498Szrj this->_M_impl._M_end_of_storage = __new_start + __len; 63238fd1498Szrj } 63338fd1498Szrj } 63438fd1498Szrj } 63538fd1498Szrj 63638fd1498Szrj template<typename _Tp, typename _Alloc> 63738fd1498Szrj bool 63838fd1498Szrj vector<_Tp, _Alloc>:: _M_shrink_to_fit()63938fd1498Szrj _M_shrink_to_fit() 64038fd1498Szrj { 64138fd1498Szrj if (capacity() == size()) 64238fd1498Szrj return false; 64338fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_REINIT; 64438fd1498Szrj return std::__shrink_to_fit_aux<vector>::_S_do_it(*this); 64538fd1498Szrj } 64638fd1498Szrj #endif 64738fd1498Szrj 64838fd1498Szrj template<typename _Tp, typename _Alloc> 64938fd1498Szrj template<typename _InputIterator> 65038fd1498Szrj void 65138fd1498Szrj vector<_Tp, _Alloc>:: _M_range_insert(iterator __pos,_InputIterator __first,_InputIterator __last,std::input_iterator_tag)65238fd1498Szrj _M_range_insert(iterator __pos, _InputIterator __first, 65338fd1498Szrj _InputIterator __last, std::input_iterator_tag) 65438fd1498Szrj { 65538fd1498Szrj if (__pos == end()) 65638fd1498Szrj { 65738fd1498Szrj for (; __first != __last; ++__first) 65838fd1498Szrj insert(end(), *__first); 65938fd1498Szrj } 66038fd1498Szrj else if (__first != __last) 66138fd1498Szrj { 66238fd1498Szrj vector __tmp(__first, __last, _M_get_Tp_allocator()); 66338fd1498Szrj insert(__pos, 66438fd1498Szrj _GLIBCXX_MAKE_MOVE_ITERATOR(__tmp.begin()), 66538fd1498Szrj _GLIBCXX_MAKE_MOVE_ITERATOR(__tmp.end())); 66638fd1498Szrj } 66738fd1498Szrj } 66838fd1498Szrj 66938fd1498Szrj template<typename _Tp, typename _Alloc> 67038fd1498Szrj template<typename _ForwardIterator> 67138fd1498Szrj void 67238fd1498Szrj vector<_Tp, _Alloc>:: _M_range_insert(iterator __position,_ForwardIterator __first,_ForwardIterator __last,std::forward_iterator_tag)67338fd1498Szrj _M_range_insert(iterator __position, _ForwardIterator __first, 67438fd1498Szrj _ForwardIterator __last, std::forward_iterator_tag) 67538fd1498Szrj { 67638fd1498Szrj if (__first != __last) 67738fd1498Szrj { 67838fd1498Szrj const size_type __n = std::distance(__first, __last); 67938fd1498Szrj if (size_type(this->_M_impl._M_end_of_storage 68038fd1498Szrj - this->_M_impl._M_finish) >= __n) 68138fd1498Szrj { 68238fd1498Szrj const size_type __elems_after = end() - __position; 68338fd1498Szrj pointer __old_finish(this->_M_impl._M_finish); 68438fd1498Szrj if (__elems_after > __n) 68538fd1498Szrj { 68638fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GROW(__n); 68738fd1498Szrj std::__uninitialized_move_a(this->_M_impl._M_finish - __n, 68838fd1498Szrj this->_M_impl._M_finish, 68938fd1498Szrj this->_M_impl._M_finish, 69038fd1498Szrj _M_get_Tp_allocator()); 69138fd1498Szrj this->_M_impl._M_finish += __n; 69238fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GREW(__n); 69338fd1498Szrj _GLIBCXX_MOVE_BACKWARD3(__position.base(), 69438fd1498Szrj __old_finish - __n, __old_finish); 69538fd1498Szrj std::copy(__first, __last, __position); 69638fd1498Szrj } 69738fd1498Szrj else 69838fd1498Szrj { 69938fd1498Szrj _ForwardIterator __mid = __first; 70038fd1498Szrj std::advance(__mid, __elems_after); 70138fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GROW(__n); 70238fd1498Szrj std::__uninitialized_copy_a(__mid, __last, 70338fd1498Szrj this->_M_impl._M_finish, 70438fd1498Szrj _M_get_Tp_allocator()); 70538fd1498Szrj this->_M_impl._M_finish += __n - __elems_after; 70638fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GREW(__n - __elems_after); 70738fd1498Szrj std::__uninitialized_move_a(__position.base(), 70838fd1498Szrj __old_finish, 70938fd1498Szrj this->_M_impl._M_finish, 71038fd1498Szrj _M_get_Tp_allocator()); 71138fd1498Szrj this->_M_impl._M_finish += __elems_after; 71238fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GREW(__elems_after); 71338fd1498Szrj std::copy(__first, __mid, __position); 71438fd1498Szrj } 71538fd1498Szrj } 71638fd1498Szrj else 71738fd1498Szrj { 71838fd1498Szrj const size_type __len = 71938fd1498Szrj _M_check_len(__n, "vector::_M_range_insert"); 72038fd1498Szrj pointer __new_start(this->_M_allocate(__len)); 72138fd1498Szrj pointer __new_finish(__new_start); 72238fd1498Szrj __try 72338fd1498Szrj { 72438fd1498Szrj __new_finish 72538fd1498Szrj = std::__uninitialized_move_if_noexcept_a 72638fd1498Szrj (this->_M_impl._M_start, __position.base(), 72738fd1498Szrj __new_start, _M_get_Tp_allocator()); 72838fd1498Szrj __new_finish 72938fd1498Szrj = std::__uninitialized_copy_a(__first, __last, 73038fd1498Szrj __new_finish, 73138fd1498Szrj _M_get_Tp_allocator()); 73238fd1498Szrj __new_finish 73338fd1498Szrj = std::__uninitialized_move_if_noexcept_a 73438fd1498Szrj (__position.base(), this->_M_impl._M_finish, 73538fd1498Szrj __new_finish, _M_get_Tp_allocator()); 73638fd1498Szrj } 73738fd1498Szrj __catch(...) 73838fd1498Szrj { 73938fd1498Szrj std::_Destroy(__new_start, __new_finish, 74038fd1498Szrj _M_get_Tp_allocator()); 74138fd1498Szrj _M_deallocate(__new_start, __len); 74238fd1498Szrj __throw_exception_again; 74338fd1498Szrj } 74438fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_REINIT; 74538fd1498Szrj std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish, 74638fd1498Szrj _M_get_Tp_allocator()); 74738fd1498Szrj _M_deallocate(this->_M_impl._M_start, 74838fd1498Szrj this->_M_impl._M_end_of_storage 74938fd1498Szrj - this->_M_impl._M_start); 75038fd1498Szrj this->_M_impl._M_start = __new_start; 75138fd1498Szrj this->_M_impl._M_finish = __new_finish; 75238fd1498Szrj this->_M_impl._M_end_of_storage = __new_start + __len; 75338fd1498Szrj } 75438fd1498Szrj } 75538fd1498Szrj } 75638fd1498Szrj 75738fd1498Szrj 75838fd1498Szrj // vector<bool> 75938fd1498Szrj template<typename _Alloc> 76038fd1498Szrj void 76138fd1498Szrj vector<bool, _Alloc>:: _M_reallocate(size_type __n)76238fd1498Szrj _M_reallocate(size_type __n) 76338fd1498Szrj { 76438fd1498Szrj _Bit_pointer __q = this->_M_allocate(__n); 76538fd1498Szrj iterator __start(std::__addressof(*__q), 0); 76638fd1498Szrj iterator __finish(_M_copy_aligned(begin(), end(), __start)); 76738fd1498Szrj this->_M_deallocate(); 76838fd1498Szrj this->_M_impl._M_start = __start; 76938fd1498Szrj this->_M_impl._M_finish = __finish; 77038fd1498Szrj this->_M_impl._M_end_of_storage = __q + _S_nword(__n); 77138fd1498Szrj } 77238fd1498Szrj 77338fd1498Szrj template<typename _Alloc> 77438fd1498Szrj void 77538fd1498Szrj vector<bool, _Alloc>:: _M_fill_insert(iterator __position,size_type __n,bool __x)77638fd1498Szrj _M_fill_insert(iterator __position, size_type __n, bool __x) 77738fd1498Szrj { 77838fd1498Szrj if (__n == 0) 77938fd1498Szrj return; 78038fd1498Szrj if (capacity() - size() >= __n) 78138fd1498Szrj { 78238fd1498Szrj std::copy_backward(__position, end(), 78338fd1498Szrj this->_M_impl._M_finish + difference_type(__n)); 78438fd1498Szrj std::fill(__position, __position + difference_type(__n), __x); 78538fd1498Szrj this->_M_impl._M_finish += difference_type(__n); 78638fd1498Szrj } 78738fd1498Szrj else 78838fd1498Szrj { 78938fd1498Szrj const size_type __len = 79038fd1498Szrj _M_check_len(__n, "vector<bool>::_M_fill_insert"); 79138fd1498Szrj _Bit_pointer __q = this->_M_allocate(__len); 79238fd1498Szrj iterator __start(std::__addressof(*__q), 0); 79338fd1498Szrj iterator __i = _M_copy_aligned(begin(), __position, __start); 79438fd1498Szrj std::fill(__i, __i + difference_type(__n), __x); 79538fd1498Szrj iterator __finish = std::copy(__position, end(), 79638fd1498Szrj __i + difference_type(__n)); 79738fd1498Szrj this->_M_deallocate(); 79838fd1498Szrj this->_M_impl._M_end_of_storage = __q + _S_nword(__len); 79938fd1498Szrj this->_M_impl._M_start = __start; 80038fd1498Szrj this->_M_impl._M_finish = __finish; 80138fd1498Szrj } 80238fd1498Szrj } 80338fd1498Szrj 80438fd1498Szrj template<typename _Alloc> 80538fd1498Szrj template<typename _ForwardIterator> 80638fd1498Szrj void 80738fd1498Szrj vector<bool, _Alloc>:: _M_insert_range(iterator __position,_ForwardIterator __first,_ForwardIterator __last,std::forward_iterator_tag)80838fd1498Szrj _M_insert_range(iterator __position, _ForwardIterator __first, 80938fd1498Szrj _ForwardIterator __last, std::forward_iterator_tag) 81038fd1498Szrj { 81138fd1498Szrj if (__first != __last) 81238fd1498Szrj { 81338fd1498Szrj size_type __n = std::distance(__first, __last); 81438fd1498Szrj if (capacity() - size() >= __n) 81538fd1498Szrj { 81638fd1498Szrj std::copy_backward(__position, end(), 81738fd1498Szrj this->_M_impl._M_finish 81838fd1498Szrj + difference_type(__n)); 81938fd1498Szrj std::copy(__first, __last, __position); 82038fd1498Szrj this->_M_impl._M_finish += difference_type(__n); 82138fd1498Szrj } 82238fd1498Szrj else 82338fd1498Szrj { 82438fd1498Szrj const size_type __len = 82538fd1498Szrj _M_check_len(__n, "vector<bool>::_M_insert_range"); 82638fd1498Szrj _Bit_pointer __q = this->_M_allocate(__len); 82738fd1498Szrj iterator __start(std::__addressof(*__q), 0); 82838fd1498Szrj iterator __i = _M_copy_aligned(begin(), __position, __start); 82938fd1498Szrj __i = std::copy(__first, __last, __i); 83038fd1498Szrj iterator __finish = std::copy(__position, end(), __i); 83138fd1498Szrj this->_M_deallocate(); 83238fd1498Szrj this->_M_impl._M_end_of_storage = __q + _S_nword(__len); 83338fd1498Szrj this->_M_impl._M_start = __start; 83438fd1498Szrj this->_M_impl._M_finish = __finish; 83538fd1498Szrj } 83638fd1498Szrj } 83738fd1498Szrj } 83838fd1498Szrj 83938fd1498Szrj template<typename _Alloc> 84038fd1498Szrj void 84138fd1498Szrj vector<bool, _Alloc>:: _M_insert_aux(iterator __position,bool __x)84238fd1498Szrj _M_insert_aux(iterator __position, bool __x) 84338fd1498Szrj { 84438fd1498Szrj if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_addr()) 84538fd1498Szrj { 84638fd1498Szrj std::copy_backward(__position, this->_M_impl._M_finish, 84738fd1498Szrj this->_M_impl._M_finish + 1); 84838fd1498Szrj *__position = __x; 84938fd1498Szrj ++this->_M_impl._M_finish; 85038fd1498Szrj } 85138fd1498Szrj else 85238fd1498Szrj { 85338fd1498Szrj const size_type __len = 85438fd1498Szrj _M_check_len(size_type(1), "vector<bool>::_M_insert_aux"); 85538fd1498Szrj _Bit_pointer __q = this->_M_allocate(__len); 85638fd1498Szrj iterator __start(std::__addressof(*__q), 0); 85738fd1498Szrj iterator __i = _M_copy_aligned(begin(), __position, __start); 85838fd1498Szrj *__i++ = __x; 85938fd1498Szrj iterator __finish = std::copy(__position, end(), __i); 86038fd1498Szrj this->_M_deallocate(); 86138fd1498Szrj this->_M_impl._M_end_of_storage = __q + _S_nword(__len); 86238fd1498Szrj this->_M_impl._M_start = __start; 86338fd1498Szrj this->_M_impl._M_finish = __finish; 86438fd1498Szrj } 86538fd1498Szrj } 86638fd1498Szrj 86738fd1498Szrj template<typename _Alloc> 86838fd1498Szrj typename vector<bool, _Alloc>::iterator 86938fd1498Szrj vector<bool, _Alloc>:: _M_erase(iterator __position)87038fd1498Szrj _M_erase(iterator __position) 87138fd1498Szrj { 87238fd1498Szrj if (__position + 1 != end()) 87338fd1498Szrj std::copy(__position + 1, end(), __position); 87438fd1498Szrj --this->_M_impl._M_finish; 87538fd1498Szrj return __position; 87638fd1498Szrj } 87738fd1498Szrj 87838fd1498Szrj template<typename _Alloc> 87938fd1498Szrj typename vector<bool, _Alloc>::iterator 88038fd1498Szrj vector<bool, _Alloc>:: _M_erase(iterator __first,iterator __last)88138fd1498Szrj _M_erase(iterator __first, iterator __last) 88238fd1498Szrj { 88338fd1498Szrj if (__first != __last) 88438fd1498Szrj _M_erase_at_end(std::copy(__last, end(), __first)); 88538fd1498Szrj return __first; 88638fd1498Szrj } 88738fd1498Szrj 88838fd1498Szrj #if __cplusplus >= 201103L 88938fd1498Szrj template<typename _Alloc> 89038fd1498Szrj bool 89138fd1498Szrj vector<bool, _Alloc>:: _M_shrink_to_fit()89238fd1498Szrj _M_shrink_to_fit() 89338fd1498Szrj { 89438fd1498Szrj if (capacity() - size() < int(_S_word_bit)) 89538fd1498Szrj return false; 89638fd1498Szrj __try 89738fd1498Szrj { 89838fd1498Szrj _M_reallocate(size()); 89938fd1498Szrj return true; 90038fd1498Szrj } 90138fd1498Szrj __catch(...) 90238fd1498Szrj { return false; } 90338fd1498Szrj } 90438fd1498Szrj #endif 90538fd1498Szrj 90638fd1498Szrj _GLIBCXX_END_NAMESPACE_CONTAINER 90738fd1498Szrj _GLIBCXX_END_NAMESPACE_VERSION 90838fd1498Szrj } // namespace std 90938fd1498Szrj 91038fd1498Szrj #if __cplusplus >= 201103L 91138fd1498Szrj 91238fd1498Szrj namespace std _GLIBCXX_VISIBILITY(default) 91338fd1498Szrj { 91438fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_VERSION 91538fd1498Szrj 91638fd1498Szrj template<typename _Alloc> 91738fd1498Szrj size_t 91838fd1498Szrj hash<_GLIBCXX_STD_C::vector<bool, _Alloc>>:: operator ()(const _GLIBCXX_STD_C::vector<bool,_Alloc> & __b) const91938fd1498Szrj operator()(const _GLIBCXX_STD_C::vector<bool, _Alloc>& __b) const noexcept 92038fd1498Szrj { 92138fd1498Szrj size_t __hash = 0; 92238fd1498Szrj using _GLIBCXX_STD_C::_S_word_bit; 92338fd1498Szrj using _GLIBCXX_STD_C::_Bit_type; 92438fd1498Szrj 92538fd1498Szrj const size_t __words = __b.size() / _S_word_bit; 92638fd1498Szrj if (__words) 92738fd1498Szrj { 92838fd1498Szrj const size_t __clength = __words * sizeof(_Bit_type); 92938fd1498Szrj __hash = std::_Hash_impl::hash(__b._M_impl._M_start._M_p, __clength); 93038fd1498Szrj } 93138fd1498Szrj 93238fd1498Szrj const size_t __extrabits = __b.size() % _S_word_bit; 93338fd1498Szrj if (__extrabits) 93438fd1498Szrj { 93538fd1498Szrj _Bit_type __hiword = *__b._M_impl._M_finish._M_p; 93638fd1498Szrj __hiword &= ~((~static_cast<_Bit_type>(0)) << __extrabits); 93738fd1498Szrj 93838fd1498Szrj const size_t __clength 93938fd1498Szrj = (__extrabits + __CHAR_BIT__ - 1) / __CHAR_BIT__; 94038fd1498Szrj if (__words) 94138fd1498Szrj __hash = std::_Hash_impl::hash(&__hiword, __clength, __hash); 94238fd1498Szrj else 94338fd1498Szrj __hash = std::_Hash_impl::hash(&__hiword, __clength); 94438fd1498Szrj } 94538fd1498Szrj 94638fd1498Szrj return __hash; 94738fd1498Szrj } 94838fd1498Szrj 94938fd1498Szrj _GLIBCXX_END_NAMESPACE_VERSION 95038fd1498Szrj } // namespace std 95138fd1498Szrj 95238fd1498Szrj #endif // C++11 95338fd1498Szrj 95438fd1498Szrj #undef _GLIBCXX_ASAN_ANNOTATE_REINIT 95538fd1498Szrj #undef _GLIBCXX_ASAN_ANNOTATE_GROW 95638fd1498Szrj #undef _GLIBCXX_ASAN_ANNOTATE_GREW 95738fd1498Szrj #undef _GLIBCXX_ASAN_ANNOTATE_SHRINK 95838fd1498Szrj 95938fd1498Szrj #endif /* _VECTOR_TCC */ 960