1*38fd1498Szrj // Vector implementation (out of line) -*- C++ -*- 2*38fd1498Szrj 3*38fd1498Szrj // Copyright (C) 2001-2018 Free Software Foundation, Inc. 4*38fd1498Szrj // 5*38fd1498Szrj // This file is part of the GNU ISO C++ Library. This library is free 6*38fd1498Szrj // software; you can redistribute it and/or modify it under the 7*38fd1498Szrj // terms of the GNU General Public License as published by the 8*38fd1498Szrj // Free Software Foundation; either version 3, or (at your option) 9*38fd1498Szrj // any later version. 10*38fd1498Szrj 11*38fd1498Szrj // This library is distributed in the hope that it will be useful, 12*38fd1498Szrj // but WITHOUT ANY WARRANTY; without even the implied warranty of 13*38fd1498Szrj // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14*38fd1498Szrj // GNU General Public License for more details. 15*38fd1498Szrj 16*38fd1498Szrj // Under Section 7 of GPL version 3, you are granted additional 17*38fd1498Szrj // permissions described in the GCC Runtime Library Exception, version 18*38fd1498Szrj // 3.1, as published by the Free Software Foundation. 19*38fd1498Szrj 20*38fd1498Szrj // You should have received a copy of the GNU General Public License and 21*38fd1498Szrj // a copy of the GCC Runtime Library Exception along with this program; 22*38fd1498Szrj // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 23*38fd1498Szrj // <http://www.gnu.org/licenses/>. 24*38fd1498Szrj 25*38fd1498Szrj /* 26*38fd1498Szrj * 27*38fd1498Szrj * Copyright (c) 1994 28*38fd1498Szrj * Hewlett-Packard Company 29*38fd1498Szrj * 30*38fd1498Szrj * Permission to use, copy, modify, distribute and sell this software 31*38fd1498Szrj * and its documentation for any purpose is hereby granted without fee, 32*38fd1498Szrj * provided that the above copyright notice appear in all copies and 33*38fd1498Szrj * that both that copyright notice and this permission notice appear 34*38fd1498Szrj * in supporting documentation. Hewlett-Packard Company makes no 35*38fd1498Szrj * representations about the suitability of this software for any 36*38fd1498Szrj * purpose. It is provided "as is" without express or implied warranty. 37*38fd1498Szrj * 38*38fd1498Szrj * 39*38fd1498Szrj * Copyright (c) 1996 40*38fd1498Szrj * Silicon Graphics Computer Systems, Inc. 41*38fd1498Szrj * 42*38fd1498Szrj * Permission to use, copy, modify, distribute and sell this software 43*38fd1498Szrj * and its documentation for any purpose is hereby granted without fee, 44*38fd1498Szrj * provided that the above copyright notice appear in all copies and 45*38fd1498Szrj * that both that copyright notice and this permission notice appear 46*38fd1498Szrj * in supporting documentation. Silicon Graphics makes no 47*38fd1498Szrj * representations about the suitability of this software for any 48*38fd1498Szrj * purpose. It is provided "as is" without express or implied warranty. 49*38fd1498Szrj */ 50*38fd1498Szrj 51*38fd1498Szrj /** @file bits/vector.tcc 52*38fd1498Szrj * This is an internal header file, included by other library headers. 53*38fd1498Szrj * Do not attempt to use it directly. @headername{vector} 54*38fd1498Szrj */ 55*38fd1498Szrj 56*38fd1498Szrj #ifndef _VECTOR_TCC 57*38fd1498Szrj #define _VECTOR_TCC 1 58*38fd1498Szrj 59*38fd1498Szrj namespace std _GLIBCXX_VISIBILITY(default) 60*38fd1498Szrj { 61*38fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_VERSION 62*38fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_CONTAINER 63*38fd1498Szrj 64*38fd1498Szrj template<typename _Tp, typename _Alloc> 65*38fd1498Szrj void 66*38fd1498Szrj vector<_Tp, _Alloc>:: 67*38fd1498Szrj reserve(size_type __n) 68*38fd1498Szrj { 69*38fd1498Szrj if (__n > this->max_size()) 70*38fd1498Szrj __throw_length_error(__N("vector::reserve")); 71*38fd1498Szrj if (this->capacity() < __n) 72*38fd1498Szrj { 73*38fd1498Szrj const size_type __old_size = size(); 74*38fd1498Szrj pointer __tmp = _M_allocate_and_copy(__n, 75*38fd1498Szrj _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(this->_M_impl._M_start), 76*38fd1498Szrj _GLIBCXX_MAKE_MOVE_IF_NOEXCEPT_ITERATOR(this->_M_impl._M_finish)); 77*38fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_REINIT; 78*38fd1498Szrj std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish, 79*38fd1498Szrj _M_get_Tp_allocator()); 80*38fd1498Szrj _M_deallocate(this->_M_impl._M_start, 81*38fd1498Szrj this->_M_impl._M_end_of_storage 82*38fd1498Szrj - this->_M_impl._M_start); 83*38fd1498Szrj this->_M_impl._M_start = __tmp; 84*38fd1498Szrj this->_M_impl._M_finish = __tmp + __old_size; 85*38fd1498Szrj this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n; 86*38fd1498Szrj } 87*38fd1498Szrj } 88*38fd1498Szrj 89*38fd1498Szrj #if __cplusplus >= 201103L 90*38fd1498Szrj template<typename _Tp, typename _Alloc> 91*38fd1498Szrj template<typename... _Args> 92*38fd1498Szrj #if __cplusplus > 201402L 93*38fd1498Szrj typename vector<_Tp, _Alloc>::reference 94*38fd1498Szrj #else 95*38fd1498Szrj void 96*38fd1498Szrj #endif 97*38fd1498Szrj vector<_Tp, _Alloc>:: 98*38fd1498Szrj emplace_back(_Args&&... __args) 99*38fd1498Szrj { 100*38fd1498Szrj if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage) 101*38fd1498Szrj { 102*38fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GROW(1); 103*38fd1498Szrj _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish, 104*38fd1498Szrj std::forward<_Args>(__args)...); 105*38fd1498Szrj ++this->_M_impl._M_finish; 106*38fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GREW(1); 107*38fd1498Szrj } 108*38fd1498Szrj else 109*38fd1498Szrj _M_realloc_insert(end(), std::forward<_Args>(__args)...); 110*38fd1498Szrj #if __cplusplus > 201402L 111*38fd1498Szrj return back(); 112*38fd1498Szrj #endif 113*38fd1498Szrj } 114*38fd1498Szrj #endif 115*38fd1498Szrj 116*38fd1498Szrj template<typename _Tp, typename _Alloc> 117*38fd1498Szrj typename vector<_Tp, _Alloc>::iterator 118*38fd1498Szrj vector<_Tp, _Alloc>:: 119*38fd1498Szrj #if __cplusplus >= 201103L 120*38fd1498Szrj insert(const_iterator __position, const value_type& __x) 121*38fd1498Szrj #else 122*38fd1498Szrj insert(iterator __position, const value_type& __x) 123*38fd1498Szrj #endif 124*38fd1498Szrj { 125*38fd1498Szrj const size_type __n = __position - begin(); 126*38fd1498Szrj if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage) 127*38fd1498Szrj if (__position == end()) 128*38fd1498Szrj { 129*38fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GROW(1); 130*38fd1498Szrj _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish, 131*38fd1498Szrj __x); 132*38fd1498Szrj ++this->_M_impl._M_finish; 133*38fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GREW(1); 134*38fd1498Szrj } 135*38fd1498Szrj else 136*38fd1498Szrj { 137*38fd1498Szrj #if __cplusplus >= 201103L 138*38fd1498Szrj const auto __pos = begin() + (__position - cbegin()); 139*38fd1498Szrj // __x could be an existing element of this vector, so make a 140*38fd1498Szrj // copy of it before _M_insert_aux moves elements around. 141*38fd1498Szrj _Temporary_value __x_copy(this, __x); 142*38fd1498Szrj _M_insert_aux(__pos, std::move(__x_copy._M_val())); 143*38fd1498Szrj #else 144*38fd1498Szrj _M_insert_aux(__position, __x); 145*38fd1498Szrj #endif 146*38fd1498Szrj } 147*38fd1498Szrj else 148*38fd1498Szrj #if __cplusplus >= 201103L 149*38fd1498Szrj _M_realloc_insert(begin() + (__position - cbegin()), __x); 150*38fd1498Szrj #else 151*38fd1498Szrj _M_realloc_insert(__position, __x); 152*38fd1498Szrj #endif 153*38fd1498Szrj 154*38fd1498Szrj return iterator(this->_M_impl._M_start + __n); 155*38fd1498Szrj } 156*38fd1498Szrj 157*38fd1498Szrj template<typename _Tp, typename _Alloc> 158*38fd1498Szrj typename vector<_Tp, _Alloc>::iterator 159*38fd1498Szrj vector<_Tp, _Alloc>:: 160*38fd1498Szrj _M_erase(iterator __position) 161*38fd1498Szrj { 162*38fd1498Szrj if (__position + 1 != end()) 163*38fd1498Szrj _GLIBCXX_MOVE3(__position + 1, end(), __position); 164*38fd1498Szrj --this->_M_impl._M_finish; 165*38fd1498Szrj _Alloc_traits::destroy(this->_M_impl, this->_M_impl._M_finish); 166*38fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_SHRINK(1); 167*38fd1498Szrj return __position; 168*38fd1498Szrj } 169*38fd1498Szrj 170*38fd1498Szrj template<typename _Tp, typename _Alloc> 171*38fd1498Szrj typename vector<_Tp, _Alloc>::iterator 172*38fd1498Szrj vector<_Tp, _Alloc>:: 173*38fd1498Szrj _M_erase(iterator __first, iterator __last) 174*38fd1498Szrj { 175*38fd1498Szrj if (__first != __last) 176*38fd1498Szrj { 177*38fd1498Szrj if (__last != end()) 178*38fd1498Szrj _GLIBCXX_MOVE3(__last, end(), __first); 179*38fd1498Szrj _M_erase_at_end(__first.base() + (end() - __last)); 180*38fd1498Szrj } 181*38fd1498Szrj return __first; 182*38fd1498Szrj } 183*38fd1498Szrj 184*38fd1498Szrj template<typename _Tp, typename _Alloc> 185*38fd1498Szrj vector<_Tp, _Alloc>& 186*38fd1498Szrj vector<_Tp, _Alloc>:: 187*38fd1498Szrj operator=(const vector<_Tp, _Alloc>& __x) 188*38fd1498Szrj { 189*38fd1498Szrj if (&__x != this) 190*38fd1498Szrj { 191*38fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_REINIT; 192*38fd1498Szrj #if __cplusplus >= 201103L 193*38fd1498Szrj if (_Alloc_traits::_S_propagate_on_copy_assign()) 194*38fd1498Szrj { 195*38fd1498Szrj if (!_Alloc_traits::_S_always_equal() 196*38fd1498Szrj && _M_get_Tp_allocator() != __x._M_get_Tp_allocator()) 197*38fd1498Szrj { 198*38fd1498Szrj // replacement allocator cannot free existing storage 199*38fd1498Szrj this->clear(); 200*38fd1498Szrj _M_deallocate(this->_M_impl._M_start, 201*38fd1498Szrj this->_M_impl._M_end_of_storage 202*38fd1498Szrj - this->_M_impl._M_start); 203*38fd1498Szrj this->_M_impl._M_start = nullptr; 204*38fd1498Szrj this->_M_impl._M_finish = nullptr; 205*38fd1498Szrj this->_M_impl._M_end_of_storage = nullptr; 206*38fd1498Szrj } 207*38fd1498Szrj std::__alloc_on_copy(_M_get_Tp_allocator(), 208*38fd1498Szrj __x._M_get_Tp_allocator()); 209*38fd1498Szrj } 210*38fd1498Szrj #endif 211*38fd1498Szrj const size_type __xlen = __x.size(); 212*38fd1498Szrj if (__xlen > capacity()) 213*38fd1498Szrj { 214*38fd1498Szrj pointer __tmp = _M_allocate_and_copy(__xlen, __x.begin(), 215*38fd1498Szrj __x.end()); 216*38fd1498Szrj std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish, 217*38fd1498Szrj _M_get_Tp_allocator()); 218*38fd1498Szrj _M_deallocate(this->_M_impl._M_start, 219*38fd1498Szrj this->_M_impl._M_end_of_storage 220*38fd1498Szrj - this->_M_impl._M_start); 221*38fd1498Szrj this->_M_impl._M_start = __tmp; 222*38fd1498Szrj this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __xlen; 223*38fd1498Szrj } 224*38fd1498Szrj else if (size() >= __xlen) 225*38fd1498Szrj { 226*38fd1498Szrj std::_Destroy(std::copy(__x.begin(), __x.end(), begin()), 227*38fd1498Szrj end(), _M_get_Tp_allocator()); 228*38fd1498Szrj } 229*38fd1498Szrj else 230*38fd1498Szrj { 231*38fd1498Szrj std::copy(__x._M_impl._M_start, __x._M_impl._M_start + size(), 232*38fd1498Szrj this->_M_impl._M_start); 233*38fd1498Szrj std::__uninitialized_copy_a(__x._M_impl._M_start + size(), 234*38fd1498Szrj __x._M_impl._M_finish, 235*38fd1498Szrj this->_M_impl._M_finish, 236*38fd1498Szrj _M_get_Tp_allocator()); 237*38fd1498Szrj } 238*38fd1498Szrj this->_M_impl._M_finish = this->_M_impl._M_start + __xlen; 239*38fd1498Szrj } 240*38fd1498Szrj return *this; 241*38fd1498Szrj } 242*38fd1498Szrj 243*38fd1498Szrj template<typename _Tp, typename _Alloc> 244*38fd1498Szrj void 245*38fd1498Szrj vector<_Tp, _Alloc>:: 246*38fd1498Szrj _M_fill_assign(size_t __n, const value_type& __val) 247*38fd1498Szrj { 248*38fd1498Szrj if (__n > capacity()) 249*38fd1498Szrj { 250*38fd1498Szrj vector __tmp(__n, __val, _M_get_Tp_allocator()); 251*38fd1498Szrj __tmp._M_impl._M_swap_data(this->_M_impl); 252*38fd1498Szrj } 253*38fd1498Szrj else if (__n > size()) 254*38fd1498Szrj { 255*38fd1498Szrj std::fill(begin(), end(), __val); 256*38fd1498Szrj const size_type __add = __n - size(); 257*38fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GROW(__add); 258*38fd1498Szrj this->_M_impl._M_finish = 259*38fd1498Szrj std::__uninitialized_fill_n_a(this->_M_impl._M_finish, 260*38fd1498Szrj __add, __val, _M_get_Tp_allocator()); 261*38fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GREW(__add); 262*38fd1498Szrj } 263*38fd1498Szrj else 264*38fd1498Szrj _M_erase_at_end(std::fill_n(this->_M_impl._M_start, __n, __val)); 265*38fd1498Szrj } 266*38fd1498Szrj 267*38fd1498Szrj template<typename _Tp, typename _Alloc> 268*38fd1498Szrj template<typename _InputIterator> 269*38fd1498Szrj void 270*38fd1498Szrj vector<_Tp, _Alloc>:: 271*38fd1498Szrj _M_assign_aux(_InputIterator __first, _InputIterator __last, 272*38fd1498Szrj std::input_iterator_tag) 273*38fd1498Szrj { 274*38fd1498Szrj pointer __cur(this->_M_impl._M_start); 275*38fd1498Szrj for (; __first != __last && __cur != this->_M_impl._M_finish; 276*38fd1498Szrj ++__cur, ++__first) 277*38fd1498Szrj *__cur = *__first; 278*38fd1498Szrj if (__first == __last) 279*38fd1498Szrj _M_erase_at_end(__cur); 280*38fd1498Szrj else 281*38fd1498Szrj _M_range_insert(end(), __first, __last, 282*38fd1498Szrj std::__iterator_category(__first)); 283*38fd1498Szrj } 284*38fd1498Szrj 285*38fd1498Szrj template<typename _Tp, typename _Alloc> 286*38fd1498Szrj template<typename _ForwardIterator> 287*38fd1498Szrj void 288*38fd1498Szrj vector<_Tp, _Alloc>:: 289*38fd1498Szrj _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last, 290*38fd1498Szrj std::forward_iterator_tag) 291*38fd1498Szrj { 292*38fd1498Szrj const size_type __len = std::distance(__first, __last); 293*38fd1498Szrj 294*38fd1498Szrj if (__len > capacity()) 295*38fd1498Szrj { 296*38fd1498Szrj pointer __tmp(_M_allocate_and_copy(__len, __first, __last)); 297*38fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_REINIT; 298*38fd1498Szrj std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish, 299*38fd1498Szrj _M_get_Tp_allocator()); 300*38fd1498Szrj _M_deallocate(this->_M_impl._M_start, 301*38fd1498Szrj this->_M_impl._M_end_of_storage 302*38fd1498Szrj - this->_M_impl._M_start); 303*38fd1498Szrj this->_M_impl._M_start = __tmp; 304*38fd1498Szrj this->_M_impl._M_finish = this->_M_impl._M_start + __len; 305*38fd1498Szrj this->_M_impl._M_end_of_storage = this->_M_impl._M_finish; 306*38fd1498Szrj } 307*38fd1498Szrj else if (size() >= __len) 308*38fd1498Szrj _M_erase_at_end(std::copy(__first, __last, this->_M_impl._M_start)); 309*38fd1498Szrj else 310*38fd1498Szrj { 311*38fd1498Szrj _ForwardIterator __mid = __first; 312*38fd1498Szrj std::advance(__mid, size()); 313*38fd1498Szrj std::copy(__first, __mid, this->_M_impl._M_start); 314*38fd1498Szrj const size_type __attribute__((__unused__)) __n = __len - size(); 315*38fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GROW(__n); 316*38fd1498Szrj this->_M_impl._M_finish = 317*38fd1498Szrj std::__uninitialized_copy_a(__mid, __last, 318*38fd1498Szrj this->_M_impl._M_finish, 319*38fd1498Szrj _M_get_Tp_allocator()); 320*38fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GREW(__n); 321*38fd1498Szrj } 322*38fd1498Szrj } 323*38fd1498Szrj 324*38fd1498Szrj #if __cplusplus >= 201103L 325*38fd1498Szrj template<typename _Tp, typename _Alloc> 326*38fd1498Szrj auto 327*38fd1498Szrj vector<_Tp, _Alloc>:: 328*38fd1498Szrj _M_insert_rval(const_iterator __position, value_type&& __v) -> iterator 329*38fd1498Szrj { 330*38fd1498Szrj const auto __n = __position - cbegin(); 331*38fd1498Szrj if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage) 332*38fd1498Szrj if (__position == cend()) 333*38fd1498Szrj { 334*38fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GROW(1); 335*38fd1498Szrj _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish, 336*38fd1498Szrj std::move(__v)); 337*38fd1498Szrj ++this->_M_impl._M_finish; 338*38fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GREW(1); 339*38fd1498Szrj } 340*38fd1498Szrj else 341*38fd1498Szrj _M_insert_aux(begin() + __n, std::move(__v)); 342*38fd1498Szrj else 343*38fd1498Szrj _M_realloc_insert(begin() + __n, std::move(__v)); 344*38fd1498Szrj 345*38fd1498Szrj return iterator(this->_M_impl._M_start + __n); 346*38fd1498Szrj } 347*38fd1498Szrj 348*38fd1498Szrj template<typename _Tp, typename _Alloc> 349*38fd1498Szrj template<typename... _Args> 350*38fd1498Szrj auto 351*38fd1498Szrj vector<_Tp, _Alloc>:: 352*38fd1498Szrj _M_emplace_aux(const_iterator __position, _Args&&... __args) 353*38fd1498Szrj -> iterator 354*38fd1498Szrj { 355*38fd1498Szrj const auto __n = __position - cbegin(); 356*38fd1498Szrj if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage) 357*38fd1498Szrj if (__position == cend()) 358*38fd1498Szrj { 359*38fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GROW(1); 360*38fd1498Szrj _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish, 361*38fd1498Szrj std::forward<_Args>(__args)...); 362*38fd1498Szrj ++this->_M_impl._M_finish; 363*38fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GREW(1); 364*38fd1498Szrj } 365*38fd1498Szrj else 366*38fd1498Szrj { 367*38fd1498Szrj // We need to construct a temporary because something in __args... 368*38fd1498Szrj // could alias one of the elements of the container and so we 369*38fd1498Szrj // need to use it before _M_insert_aux moves elements around. 370*38fd1498Szrj _Temporary_value __tmp(this, std::forward<_Args>(__args)...); 371*38fd1498Szrj _M_insert_aux(begin() + __n, std::move(__tmp._M_val())); 372*38fd1498Szrj } 373*38fd1498Szrj else 374*38fd1498Szrj _M_realloc_insert(begin() + __n, std::forward<_Args>(__args)...); 375*38fd1498Szrj 376*38fd1498Szrj return iterator(this->_M_impl._M_start + __n); 377*38fd1498Szrj } 378*38fd1498Szrj 379*38fd1498Szrj template<typename _Tp, typename _Alloc> 380*38fd1498Szrj template<typename _Arg> 381*38fd1498Szrj void 382*38fd1498Szrj vector<_Tp, _Alloc>:: 383*38fd1498Szrj _M_insert_aux(iterator __position, _Arg&& __arg) 384*38fd1498Szrj #else 385*38fd1498Szrj template<typename _Tp, typename _Alloc> 386*38fd1498Szrj void 387*38fd1498Szrj vector<_Tp, _Alloc>:: 388*38fd1498Szrj _M_insert_aux(iterator __position, const _Tp& __x) 389*38fd1498Szrj #endif 390*38fd1498Szrj { 391*38fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GROW(1); 392*38fd1498Szrj _Alloc_traits::construct(this->_M_impl, this->_M_impl._M_finish, 393*38fd1498Szrj _GLIBCXX_MOVE(*(this->_M_impl._M_finish - 1))); 394*38fd1498Szrj ++this->_M_impl._M_finish; 395*38fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GREW(1); 396*38fd1498Szrj #if __cplusplus < 201103L 397*38fd1498Szrj _Tp __x_copy = __x; 398*38fd1498Szrj #endif 399*38fd1498Szrj _GLIBCXX_MOVE_BACKWARD3(__position.base(), 400*38fd1498Szrj this->_M_impl._M_finish - 2, 401*38fd1498Szrj this->_M_impl._M_finish - 1); 402*38fd1498Szrj #if __cplusplus < 201103L 403*38fd1498Szrj *__position = __x_copy; 404*38fd1498Szrj #else 405*38fd1498Szrj *__position = std::forward<_Arg>(__arg); 406*38fd1498Szrj #endif 407*38fd1498Szrj } 408*38fd1498Szrj 409*38fd1498Szrj #if __cplusplus >= 201103L 410*38fd1498Szrj template<typename _Tp, typename _Alloc> 411*38fd1498Szrj template<typename... _Args> 412*38fd1498Szrj void 413*38fd1498Szrj vector<_Tp, _Alloc>:: 414*38fd1498Szrj _M_realloc_insert(iterator __position, _Args&&... __args) 415*38fd1498Szrj #else 416*38fd1498Szrj template<typename _Tp, typename _Alloc> 417*38fd1498Szrj void 418*38fd1498Szrj vector<_Tp, _Alloc>:: 419*38fd1498Szrj _M_realloc_insert(iterator __position, const _Tp& __x) 420*38fd1498Szrj #endif 421*38fd1498Szrj { 422*38fd1498Szrj const size_type __len = 423*38fd1498Szrj _M_check_len(size_type(1), "vector::_M_realloc_insert"); 424*38fd1498Szrj pointer __old_start = this->_M_impl._M_start; 425*38fd1498Szrj pointer __old_finish = this->_M_impl._M_finish; 426*38fd1498Szrj const size_type __elems_before = __position - begin(); 427*38fd1498Szrj pointer __new_start(this->_M_allocate(__len)); 428*38fd1498Szrj pointer __new_finish(__new_start); 429*38fd1498Szrj __try 430*38fd1498Szrj { 431*38fd1498Szrj // The order of the three operations is dictated by the C++11 432*38fd1498Szrj // case, where the moves could alter a new element belonging 433*38fd1498Szrj // to the existing vector. This is an issue only for callers 434*38fd1498Szrj // taking the element by lvalue ref (see last bullet of C++11 435*38fd1498Szrj // [res.on.arguments]). 436*38fd1498Szrj _Alloc_traits::construct(this->_M_impl, 437*38fd1498Szrj __new_start + __elems_before, 438*38fd1498Szrj #if __cplusplus >= 201103L 439*38fd1498Szrj std::forward<_Args>(__args)...); 440*38fd1498Szrj #else 441*38fd1498Szrj __x); 442*38fd1498Szrj #endif 443*38fd1498Szrj __new_finish = pointer(); 444*38fd1498Szrj 445*38fd1498Szrj __new_finish 446*38fd1498Szrj = std::__uninitialized_move_if_noexcept_a 447*38fd1498Szrj (__old_start, __position.base(), 448*38fd1498Szrj __new_start, _M_get_Tp_allocator()); 449*38fd1498Szrj 450*38fd1498Szrj ++__new_finish; 451*38fd1498Szrj 452*38fd1498Szrj __new_finish 453*38fd1498Szrj = std::__uninitialized_move_if_noexcept_a 454*38fd1498Szrj (__position.base(), __old_finish, 455*38fd1498Szrj __new_finish, _M_get_Tp_allocator()); 456*38fd1498Szrj } 457*38fd1498Szrj __catch(...) 458*38fd1498Szrj { 459*38fd1498Szrj if (!__new_finish) 460*38fd1498Szrj _Alloc_traits::destroy(this->_M_impl, 461*38fd1498Szrj __new_start + __elems_before); 462*38fd1498Szrj else 463*38fd1498Szrj std::_Destroy(__new_start, __new_finish, _M_get_Tp_allocator()); 464*38fd1498Szrj _M_deallocate(__new_start, __len); 465*38fd1498Szrj __throw_exception_again; 466*38fd1498Szrj } 467*38fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_REINIT; 468*38fd1498Szrj std::_Destroy(__old_start, __old_finish, _M_get_Tp_allocator()); 469*38fd1498Szrj _M_deallocate(__old_start, 470*38fd1498Szrj this->_M_impl._M_end_of_storage - __old_start); 471*38fd1498Szrj this->_M_impl._M_start = __new_start; 472*38fd1498Szrj this->_M_impl._M_finish = __new_finish; 473*38fd1498Szrj this->_M_impl._M_end_of_storage = __new_start + __len; 474*38fd1498Szrj } 475*38fd1498Szrj 476*38fd1498Szrj template<typename _Tp, typename _Alloc> 477*38fd1498Szrj void 478*38fd1498Szrj vector<_Tp, _Alloc>:: 479*38fd1498Szrj _M_fill_insert(iterator __position, size_type __n, const value_type& __x) 480*38fd1498Szrj { 481*38fd1498Szrj if (__n != 0) 482*38fd1498Szrj { 483*38fd1498Szrj if (size_type(this->_M_impl._M_end_of_storage 484*38fd1498Szrj - this->_M_impl._M_finish) >= __n) 485*38fd1498Szrj { 486*38fd1498Szrj #if __cplusplus < 201103L 487*38fd1498Szrj value_type __x_copy = __x; 488*38fd1498Szrj #else 489*38fd1498Szrj _Temporary_value __tmp(this, __x); 490*38fd1498Szrj value_type& __x_copy = __tmp._M_val(); 491*38fd1498Szrj #endif 492*38fd1498Szrj const size_type __elems_after = end() - __position; 493*38fd1498Szrj pointer __old_finish(this->_M_impl._M_finish); 494*38fd1498Szrj if (__elems_after > __n) 495*38fd1498Szrj { 496*38fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GROW(__n); 497*38fd1498Szrj std::__uninitialized_move_a(this->_M_impl._M_finish - __n, 498*38fd1498Szrj this->_M_impl._M_finish, 499*38fd1498Szrj this->_M_impl._M_finish, 500*38fd1498Szrj _M_get_Tp_allocator()); 501*38fd1498Szrj this->_M_impl._M_finish += __n; 502*38fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GREW(__n); 503*38fd1498Szrj _GLIBCXX_MOVE_BACKWARD3(__position.base(), 504*38fd1498Szrj __old_finish - __n, __old_finish); 505*38fd1498Szrj std::fill(__position.base(), __position.base() + __n, 506*38fd1498Szrj __x_copy); 507*38fd1498Szrj } 508*38fd1498Szrj else 509*38fd1498Szrj { 510*38fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GROW(__n); 511*38fd1498Szrj this->_M_impl._M_finish = 512*38fd1498Szrj std::__uninitialized_fill_n_a(this->_M_impl._M_finish, 513*38fd1498Szrj __n - __elems_after, 514*38fd1498Szrj __x_copy, 515*38fd1498Szrj _M_get_Tp_allocator()); 516*38fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GREW(__n - __elems_after); 517*38fd1498Szrj std::__uninitialized_move_a(__position.base(), __old_finish, 518*38fd1498Szrj this->_M_impl._M_finish, 519*38fd1498Szrj _M_get_Tp_allocator()); 520*38fd1498Szrj this->_M_impl._M_finish += __elems_after; 521*38fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GREW(__elems_after); 522*38fd1498Szrj std::fill(__position.base(), __old_finish, __x_copy); 523*38fd1498Szrj } 524*38fd1498Szrj } 525*38fd1498Szrj else 526*38fd1498Szrj { 527*38fd1498Szrj const size_type __len = 528*38fd1498Szrj _M_check_len(__n, "vector::_M_fill_insert"); 529*38fd1498Szrj const size_type __elems_before = __position - begin(); 530*38fd1498Szrj pointer __new_start(this->_M_allocate(__len)); 531*38fd1498Szrj pointer __new_finish(__new_start); 532*38fd1498Szrj __try 533*38fd1498Szrj { 534*38fd1498Szrj // See _M_realloc_insert above. 535*38fd1498Szrj std::__uninitialized_fill_n_a(__new_start + __elems_before, 536*38fd1498Szrj __n, __x, 537*38fd1498Szrj _M_get_Tp_allocator()); 538*38fd1498Szrj __new_finish = pointer(); 539*38fd1498Szrj 540*38fd1498Szrj __new_finish 541*38fd1498Szrj = std::__uninitialized_move_if_noexcept_a 542*38fd1498Szrj (this->_M_impl._M_start, __position.base(), 543*38fd1498Szrj __new_start, _M_get_Tp_allocator()); 544*38fd1498Szrj 545*38fd1498Szrj __new_finish += __n; 546*38fd1498Szrj 547*38fd1498Szrj __new_finish 548*38fd1498Szrj = std::__uninitialized_move_if_noexcept_a 549*38fd1498Szrj (__position.base(), this->_M_impl._M_finish, 550*38fd1498Szrj __new_finish, _M_get_Tp_allocator()); 551*38fd1498Szrj } 552*38fd1498Szrj __catch(...) 553*38fd1498Szrj { 554*38fd1498Szrj if (!__new_finish) 555*38fd1498Szrj std::_Destroy(__new_start + __elems_before, 556*38fd1498Szrj __new_start + __elems_before + __n, 557*38fd1498Szrj _M_get_Tp_allocator()); 558*38fd1498Szrj else 559*38fd1498Szrj std::_Destroy(__new_start, __new_finish, 560*38fd1498Szrj _M_get_Tp_allocator()); 561*38fd1498Szrj _M_deallocate(__new_start, __len); 562*38fd1498Szrj __throw_exception_again; 563*38fd1498Szrj } 564*38fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_REINIT; 565*38fd1498Szrj std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish, 566*38fd1498Szrj _M_get_Tp_allocator()); 567*38fd1498Szrj _M_deallocate(this->_M_impl._M_start, 568*38fd1498Szrj this->_M_impl._M_end_of_storage 569*38fd1498Szrj - this->_M_impl._M_start); 570*38fd1498Szrj this->_M_impl._M_start = __new_start; 571*38fd1498Szrj this->_M_impl._M_finish = __new_finish; 572*38fd1498Szrj this->_M_impl._M_end_of_storage = __new_start + __len; 573*38fd1498Szrj } 574*38fd1498Szrj } 575*38fd1498Szrj } 576*38fd1498Szrj 577*38fd1498Szrj #if __cplusplus >= 201103L 578*38fd1498Szrj template<typename _Tp, typename _Alloc> 579*38fd1498Szrj void 580*38fd1498Szrj vector<_Tp, _Alloc>:: 581*38fd1498Szrj _M_default_append(size_type __n) 582*38fd1498Szrj { 583*38fd1498Szrj if (__n != 0) 584*38fd1498Szrj { 585*38fd1498Szrj size_type __size = size(); 586*38fd1498Szrj size_type __navail = size_type(this->_M_impl._M_end_of_storage 587*38fd1498Szrj - this->_M_impl._M_finish); 588*38fd1498Szrj 589*38fd1498Szrj if (__size > max_size() || __navail > max_size() - __size) 590*38fd1498Szrj __builtin_unreachable(); 591*38fd1498Szrj 592*38fd1498Szrj if (__navail >= __n) 593*38fd1498Szrj { 594*38fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GROW(__n); 595*38fd1498Szrj this->_M_impl._M_finish = 596*38fd1498Szrj std::__uninitialized_default_n_a(this->_M_impl._M_finish, 597*38fd1498Szrj __n, _M_get_Tp_allocator()); 598*38fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GREW(__n); 599*38fd1498Szrj } 600*38fd1498Szrj else 601*38fd1498Szrj { 602*38fd1498Szrj const size_type __len = 603*38fd1498Szrj _M_check_len(__n, "vector::_M_default_append"); 604*38fd1498Szrj const size_type __old_size = __size; 605*38fd1498Szrj pointer __new_start(this->_M_allocate(__len)); 606*38fd1498Szrj pointer __new_finish(__new_start); 607*38fd1498Szrj __try 608*38fd1498Szrj { 609*38fd1498Szrj __new_finish 610*38fd1498Szrj = std::__uninitialized_move_if_noexcept_a 611*38fd1498Szrj (this->_M_impl._M_start, this->_M_impl._M_finish, 612*38fd1498Szrj __new_start, _M_get_Tp_allocator()); 613*38fd1498Szrj __new_finish = 614*38fd1498Szrj std::__uninitialized_default_n_a(__new_finish, __n, 615*38fd1498Szrj _M_get_Tp_allocator()); 616*38fd1498Szrj } 617*38fd1498Szrj __catch(...) 618*38fd1498Szrj { 619*38fd1498Szrj std::_Destroy(__new_start, __new_finish, 620*38fd1498Szrj _M_get_Tp_allocator()); 621*38fd1498Szrj _M_deallocate(__new_start, __len); 622*38fd1498Szrj __throw_exception_again; 623*38fd1498Szrj } 624*38fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_REINIT; 625*38fd1498Szrj std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish, 626*38fd1498Szrj _M_get_Tp_allocator()); 627*38fd1498Szrj _M_deallocate(this->_M_impl._M_start, 628*38fd1498Szrj this->_M_impl._M_end_of_storage 629*38fd1498Szrj - this->_M_impl._M_start); 630*38fd1498Szrj this->_M_impl._M_start = __new_start; 631*38fd1498Szrj this->_M_impl._M_finish = __new_finish; 632*38fd1498Szrj this->_M_impl._M_end_of_storage = __new_start + __len; 633*38fd1498Szrj } 634*38fd1498Szrj } 635*38fd1498Szrj } 636*38fd1498Szrj 637*38fd1498Szrj template<typename _Tp, typename _Alloc> 638*38fd1498Szrj bool 639*38fd1498Szrj vector<_Tp, _Alloc>:: 640*38fd1498Szrj _M_shrink_to_fit() 641*38fd1498Szrj { 642*38fd1498Szrj if (capacity() == size()) 643*38fd1498Szrj return false; 644*38fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_REINIT; 645*38fd1498Szrj return std::__shrink_to_fit_aux<vector>::_S_do_it(*this); 646*38fd1498Szrj } 647*38fd1498Szrj #endif 648*38fd1498Szrj 649*38fd1498Szrj template<typename _Tp, typename _Alloc> 650*38fd1498Szrj template<typename _InputIterator> 651*38fd1498Szrj void 652*38fd1498Szrj vector<_Tp, _Alloc>:: 653*38fd1498Szrj _M_range_insert(iterator __pos, _InputIterator __first, 654*38fd1498Szrj _InputIterator __last, std::input_iterator_tag) 655*38fd1498Szrj { 656*38fd1498Szrj if (__pos == end()) 657*38fd1498Szrj { 658*38fd1498Szrj for (; __first != __last; ++__first) 659*38fd1498Szrj insert(end(), *__first); 660*38fd1498Szrj } 661*38fd1498Szrj else if (__first != __last) 662*38fd1498Szrj { 663*38fd1498Szrj vector __tmp(__first, __last, _M_get_Tp_allocator()); 664*38fd1498Szrj insert(__pos, 665*38fd1498Szrj _GLIBCXX_MAKE_MOVE_ITERATOR(__tmp.begin()), 666*38fd1498Szrj _GLIBCXX_MAKE_MOVE_ITERATOR(__tmp.end())); 667*38fd1498Szrj } 668*38fd1498Szrj } 669*38fd1498Szrj 670*38fd1498Szrj template<typename _Tp, typename _Alloc> 671*38fd1498Szrj template<typename _ForwardIterator> 672*38fd1498Szrj void 673*38fd1498Szrj vector<_Tp, _Alloc>:: 674*38fd1498Szrj _M_range_insert(iterator __position, _ForwardIterator __first, 675*38fd1498Szrj _ForwardIterator __last, std::forward_iterator_tag) 676*38fd1498Szrj { 677*38fd1498Szrj if (__first != __last) 678*38fd1498Szrj { 679*38fd1498Szrj const size_type __n = std::distance(__first, __last); 680*38fd1498Szrj if (size_type(this->_M_impl._M_end_of_storage 681*38fd1498Szrj - this->_M_impl._M_finish) >= __n) 682*38fd1498Szrj { 683*38fd1498Szrj const size_type __elems_after = end() - __position; 684*38fd1498Szrj pointer __old_finish(this->_M_impl._M_finish); 685*38fd1498Szrj if (__elems_after > __n) 686*38fd1498Szrj { 687*38fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GROW(__n); 688*38fd1498Szrj std::__uninitialized_move_a(this->_M_impl._M_finish - __n, 689*38fd1498Szrj this->_M_impl._M_finish, 690*38fd1498Szrj this->_M_impl._M_finish, 691*38fd1498Szrj _M_get_Tp_allocator()); 692*38fd1498Szrj this->_M_impl._M_finish += __n; 693*38fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GREW(__n); 694*38fd1498Szrj _GLIBCXX_MOVE_BACKWARD3(__position.base(), 695*38fd1498Szrj __old_finish - __n, __old_finish); 696*38fd1498Szrj std::copy(__first, __last, __position); 697*38fd1498Szrj } 698*38fd1498Szrj else 699*38fd1498Szrj { 700*38fd1498Szrj _ForwardIterator __mid = __first; 701*38fd1498Szrj std::advance(__mid, __elems_after); 702*38fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GROW(__n); 703*38fd1498Szrj std::__uninitialized_copy_a(__mid, __last, 704*38fd1498Szrj this->_M_impl._M_finish, 705*38fd1498Szrj _M_get_Tp_allocator()); 706*38fd1498Szrj this->_M_impl._M_finish += __n - __elems_after; 707*38fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GREW(__n - __elems_after); 708*38fd1498Szrj std::__uninitialized_move_a(__position.base(), 709*38fd1498Szrj __old_finish, 710*38fd1498Szrj this->_M_impl._M_finish, 711*38fd1498Szrj _M_get_Tp_allocator()); 712*38fd1498Szrj this->_M_impl._M_finish += __elems_after; 713*38fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_GREW(__elems_after); 714*38fd1498Szrj std::copy(__first, __mid, __position); 715*38fd1498Szrj } 716*38fd1498Szrj } 717*38fd1498Szrj else 718*38fd1498Szrj { 719*38fd1498Szrj const size_type __len = 720*38fd1498Szrj _M_check_len(__n, "vector::_M_range_insert"); 721*38fd1498Szrj pointer __new_start(this->_M_allocate(__len)); 722*38fd1498Szrj pointer __new_finish(__new_start); 723*38fd1498Szrj __try 724*38fd1498Szrj { 725*38fd1498Szrj __new_finish 726*38fd1498Szrj = std::__uninitialized_move_if_noexcept_a 727*38fd1498Szrj (this->_M_impl._M_start, __position.base(), 728*38fd1498Szrj __new_start, _M_get_Tp_allocator()); 729*38fd1498Szrj __new_finish 730*38fd1498Szrj = std::__uninitialized_copy_a(__first, __last, 731*38fd1498Szrj __new_finish, 732*38fd1498Szrj _M_get_Tp_allocator()); 733*38fd1498Szrj __new_finish 734*38fd1498Szrj = std::__uninitialized_move_if_noexcept_a 735*38fd1498Szrj (__position.base(), this->_M_impl._M_finish, 736*38fd1498Szrj __new_finish, _M_get_Tp_allocator()); 737*38fd1498Szrj } 738*38fd1498Szrj __catch(...) 739*38fd1498Szrj { 740*38fd1498Szrj std::_Destroy(__new_start, __new_finish, 741*38fd1498Szrj _M_get_Tp_allocator()); 742*38fd1498Szrj _M_deallocate(__new_start, __len); 743*38fd1498Szrj __throw_exception_again; 744*38fd1498Szrj } 745*38fd1498Szrj _GLIBCXX_ASAN_ANNOTATE_REINIT; 746*38fd1498Szrj std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish, 747*38fd1498Szrj _M_get_Tp_allocator()); 748*38fd1498Szrj _M_deallocate(this->_M_impl._M_start, 749*38fd1498Szrj this->_M_impl._M_end_of_storage 750*38fd1498Szrj - this->_M_impl._M_start); 751*38fd1498Szrj this->_M_impl._M_start = __new_start; 752*38fd1498Szrj this->_M_impl._M_finish = __new_finish; 753*38fd1498Szrj this->_M_impl._M_end_of_storage = __new_start + __len; 754*38fd1498Szrj } 755*38fd1498Szrj } 756*38fd1498Szrj } 757*38fd1498Szrj 758*38fd1498Szrj 759*38fd1498Szrj // vector<bool> 760*38fd1498Szrj template<typename _Alloc> 761*38fd1498Szrj void 762*38fd1498Szrj vector<bool, _Alloc>:: 763*38fd1498Szrj _M_reallocate(size_type __n) 764*38fd1498Szrj { 765*38fd1498Szrj _Bit_pointer __q = this->_M_allocate(__n); 766*38fd1498Szrj iterator __start(std::__addressof(*__q), 0); 767*38fd1498Szrj iterator __finish(_M_copy_aligned(begin(), end(), __start)); 768*38fd1498Szrj this->_M_deallocate(); 769*38fd1498Szrj this->_M_impl._M_start = __start; 770*38fd1498Szrj this->_M_impl._M_finish = __finish; 771*38fd1498Szrj this->_M_impl._M_end_of_storage = __q + _S_nword(__n); 772*38fd1498Szrj } 773*38fd1498Szrj 774*38fd1498Szrj template<typename _Alloc> 775*38fd1498Szrj void 776*38fd1498Szrj vector<bool, _Alloc>:: 777*38fd1498Szrj _M_fill_insert(iterator __position, size_type __n, bool __x) 778*38fd1498Szrj { 779*38fd1498Szrj if (__n == 0) 780*38fd1498Szrj return; 781*38fd1498Szrj if (capacity() - size() >= __n) 782*38fd1498Szrj { 783*38fd1498Szrj std::copy_backward(__position, end(), 784*38fd1498Szrj this->_M_impl._M_finish + difference_type(__n)); 785*38fd1498Szrj std::fill(__position, __position + difference_type(__n), __x); 786*38fd1498Szrj this->_M_impl._M_finish += difference_type(__n); 787*38fd1498Szrj } 788*38fd1498Szrj else 789*38fd1498Szrj { 790*38fd1498Szrj const size_type __len = 791*38fd1498Szrj _M_check_len(__n, "vector<bool>::_M_fill_insert"); 792*38fd1498Szrj _Bit_pointer __q = this->_M_allocate(__len); 793*38fd1498Szrj iterator __start(std::__addressof(*__q), 0); 794*38fd1498Szrj iterator __i = _M_copy_aligned(begin(), __position, __start); 795*38fd1498Szrj std::fill(__i, __i + difference_type(__n), __x); 796*38fd1498Szrj iterator __finish = std::copy(__position, end(), 797*38fd1498Szrj __i + difference_type(__n)); 798*38fd1498Szrj this->_M_deallocate(); 799*38fd1498Szrj this->_M_impl._M_end_of_storage = __q + _S_nword(__len); 800*38fd1498Szrj this->_M_impl._M_start = __start; 801*38fd1498Szrj this->_M_impl._M_finish = __finish; 802*38fd1498Szrj } 803*38fd1498Szrj } 804*38fd1498Szrj 805*38fd1498Szrj template<typename _Alloc> 806*38fd1498Szrj template<typename _ForwardIterator> 807*38fd1498Szrj void 808*38fd1498Szrj vector<bool, _Alloc>:: 809*38fd1498Szrj _M_insert_range(iterator __position, _ForwardIterator __first, 810*38fd1498Szrj _ForwardIterator __last, std::forward_iterator_tag) 811*38fd1498Szrj { 812*38fd1498Szrj if (__first != __last) 813*38fd1498Szrj { 814*38fd1498Szrj size_type __n = std::distance(__first, __last); 815*38fd1498Szrj if (capacity() - size() >= __n) 816*38fd1498Szrj { 817*38fd1498Szrj std::copy_backward(__position, end(), 818*38fd1498Szrj this->_M_impl._M_finish 819*38fd1498Szrj + difference_type(__n)); 820*38fd1498Szrj std::copy(__first, __last, __position); 821*38fd1498Szrj this->_M_impl._M_finish += difference_type(__n); 822*38fd1498Szrj } 823*38fd1498Szrj else 824*38fd1498Szrj { 825*38fd1498Szrj const size_type __len = 826*38fd1498Szrj _M_check_len(__n, "vector<bool>::_M_insert_range"); 827*38fd1498Szrj _Bit_pointer __q = this->_M_allocate(__len); 828*38fd1498Szrj iterator __start(std::__addressof(*__q), 0); 829*38fd1498Szrj iterator __i = _M_copy_aligned(begin(), __position, __start); 830*38fd1498Szrj __i = std::copy(__first, __last, __i); 831*38fd1498Szrj iterator __finish = std::copy(__position, end(), __i); 832*38fd1498Szrj this->_M_deallocate(); 833*38fd1498Szrj this->_M_impl._M_end_of_storage = __q + _S_nword(__len); 834*38fd1498Szrj this->_M_impl._M_start = __start; 835*38fd1498Szrj this->_M_impl._M_finish = __finish; 836*38fd1498Szrj } 837*38fd1498Szrj } 838*38fd1498Szrj } 839*38fd1498Szrj 840*38fd1498Szrj template<typename _Alloc> 841*38fd1498Szrj void 842*38fd1498Szrj vector<bool, _Alloc>:: 843*38fd1498Szrj _M_insert_aux(iterator __position, bool __x) 844*38fd1498Szrj { 845*38fd1498Szrj if (this->_M_impl._M_finish._M_p != this->_M_impl._M_end_addr()) 846*38fd1498Szrj { 847*38fd1498Szrj std::copy_backward(__position, this->_M_impl._M_finish, 848*38fd1498Szrj this->_M_impl._M_finish + 1); 849*38fd1498Szrj *__position = __x; 850*38fd1498Szrj ++this->_M_impl._M_finish; 851*38fd1498Szrj } 852*38fd1498Szrj else 853*38fd1498Szrj { 854*38fd1498Szrj const size_type __len = 855*38fd1498Szrj _M_check_len(size_type(1), "vector<bool>::_M_insert_aux"); 856*38fd1498Szrj _Bit_pointer __q = this->_M_allocate(__len); 857*38fd1498Szrj iterator __start(std::__addressof(*__q), 0); 858*38fd1498Szrj iterator __i = _M_copy_aligned(begin(), __position, __start); 859*38fd1498Szrj *__i++ = __x; 860*38fd1498Szrj iterator __finish = std::copy(__position, end(), __i); 861*38fd1498Szrj this->_M_deallocate(); 862*38fd1498Szrj this->_M_impl._M_end_of_storage = __q + _S_nword(__len); 863*38fd1498Szrj this->_M_impl._M_start = __start; 864*38fd1498Szrj this->_M_impl._M_finish = __finish; 865*38fd1498Szrj } 866*38fd1498Szrj } 867*38fd1498Szrj 868*38fd1498Szrj template<typename _Alloc> 869*38fd1498Szrj typename vector<bool, _Alloc>::iterator 870*38fd1498Szrj vector<bool, _Alloc>:: 871*38fd1498Szrj _M_erase(iterator __position) 872*38fd1498Szrj { 873*38fd1498Szrj if (__position + 1 != end()) 874*38fd1498Szrj std::copy(__position + 1, end(), __position); 875*38fd1498Szrj --this->_M_impl._M_finish; 876*38fd1498Szrj return __position; 877*38fd1498Szrj } 878*38fd1498Szrj 879*38fd1498Szrj template<typename _Alloc> 880*38fd1498Szrj typename vector<bool, _Alloc>::iterator 881*38fd1498Szrj vector<bool, _Alloc>:: 882*38fd1498Szrj _M_erase(iterator __first, iterator __last) 883*38fd1498Szrj { 884*38fd1498Szrj if (__first != __last) 885*38fd1498Szrj _M_erase_at_end(std::copy(__last, end(), __first)); 886*38fd1498Szrj return __first; 887*38fd1498Szrj } 888*38fd1498Szrj 889*38fd1498Szrj #if __cplusplus >= 201103L 890*38fd1498Szrj template<typename _Alloc> 891*38fd1498Szrj bool 892*38fd1498Szrj vector<bool, _Alloc>:: 893*38fd1498Szrj _M_shrink_to_fit() 894*38fd1498Szrj { 895*38fd1498Szrj if (capacity() - size() < int(_S_word_bit)) 896*38fd1498Szrj return false; 897*38fd1498Szrj __try 898*38fd1498Szrj { 899*38fd1498Szrj _M_reallocate(size()); 900*38fd1498Szrj return true; 901*38fd1498Szrj } 902*38fd1498Szrj __catch(...) 903*38fd1498Szrj { return false; } 904*38fd1498Szrj } 905*38fd1498Szrj #endif 906*38fd1498Szrj 907*38fd1498Szrj _GLIBCXX_END_NAMESPACE_CONTAINER 908*38fd1498Szrj _GLIBCXX_END_NAMESPACE_VERSION 909*38fd1498Szrj } // namespace std 910*38fd1498Szrj 911*38fd1498Szrj #if __cplusplus >= 201103L 912*38fd1498Szrj 913*38fd1498Szrj namespace std _GLIBCXX_VISIBILITY(default) 914*38fd1498Szrj { 915*38fd1498Szrj _GLIBCXX_BEGIN_NAMESPACE_VERSION 916*38fd1498Szrj 917*38fd1498Szrj template<typename _Alloc> 918*38fd1498Szrj size_t 919*38fd1498Szrj hash<_GLIBCXX_STD_C::vector<bool, _Alloc>>:: 920*38fd1498Szrj operator()(const _GLIBCXX_STD_C::vector<bool, _Alloc>& __b) const noexcept 921*38fd1498Szrj { 922*38fd1498Szrj size_t __hash = 0; 923*38fd1498Szrj using _GLIBCXX_STD_C::_S_word_bit; 924*38fd1498Szrj using _GLIBCXX_STD_C::_Bit_type; 925*38fd1498Szrj 926*38fd1498Szrj const size_t __words = __b.size() / _S_word_bit; 927*38fd1498Szrj if (__words) 928*38fd1498Szrj { 929*38fd1498Szrj const size_t __clength = __words * sizeof(_Bit_type); 930*38fd1498Szrj __hash = std::_Hash_impl::hash(__b._M_impl._M_start._M_p, __clength); 931*38fd1498Szrj } 932*38fd1498Szrj 933*38fd1498Szrj const size_t __extrabits = __b.size() % _S_word_bit; 934*38fd1498Szrj if (__extrabits) 935*38fd1498Szrj { 936*38fd1498Szrj _Bit_type __hiword = *__b._M_impl._M_finish._M_p; 937*38fd1498Szrj __hiword &= ~((~static_cast<_Bit_type>(0)) << __extrabits); 938*38fd1498Szrj 939*38fd1498Szrj const size_t __clength 940*38fd1498Szrj = (__extrabits + __CHAR_BIT__ - 1) / __CHAR_BIT__; 941*38fd1498Szrj if (__words) 942*38fd1498Szrj __hash = std::_Hash_impl::hash(&__hiword, __clength, __hash); 943*38fd1498Szrj else 944*38fd1498Szrj __hash = std::_Hash_impl::hash(&__hiword, __clength); 945*38fd1498Szrj } 946*38fd1498Szrj 947*38fd1498Szrj return __hash; 948*38fd1498Szrj } 949*38fd1498Szrj 950*38fd1498Szrj _GLIBCXX_END_NAMESPACE_VERSION 951*38fd1498Szrj } // namespace std 952*38fd1498Szrj 953*38fd1498Szrj #endif // C++11 954*38fd1498Szrj 955*38fd1498Szrj #undef _GLIBCXX_ASAN_ANNOTATE_REINIT 956*38fd1498Szrj #undef _GLIBCXX_ASAN_ANNOTATE_GROW 957*38fd1498Szrj #undef _GLIBCXX_ASAN_ANNOTATE_GREW 958*38fd1498Szrj #undef _GLIBCXX_ASAN_ANNOTATE_SHRINK 959*38fd1498Szrj 960*38fd1498Szrj #endif /* _VECTOR_TCC */ 961