1*404b540aSrobert // Vector implementation -*- C++ -*- 2*404b540aSrobert 3*404b540aSrobert // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 4*404b540aSrobert // Free Software Foundation, Inc. 5*404b540aSrobert // 6*404b540aSrobert // This file is part of the GNU ISO C++ Library. This library is free 7*404b540aSrobert // software; you can redistribute it and/or modify it under the 8*404b540aSrobert // terms of the GNU General Public License as published by the 9*404b540aSrobert // Free Software Foundation; either version 2, or (at your option) 10*404b540aSrobert // any later version. 11*404b540aSrobert 12*404b540aSrobert // This library is distributed in the hope that it will be useful, 13*404b540aSrobert // but WITHOUT ANY WARRANTY; without even the implied warranty of 14*404b540aSrobert // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*404b540aSrobert // GNU General Public License for more details. 16*404b540aSrobert 17*404b540aSrobert // You should have received a copy of the GNU General Public License along 18*404b540aSrobert // with this library; see the file COPYING. If not, write to the Free 19*404b540aSrobert // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 20*404b540aSrobert // USA. 21*404b540aSrobert 22*404b540aSrobert // As a special exception, you may use this file as part of a free software 23*404b540aSrobert // library without restriction. Specifically, if other files instantiate 24*404b540aSrobert // templates or use macros or inline functions from this file, or you compile 25*404b540aSrobert // this file and link it with other files to produce an executable, this 26*404b540aSrobert // file does not by itself cause the resulting executable to be covered by 27*404b540aSrobert // the GNU General Public License. This exception does not however 28*404b540aSrobert // invalidate any other reasons why the executable file might be covered by 29*404b540aSrobert // the GNU General Public License. 30*404b540aSrobert 31*404b540aSrobert /* 32*404b540aSrobert * 33*404b540aSrobert * Copyright (c) 1994 34*404b540aSrobert * Hewlett-Packard Company 35*404b540aSrobert * 36*404b540aSrobert * Permission to use, copy, modify, distribute and sell this software 37*404b540aSrobert * and its documentation for any purpose is hereby granted without fee, 38*404b540aSrobert * provided that the above copyright notice appear in all copies and 39*404b540aSrobert * that both that copyright notice and this permission notice appear 40*404b540aSrobert * in supporting documentation. Hewlett-Packard Company makes no 41*404b540aSrobert * representations about the suitability of this software for any 42*404b540aSrobert * purpose. It is provided "as is" without express or implied warranty. 43*404b540aSrobert * 44*404b540aSrobert * 45*404b540aSrobert * Copyright (c) 1996 46*404b540aSrobert * Silicon Graphics Computer Systems, Inc. 47*404b540aSrobert * 48*404b540aSrobert * Permission to use, copy, modify, distribute and sell this software 49*404b540aSrobert * and its documentation for any purpose is hereby granted without fee, 50*404b540aSrobert * provided that the above copyright notice appear in all copies and 51*404b540aSrobert * that both that copyright notice and this permission notice appear 52*404b540aSrobert * in supporting documentation. Silicon Graphics makes no 53*404b540aSrobert * representations about the suitability of this software for any 54*404b540aSrobert * purpose. It is provided "as is" without express or implied warranty. 55*404b540aSrobert */ 56*404b540aSrobert 57*404b540aSrobert /** @file stl_vector.h 58*404b540aSrobert * This is an internal header file, included by other library headers. 59*404b540aSrobert * You should not attempt to use it directly. 60*404b540aSrobert */ 61*404b540aSrobert 62*404b540aSrobert #ifndef _VECTOR_H 63*404b540aSrobert #define _VECTOR_H 1 64*404b540aSrobert 65*404b540aSrobert #include <bits/stl_iterator_base_funcs.h> 66*404b540aSrobert #include <bits/functexcept.h> 67*404b540aSrobert #include <bits/concept_check.h> 68*404b540aSrobert 69*404b540aSrobert _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD) 70*404b540aSrobert 71*404b540aSrobert /** 72*404b540aSrobert * @if maint 73*404b540aSrobert * See bits/stl_deque.h's _Deque_base for an explanation. 74*404b540aSrobert * @endif 75*404b540aSrobert */ 76*404b540aSrobert template<typename _Tp, typename _Alloc> 77*404b540aSrobert struct _Vector_base 78*404b540aSrobert { 79*404b540aSrobert typedef typename _Alloc::template rebind<_Tp>::other _Tp_alloc_type; 80*404b540aSrobert 81*404b540aSrobert struct _Vector_impl 82*404b540aSrobert : public _Tp_alloc_type 83*404b540aSrobert { 84*404b540aSrobert _Tp* _M_start; 85*404b540aSrobert _Tp* _M_finish; 86*404b540aSrobert _Tp* _M_end_of_storage; _Vector_impl_Vector_base::_Vector_impl87*404b540aSrobert _Vector_impl(_Tp_alloc_type const& __a) 88*404b540aSrobert : _Tp_alloc_type(__a), _M_start(0), _M_finish(0), _M_end_of_storage(0) 89*404b540aSrobert { } 90*404b540aSrobert }; 91*404b540aSrobert 92*404b540aSrobert public: 93*404b540aSrobert typedef _Alloc allocator_type; 94*404b540aSrobert 95*404b540aSrobert _Tp_alloc_type& _M_get_Tp_allocator_Vector_base96*404b540aSrobert _M_get_Tp_allocator() 97*404b540aSrobert { return *static_cast<_Tp_alloc_type*>(&this->_M_impl); } 98*404b540aSrobert 99*404b540aSrobert const _Tp_alloc_type& _M_get_Tp_allocator_Vector_base100*404b540aSrobert _M_get_Tp_allocator() const 101*404b540aSrobert { return *static_cast<const _Tp_alloc_type*>(&this->_M_impl); } 102*404b540aSrobert 103*404b540aSrobert allocator_type get_allocator_Vector_base104*404b540aSrobert get_allocator() const 105*404b540aSrobert { return allocator_type(_M_get_Tp_allocator()); } 106*404b540aSrobert _Vector_base_Vector_base107*404b540aSrobert _Vector_base(const allocator_type& __a) 108*404b540aSrobert : _M_impl(__a) 109*404b540aSrobert { } 110*404b540aSrobert _Vector_base_Vector_base111*404b540aSrobert _Vector_base(size_t __n, const allocator_type& __a) 112*404b540aSrobert : _M_impl(__a) 113*404b540aSrobert { 114*404b540aSrobert this->_M_impl._M_start = this->_M_allocate(__n); 115*404b540aSrobert this->_M_impl._M_finish = this->_M_impl._M_start; 116*404b540aSrobert this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n; 117*404b540aSrobert } 118*404b540aSrobert ~_Vector_base_Vector_base119*404b540aSrobert ~_Vector_base() 120*404b540aSrobert { _M_deallocate(this->_M_impl._M_start, this->_M_impl._M_end_of_storage 121*404b540aSrobert - this->_M_impl._M_start); } 122*404b540aSrobert 123*404b540aSrobert public: 124*404b540aSrobert _Vector_impl _M_impl; 125*404b540aSrobert 126*404b540aSrobert _Tp* _M_allocate_Vector_base127*404b540aSrobert _M_allocate(size_t __n) 128*404b540aSrobert { return _M_impl.allocate(__n); } 129*404b540aSrobert 130*404b540aSrobert void _M_deallocate_Vector_base131*404b540aSrobert _M_deallocate(_Tp* __p, size_t __n) 132*404b540aSrobert { 133*404b540aSrobert if (__p) 134*404b540aSrobert _M_impl.deallocate(__p, __n); 135*404b540aSrobert } 136*404b540aSrobert }; 137*404b540aSrobert 138*404b540aSrobert 139*404b540aSrobert /** 140*404b540aSrobert * @brief A standard container which offers fixed time access to 141*404b540aSrobert * individual elements in any order. 142*404b540aSrobert * 143*404b540aSrobert * @ingroup Containers 144*404b540aSrobert * @ingroup Sequences 145*404b540aSrobert * 146*404b540aSrobert * Meets the requirements of a <a href="tables.html#65">container</a>, a 147*404b540aSrobert * <a href="tables.html#66">reversible container</a>, and a 148*404b540aSrobert * <a href="tables.html#67">sequence</a>, including the 149*404b540aSrobert * <a href="tables.html#68">optional sequence requirements</a> with the 150*404b540aSrobert * %exception of @c push_front and @c pop_front. 151*404b540aSrobert * 152*404b540aSrobert * In some terminology a %vector can be described as a dynamic 153*404b540aSrobert * C-style array, it offers fast and efficient access to individual 154*404b540aSrobert * elements in any order and saves the user from worrying about 155*404b540aSrobert * memory and size allocation. Subscripting ( @c [] ) access is 156*404b540aSrobert * also provided as with C-style arrays. 157*404b540aSrobert */ 158*404b540aSrobert template<typename _Tp, typename _Alloc = std::allocator<_Tp> > 159*404b540aSrobert class vector : protected _Vector_base<_Tp, _Alloc> 160*404b540aSrobert { 161*404b540aSrobert // Concept requirements. 162*404b540aSrobert typedef typename _Alloc::value_type _Alloc_value_type; 163*404b540aSrobert __glibcxx_class_requires(_Tp, _SGIAssignableConcept) 164*404b540aSrobert __glibcxx_class_requires2(_Tp, _Alloc_value_type, _SameTypeConcept) 165*404b540aSrobert 166*404b540aSrobert typedef _Vector_base<_Tp, _Alloc> _Base; 167*404b540aSrobert typedef vector<_Tp, _Alloc> vector_type; 168*404b540aSrobert typedef typename _Base::_Tp_alloc_type _Tp_alloc_type; 169*404b540aSrobert 170*404b540aSrobert public: 171*404b540aSrobert typedef _Tp value_type; 172*404b540aSrobert typedef typename _Tp_alloc_type::pointer pointer; 173*404b540aSrobert typedef typename _Tp_alloc_type::const_pointer const_pointer; 174*404b540aSrobert typedef typename _Tp_alloc_type::reference reference; 175*404b540aSrobert typedef typename _Tp_alloc_type::const_reference const_reference; 176*404b540aSrobert typedef __gnu_cxx::__normal_iterator<pointer, vector_type> iterator; 177*404b540aSrobert typedef __gnu_cxx::__normal_iterator<const_pointer, vector_type> 178*404b540aSrobert const_iterator; 179*404b540aSrobert typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 180*404b540aSrobert typedef std::reverse_iterator<iterator> reverse_iterator; 181*404b540aSrobert typedef size_t size_type; 182*404b540aSrobert typedef ptrdiff_t difference_type; 183*404b540aSrobert typedef _Alloc allocator_type; 184*404b540aSrobert 185*404b540aSrobert protected: 186*404b540aSrobert using _Base::_M_allocate; 187*404b540aSrobert using _Base::_M_deallocate; 188*404b540aSrobert using _Base::_M_impl; 189*404b540aSrobert using _Base::_M_get_Tp_allocator; 190*404b540aSrobert 191*404b540aSrobert public: 192*404b540aSrobert // [23.2.4.1] construct/copy/destroy 193*404b540aSrobert // (assign() and get_allocator() are also listed in this section) 194*404b540aSrobert /** 195*404b540aSrobert * @brief Default constructor creates no elements. 196*404b540aSrobert */ 197*404b540aSrobert explicit 198*404b540aSrobert vector(const allocator_type& __a = allocator_type()) _Base(__a)199*404b540aSrobert : _Base(__a) 200*404b540aSrobert { } 201*404b540aSrobert 202*404b540aSrobert /** 203*404b540aSrobert * @brief Create a %vector with copies of an exemplar element. 204*404b540aSrobert * @param n The number of elements to initially create. 205*404b540aSrobert * @param value An element to copy. 206*404b540aSrobert * 207*404b540aSrobert * This constructor fills the %vector with @a n copies of @a value. 208*404b540aSrobert */ 209*404b540aSrobert explicit 210*404b540aSrobert vector(size_type __n, const value_type& __value = value_type(), 211*404b540aSrobert const allocator_type& __a = allocator_type()) _Base(__n,__a)212*404b540aSrobert : _Base(__n, __a) 213*404b540aSrobert { 214*404b540aSrobert std::__uninitialized_fill_n_a(this->_M_impl._M_start, __n, __value, 215*404b540aSrobert _M_get_Tp_allocator()); 216*404b540aSrobert this->_M_impl._M_finish = this->_M_impl._M_start + __n; 217*404b540aSrobert } 218*404b540aSrobert 219*404b540aSrobert /** 220*404b540aSrobert * @brief %Vector copy constructor. 221*404b540aSrobert * @param x A %vector of identical element and allocator types. 222*404b540aSrobert * 223*404b540aSrobert * The newly-created %vector uses a copy of the allocation 224*404b540aSrobert * object used by @a x. All the elements of @a x are copied, 225*404b540aSrobert * but any extra memory in 226*404b540aSrobert * @a x (for fast expansion) will not be copied. 227*404b540aSrobert */ vector(const vector & __x)228*404b540aSrobert vector(const vector& __x) 229*404b540aSrobert : _Base(__x.size(), __x._M_get_Tp_allocator()) 230*404b540aSrobert { this->_M_impl._M_finish = 231*404b540aSrobert std::__uninitialized_copy_a(__x.begin(), __x.end(), 232*404b540aSrobert this->_M_impl._M_start, 233*404b540aSrobert _M_get_Tp_allocator()); 234*404b540aSrobert } 235*404b540aSrobert 236*404b540aSrobert /** 237*404b540aSrobert * @brief Builds a %vector from a range. 238*404b540aSrobert * @param first An input iterator. 239*404b540aSrobert * @param last An input iterator. 240*404b540aSrobert * 241*404b540aSrobert * Create a %vector consisting of copies of the elements from 242*404b540aSrobert * [first,last). 243*404b540aSrobert * 244*404b540aSrobert * If the iterators are forward, bidirectional, or 245*404b540aSrobert * random-access, then this will call the elements' copy 246*404b540aSrobert * constructor N times (where N is distance(first,last)) and do 247*404b540aSrobert * no memory reallocation. But if only input iterators are 248*404b540aSrobert * used, then this will do at most 2N calls to the copy 249*404b540aSrobert * constructor, and logN memory reallocations. 250*404b540aSrobert */ 251*404b540aSrobert template<typename _InputIterator> 252*404b540aSrobert vector(_InputIterator __first, _InputIterator __last, 253*404b540aSrobert const allocator_type& __a = allocator_type()) _Base(__a)254*404b540aSrobert : _Base(__a) 255*404b540aSrobert { 256*404b540aSrobert // Check whether it's an integral type. If so, it's not an iterator. 257*404b540aSrobert typedef typename std::__is_integer<_InputIterator>::__type _Integral; 258*404b540aSrobert _M_initialize_dispatch(__first, __last, _Integral()); 259*404b540aSrobert } 260*404b540aSrobert 261*404b540aSrobert /** 262*404b540aSrobert * The dtor only erases the elements, and note that if the 263*404b540aSrobert * elements themselves are pointers, the pointed-to memory is 264*404b540aSrobert * not touched in any way. Managing the pointer is the user's 265*404b540aSrobert * responsibilty. 266*404b540aSrobert */ ~vector()267*404b540aSrobert ~vector() 268*404b540aSrobert { std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish, 269*404b540aSrobert _M_get_Tp_allocator()); } 270*404b540aSrobert 271*404b540aSrobert /** 272*404b540aSrobert * @brief %Vector assignment operator. 273*404b540aSrobert * @param x A %vector of identical element and allocator types. 274*404b540aSrobert * 275*404b540aSrobert * All the elements of @a x are copied, but any extra memory in 276*404b540aSrobert * @a x (for fast expansion) will not be copied. Unlike the 277*404b540aSrobert * copy constructor, the allocator object is not copied. 278*404b540aSrobert */ 279*404b540aSrobert vector& 280*404b540aSrobert operator=(const vector& __x); 281*404b540aSrobert 282*404b540aSrobert /** 283*404b540aSrobert * @brief Assigns a given value to a %vector. 284*404b540aSrobert * @param n Number of elements to be assigned. 285*404b540aSrobert * @param val Value to be assigned. 286*404b540aSrobert * 287*404b540aSrobert * This function fills a %vector with @a n copies of the given 288*404b540aSrobert * value. Note that the assignment completely changes the 289*404b540aSrobert * %vector and that the resulting %vector's size is the same as 290*404b540aSrobert * the number of elements assigned. Old data may be lost. 291*404b540aSrobert */ 292*404b540aSrobert void assign(size_type __n,const value_type & __val)293*404b540aSrobert assign(size_type __n, const value_type& __val) 294*404b540aSrobert { _M_fill_assign(__n, __val); } 295*404b540aSrobert 296*404b540aSrobert /** 297*404b540aSrobert * @brief Assigns a range to a %vector. 298*404b540aSrobert * @param first An input iterator. 299*404b540aSrobert * @param last An input iterator. 300*404b540aSrobert * 301*404b540aSrobert * This function fills a %vector with copies of the elements in the 302*404b540aSrobert * range [first,last). 303*404b540aSrobert * 304*404b540aSrobert * Note that the assignment completely changes the %vector and 305*404b540aSrobert * that the resulting %vector's size is the same as the number 306*404b540aSrobert * of elements assigned. Old data may be lost. 307*404b540aSrobert */ 308*404b540aSrobert template<typename _InputIterator> 309*404b540aSrobert void assign(_InputIterator __first,_InputIterator __last)310*404b540aSrobert assign(_InputIterator __first, _InputIterator __last) 311*404b540aSrobert { 312*404b540aSrobert // Check whether it's an integral type. If so, it's not an iterator. 313*404b540aSrobert typedef typename std::__is_integer<_InputIterator>::__type _Integral; 314*404b540aSrobert _M_assign_dispatch(__first, __last, _Integral()); 315*404b540aSrobert } 316*404b540aSrobert 317*404b540aSrobert /// Get a copy of the memory allocation object. 318*404b540aSrobert using _Base::get_allocator; 319*404b540aSrobert 320*404b540aSrobert // iterators 321*404b540aSrobert /** 322*404b540aSrobert * Returns a read/write iterator that points to the first 323*404b540aSrobert * element in the %vector. Iteration is done in ordinary 324*404b540aSrobert * element order. 325*404b540aSrobert */ 326*404b540aSrobert iterator begin()327*404b540aSrobert begin() 328*404b540aSrobert { return iterator(this->_M_impl._M_start); } 329*404b540aSrobert 330*404b540aSrobert /** 331*404b540aSrobert * Returns a read-only (constant) iterator that points to the 332*404b540aSrobert * first element in the %vector. Iteration is done in ordinary 333*404b540aSrobert * element order. 334*404b540aSrobert */ 335*404b540aSrobert const_iterator begin()336*404b540aSrobert begin() const 337*404b540aSrobert { return const_iterator(this->_M_impl._M_start); } 338*404b540aSrobert 339*404b540aSrobert /** 340*404b540aSrobert * Returns a read/write iterator that points one past the last 341*404b540aSrobert * element in the %vector. Iteration is done in ordinary 342*404b540aSrobert * element order. 343*404b540aSrobert */ 344*404b540aSrobert iterator end()345*404b540aSrobert end() 346*404b540aSrobert { return iterator(this->_M_impl._M_finish); } 347*404b540aSrobert 348*404b540aSrobert /** 349*404b540aSrobert * Returns a read-only (constant) iterator that points one past 350*404b540aSrobert * the last element in the %vector. Iteration is done in 351*404b540aSrobert * ordinary element order. 352*404b540aSrobert */ 353*404b540aSrobert const_iterator end()354*404b540aSrobert end() const 355*404b540aSrobert { return const_iterator(this->_M_impl._M_finish); } 356*404b540aSrobert 357*404b540aSrobert /** 358*404b540aSrobert * Returns a read/write reverse iterator that points to the 359*404b540aSrobert * last element in the %vector. Iteration is done in reverse 360*404b540aSrobert * element order. 361*404b540aSrobert */ 362*404b540aSrobert reverse_iterator rbegin()363*404b540aSrobert rbegin() 364*404b540aSrobert { return reverse_iterator(end()); } 365*404b540aSrobert 366*404b540aSrobert /** 367*404b540aSrobert * Returns a read-only (constant) reverse iterator that points 368*404b540aSrobert * to the last element in the %vector. Iteration is done in 369*404b540aSrobert * reverse element order. 370*404b540aSrobert */ 371*404b540aSrobert const_reverse_iterator rbegin()372*404b540aSrobert rbegin() const 373*404b540aSrobert { return const_reverse_iterator(end()); } 374*404b540aSrobert 375*404b540aSrobert /** 376*404b540aSrobert * Returns a read/write reverse iterator that points to one 377*404b540aSrobert * before the first element in the %vector. Iteration is done 378*404b540aSrobert * in reverse element order. 379*404b540aSrobert */ 380*404b540aSrobert reverse_iterator rend()381*404b540aSrobert rend() 382*404b540aSrobert { return reverse_iterator(begin()); } 383*404b540aSrobert 384*404b540aSrobert /** 385*404b540aSrobert * Returns a read-only (constant) reverse iterator that points 386*404b540aSrobert * to one before the first element in the %vector. Iteration 387*404b540aSrobert * is done in reverse element order. 388*404b540aSrobert */ 389*404b540aSrobert const_reverse_iterator rend()390*404b540aSrobert rend() const 391*404b540aSrobert { return const_reverse_iterator(begin()); } 392*404b540aSrobert 393*404b540aSrobert // [23.2.4.2] capacity 394*404b540aSrobert /** Returns the number of elements in the %vector. */ 395*404b540aSrobert size_type size()396*404b540aSrobert size() const 397*404b540aSrobert { return size_type(this->_M_impl._M_finish - this->_M_impl._M_start); } 398*404b540aSrobert 399*404b540aSrobert /** Returns the size() of the largest possible %vector. */ 400*404b540aSrobert size_type max_size()401*404b540aSrobert max_size() const 402*404b540aSrobert { return _M_get_Tp_allocator().max_size(); } 403*404b540aSrobert 404*404b540aSrobert /** 405*404b540aSrobert * @brief Resizes the %vector to the specified number of elements. 406*404b540aSrobert * @param new_size Number of elements the %vector should contain. 407*404b540aSrobert * @param x Data with which new elements should be populated. 408*404b540aSrobert * 409*404b540aSrobert * This function will %resize the %vector to the specified 410*404b540aSrobert * number of elements. If the number is smaller than the 411*404b540aSrobert * %vector's current size the %vector is truncated, otherwise 412*404b540aSrobert * the %vector is extended and new elements are populated with 413*404b540aSrobert * given data. 414*404b540aSrobert */ 415*404b540aSrobert void 416*404b540aSrobert resize(size_type __new_size, value_type __x = value_type()) 417*404b540aSrobert { 418*404b540aSrobert if (__new_size < size()) 419*404b540aSrobert _M_erase_at_end(this->_M_impl._M_start + __new_size); 420*404b540aSrobert else 421*404b540aSrobert insert(end(), __new_size - size(), __x); 422*404b540aSrobert } 423*404b540aSrobert 424*404b540aSrobert /** 425*404b540aSrobert * Returns the total number of elements that the %vector can 426*404b540aSrobert * hold before needing to allocate more memory. 427*404b540aSrobert */ 428*404b540aSrobert size_type capacity()429*404b540aSrobert capacity() const 430*404b540aSrobert { return size_type(this->_M_impl._M_end_of_storage 431*404b540aSrobert - this->_M_impl._M_start); } 432*404b540aSrobert 433*404b540aSrobert /** 434*404b540aSrobert * Returns true if the %vector is empty. (Thus begin() would 435*404b540aSrobert * equal end().) 436*404b540aSrobert */ 437*404b540aSrobert bool empty()438*404b540aSrobert empty() const 439*404b540aSrobert { return begin() == end(); } 440*404b540aSrobert 441*404b540aSrobert /** 442*404b540aSrobert * @brief Attempt to preallocate enough memory for specified number of 443*404b540aSrobert * elements. 444*404b540aSrobert * @param n Number of elements required. 445*404b540aSrobert * @throw std::length_error If @a n exceeds @c max_size(). 446*404b540aSrobert * 447*404b540aSrobert * This function attempts to reserve enough memory for the 448*404b540aSrobert * %vector to hold the specified number of elements. If the 449*404b540aSrobert * number requested is more than max_size(), length_error is 450*404b540aSrobert * thrown. 451*404b540aSrobert * 452*404b540aSrobert * The advantage of this function is that if optimal code is a 453*404b540aSrobert * necessity and the user can determine the number of elements 454*404b540aSrobert * that will be required, the user can reserve the memory in 455*404b540aSrobert * %advance, and thus prevent a possible reallocation of memory 456*404b540aSrobert * and copying of %vector data. 457*404b540aSrobert */ 458*404b540aSrobert void 459*404b540aSrobert reserve(size_type __n); 460*404b540aSrobert 461*404b540aSrobert // element access 462*404b540aSrobert /** 463*404b540aSrobert * @brief Subscript access to the data contained in the %vector. 464*404b540aSrobert * @param n The index of the element for which data should be 465*404b540aSrobert * accessed. 466*404b540aSrobert * @return Read/write reference to data. 467*404b540aSrobert * 468*404b540aSrobert * This operator allows for easy, array-style, data access. 469*404b540aSrobert * Note that data access with this operator is unchecked and 470*404b540aSrobert * out_of_range lookups are not defined. (For checked lookups 471*404b540aSrobert * see at().) 472*404b540aSrobert */ 473*404b540aSrobert reference 474*404b540aSrobert operator[](size_type __n) 475*404b540aSrobert { return *(this->_M_impl._M_start + __n); } 476*404b540aSrobert 477*404b540aSrobert /** 478*404b540aSrobert * @brief Subscript access to the data contained in the %vector. 479*404b540aSrobert * @param n The index of the element for which data should be 480*404b540aSrobert * accessed. 481*404b540aSrobert * @return Read-only (constant) reference to data. 482*404b540aSrobert * 483*404b540aSrobert * This operator allows for easy, array-style, data access. 484*404b540aSrobert * Note that data access with this operator is unchecked and 485*404b540aSrobert * out_of_range lookups are not defined. (For checked lookups 486*404b540aSrobert * see at().) 487*404b540aSrobert */ 488*404b540aSrobert const_reference 489*404b540aSrobert operator[](size_type __n) const 490*404b540aSrobert { return *(this->_M_impl._M_start + __n); } 491*404b540aSrobert 492*404b540aSrobert protected: 493*404b540aSrobert /// @if maint Safety check used only from at(). @endif 494*404b540aSrobert void _M_range_check(size_type __n)495*404b540aSrobert _M_range_check(size_type __n) const 496*404b540aSrobert { 497*404b540aSrobert if (__n >= this->size()) 498*404b540aSrobert __throw_out_of_range(__N("vector::_M_range_check")); 499*404b540aSrobert } 500*404b540aSrobert 501*404b540aSrobert public: 502*404b540aSrobert /** 503*404b540aSrobert * @brief Provides access to the data contained in the %vector. 504*404b540aSrobert * @param n The index of the element for which data should be 505*404b540aSrobert * accessed. 506*404b540aSrobert * @return Read/write reference to data. 507*404b540aSrobert * @throw std::out_of_range If @a n is an invalid index. 508*404b540aSrobert * 509*404b540aSrobert * This function provides for safer data access. The parameter 510*404b540aSrobert * is first checked that it is in the range of the vector. The 511*404b540aSrobert * function throws out_of_range if the check fails. 512*404b540aSrobert */ 513*404b540aSrobert reference at(size_type __n)514*404b540aSrobert at(size_type __n) 515*404b540aSrobert { 516*404b540aSrobert _M_range_check(__n); 517*404b540aSrobert return (*this)[__n]; 518*404b540aSrobert } 519*404b540aSrobert 520*404b540aSrobert /** 521*404b540aSrobert * @brief Provides access to the data contained in the %vector. 522*404b540aSrobert * @param n The index of the element for which data should be 523*404b540aSrobert * accessed. 524*404b540aSrobert * @return Read-only (constant) reference to data. 525*404b540aSrobert * @throw std::out_of_range If @a n is an invalid index. 526*404b540aSrobert * 527*404b540aSrobert * This function provides for safer data access. The parameter 528*404b540aSrobert * is first checked that it is in the range of the vector. The 529*404b540aSrobert * function throws out_of_range if the check fails. 530*404b540aSrobert */ 531*404b540aSrobert const_reference at(size_type __n)532*404b540aSrobert at(size_type __n) const 533*404b540aSrobert { 534*404b540aSrobert _M_range_check(__n); 535*404b540aSrobert return (*this)[__n]; 536*404b540aSrobert } 537*404b540aSrobert 538*404b540aSrobert /** 539*404b540aSrobert * Returns a read/write reference to the data at the first 540*404b540aSrobert * element of the %vector. 541*404b540aSrobert */ 542*404b540aSrobert reference front()543*404b540aSrobert front() 544*404b540aSrobert { return *begin(); } 545*404b540aSrobert 546*404b540aSrobert /** 547*404b540aSrobert * Returns a read-only (constant) reference to the data at the first 548*404b540aSrobert * element of the %vector. 549*404b540aSrobert */ 550*404b540aSrobert const_reference front()551*404b540aSrobert front() const 552*404b540aSrobert { return *begin(); } 553*404b540aSrobert 554*404b540aSrobert /** 555*404b540aSrobert * Returns a read/write reference to the data at the last 556*404b540aSrobert * element of the %vector. 557*404b540aSrobert */ 558*404b540aSrobert reference back()559*404b540aSrobert back() 560*404b540aSrobert { return *(end() - 1); } 561*404b540aSrobert 562*404b540aSrobert /** 563*404b540aSrobert * Returns a read-only (constant) reference to the data at the 564*404b540aSrobert * last element of the %vector. 565*404b540aSrobert */ 566*404b540aSrobert const_reference back()567*404b540aSrobert back() const 568*404b540aSrobert { return *(end() - 1); } 569*404b540aSrobert 570*404b540aSrobert // _GLIBCXX_RESOLVE_LIB_DEFECTS 571*404b540aSrobert // DR 464. Suggestion for new member functions in standard containers. 572*404b540aSrobert // data access 573*404b540aSrobert /** 574*404b540aSrobert * Returns a pointer such that [data(), data() + size()) is a valid 575*404b540aSrobert * range. For a non-empty %vector, data() == &front(). 576*404b540aSrobert */ 577*404b540aSrobert pointer data()578*404b540aSrobert data() 579*404b540aSrobert { return pointer(this->_M_impl._M_start); } 580*404b540aSrobert 581*404b540aSrobert const_pointer data()582*404b540aSrobert data() const 583*404b540aSrobert { return const_pointer(this->_M_impl._M_start); } 584*404b540aSrobert 585*404b540aSrobert // [23.2.4.3] modifiers 586*404b540aSrobert /** 587*404b540aSrobert * @brief Add data to the end of the %vector. 588*404b540aSrobert * @param x Data to be added. 589*404b540aSrobert * 590*404b540aSrobert * This is a typical stack operation. The function creates an 591*404b540aSrobert * element at the end of the %vector and assigns the given data 592*404b540aSrobert * to it. Due to the nature of a %vector this operation can be 593*404b540aSrobert * done in constant time if the %vector has preallocated space 594*404b540aSrobert * available. 595*404b540aSrobert */ 596*404b540aSrobert void push_back(const value_type & __x)597*404b540aSrobert push_back(const value_type& __x) 598*404b540aSrobert { 599*404b540aSrobert if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage) 600*404b540aSrobert { 601*404b540aSrobert this->_M_impl.construct(this->_M_impl._M_finish, __x); 602*404b540aSrobert ++this->_M_impl._M_finish; 603*404b540aSrobert } 604*404b540aSrobert else 605*404b540aSrobert _M_insert_aux(end(), __x); 606*404b540aSrobert } 607*404b540aSrobert 608*404b540aSrobert /** 609*404b540aSrobert * @brief Removes last element. 610*404b540aSrobert * 611*404b540aSrobert * This is a typical stack operation. It shrinks the %vector by one. 612*404b540aSrobert * 613*404b540aSrobert * Note that no data is returned, and if the last element's 614*404b540aSrobert * data is needed, it should be retrieved before pop_back() is 615*404b540aSrobert * called. 616*404b540aSrobert */ 617*404b540aSrobert void pop_back()618*404b540aSrobert pop_back() 619*404b540aSrobert { 620*404b540aSrobert --this->_M_impl._M_finish; 621*404b540aSrobert this->_M_impl.destroy(this->_M_impl._M_finish); 622*404b540aSrobert } 623*404b540aSrobert 624*404b540aSrobert /** 625*404b540aSrobert * @brief Inserts given value into %vector before specified iterator. 626*404b540aSrobert * @param position An iterator into the %vector. 627*404b540aSrobert * @param x Data to be inserted. 628*404b540aSrobert * @return An iterator that points to the inserted data. 629*404b540aSrobert * 630*404b540aSrobert * This function will insert a copy of the given value before 631*404b540aSrobert * the specified location. Note that this kind of operation 632*404b540aSrobert * could be expensive for a %vector and if it is frequently 633*404b540aSrobert * used the user should consider using std::list. 634*404b540aSrobert */ 635*404b540aSrobert iterator 636*404b540aSrobert insert(iterator __position, const value_type& __x); 637*404b540aSrobert 638*404b540aSrobert /** 639*404b540aSrobert * @brief Inserts a number of copies of given data into the %vector. 640*404b540aSrobert * @param position An iterator into the %vector. 641*404b540aSrobert * @param n Number of elements to be inserted. 642*404b540aSrobert * @param x Data to be inserted. 643*404b540aSrobert * 644*404b540aSrobert * This function will insert a specified number of copies of 645*404b540aSrobert * the given data before the location specified by @a position. 646*404b540aSrobert * 647*404b540aSrobert * Note that this kind of operation could be expensive for a 648*404b540aSrobert * %vector and if it is frequently used the user should 649*404b540aSrobert * consider using std::list. 650*404b540aSrobert */ 651*404b540aSrobert void insert(iterator __position,size_type __n,const value_type & __x)652*404b540aSrobert insert(iterator __position, size_type __n, const value_type& __x) 653*404b540aSrobert { _M_fill_insert(__position, __n, __x); } 654*404b540aSrobert 655*404b540aSrobert /** 656*404b540aSrobert * @brief Inserts a range into the %vector. 657*404b540aSrobert * @param position An iterator into the %vector. 658*404b540aSrobert * @param first An input iterator. 659*404b540aSrobert * @param last An input iterator. 660*404b540aSrobert * 661*404b540aSrobert * This function will insert copies of the data in the range 662*404b540aSrobert * [first,last) into the %vector before the location specified 663*404b540aSrobert * by @a pos. 664*404b540aSrobert * 665*404b540aSrobert * Note that this kind of operation could be expensive for a 666*404b540aSrobert * %vector and if it is frequently used the user should 667*404b540aSrobert * consider using std::list. 668*404b540aSrobert */ 669*404b540aSrobert template<typename _InputIterator> 670*404b540aSrobert void insert(iterator __position,_InputIterator __first,_InputIterator __last)671*404b540aSrobert insert(iterator __position, _InputIterator __first, 672*404b540aSrobert _InputIterator __last) 673*404b540aSrobert { 674*404b540aSrobert // Check whether it's an integral type. If so, it's not an iterator. 675*404b540aSrobert typedef typename std::__is_integer<_InputIterator>::__type _Integral; 676*404b540aSrobert _M_insert_dispatch(__position, __first, __last, _Integral()); 677*404b540aSrobert } 678*404b540aSrobert 679*404b540aSrobert /** 680*404b540aSrobert * @brief Remove element at given position. 681*404b540aSrobert * @param position Iterator pointing to element to be erased. 682*404b540aSrobert * @return An iterator pointing to the next element (or end()). 683*404b540aSrobert * 684*404b540aSrobert * This function will erase the element at the given position and thus 685*404b540aSrobert * shorten the %vector by one. 686*404b540aSrobert * 687*404b540aSrobert * Note This operation could be expensive and if it is 688*404b540aSrobert * frequently used the user should consider using std::list. 689*404b540aSrobert * The user is also cautioned that this function only erases 690*404b540aSrobert * the element, and that if the element is itself a pointer, 691*404b540aSrobert * the pointed-to memory is not touched in any way. Managing 692*404b540aSrobert * the pointer is the user's responsibilty. 693*404b540aSrobert */ 694*404b540aSrobert iterator 695*404b540aSrobert erase(iterator __position); 696*404b540aSrobert 697*404b540aSrobert /** 698*404b540aSrobert * @brief Remove a range of elements. 699*404b540aSrobert * @param first Iterator pointing to the first element to be erased. 700*404b540aSrobert * @param last Iterator pointing to one past the last element to be 701*404b540aSrobert * erased. 702*404b540aSrobert * @return An iterator pointing to the element pointed to by @a last 703*404b540aSrobert * prior to erasing (or end()). 704*404b540aSrobert * 705*404b540aSrobert * This function will erase the elements in the range [first,last) and 706*404b540aSrobert * shorten the %vector accordingly. 707*404b540aSrobert * 708*404b540aSrobert * Note This operation could be expensive and if it is 709*404b540aSrobert * frequently used the user should consider using std::list. 710*404b540aSrobert * The user is also cautioned that this function only erases 711*404b540aSrobert * the elements, and that if the elements themselves are 712*404b540aSrobert * pointers, the pointed-to memory is not touched in any way. 713*404b540aSrobert * Managing the pointer is the user's responsibilty. 714*404b540aSrobert */ 715*404b540aSrobert iterator 716*404b540aSrobert erase(iterator __first, iterator __last); 717*404b540aSrobert 718*404b540aSrobert /** 719*404b540aSrobert * @brief Swaps data with another %vector. 720*404b540aSrobert * @param x A %vector of the same element and allocator types. 721*404b540aSrobert * 722*404b540aSrobert * This exchanges the elements between two vectors in constant time. 723*404b540aSrobert * (Three pointers, so it should be quite fast.) 724*404b540aSrobert * Note that the global std::swap() function is specialized such that 725*404b540aSrobert * std::swap(v1,v2) will feed to this function. 726*404b540aSrobert */ 727*404b540aSrobert void swap(vector & __x)728*404b540aSrobert swap(vector& __x) 729*404b540aSrobert { 730*404b540aSrobert std::swap(this->_M_impl._M_start, __x._M_impl._M_start); 731*404b540aSrobert std::swap(this->_M_impl._M_finish, __x._M_impl._M_finish); 732*404b540aSrobert std::swap(this->_M_impl._M_end_of_storage, 733*404b540aSrobert __x._M_impl._M_end_of_storage); 734*404b540aSrobert 735*404b540aSrobert // _GLIBCXX_RESOLVE_LIB_DEFECTS 736*404b540aSrobert // 431. Swapping containers with unequal allocators. 737*404b540aSrobert std::__alloc_swap<_Tp_alloc_type>::_S_do_it(_M_get_Tp_allocator(), 738*404b540aSrobert __x._M_get_Tp_allocator()); 739*404b540aSrobert } 740*404b540aSrobert 741*404b540aSrobert /** 742*404b540aSrobert * Erases all the elements. Note that this function only erases the 743*404b540aSrobert * elements, and that if the elements themselves are pointers, the 744*404b540aSrobert * pointed-to memory is not touched in any way. Managing the pointer is 745*404b540aSrobert * the user's responsibilty. 746*404b540aSrobert */ 747*404b540aSrobert void clear()748*404b540aSrobert clear() 749*404b540aSrobert { _M_erase_at_end(this->_M_impl._M_start); } 750*404b540aSrobert 751*404b540aSrobert protected: 752*404b540aSrobert /** 753*404b540aSrobert * @if maint 754*404b540aSrobert * Memory expansion handler. Uses the member allocation function to 755*404b540aSrobert * obtain @a n bytes of memory, and then copies [first,last) into it. 756*404b540aSrobert * @endif 757*404b540aSrobert */ 758*404b540aSrobert template<typename _ForwardIterator> 759*404b540aSrobert pointer _M_allocate_and_copy(size_type __n,_ForwardIterator __first,_ForwardIterator __last)760*404b540aSrobert _M_allocate_and_copy(size_type __n, 761*404b540aSrobert _ForwardIterator __first, _ForwardIterator __last) 762*404b540aSrobert { 763*404b540aSrobert pointer __result = this->_M_allocate(__n); 764*404b540aSrobert try 765*404b540aSrobert { 766*404b540aSrobert std::__uninitialized_copy_a(__first, __last, __result, 767*404b540aSrobert _M_get_Tp_allocator()); 768*404b540aSrobert return __result; 769*404b540aSrobert } 770*404b540aSrobert catch(...) 771*404b540aSrobert { 772*404b540aSrobert _M_deallocate(__result, __n); 773*404b540aSrobert __throw_exception_again; 774*404b540aSrobert } 775*404b540aSrobert } 776*404b540aSrobert 777*404b540aSrobert 778*404b540aSrobert // Internal constructor functions follow. 779*404b540aSrobert 780*404b540aSrobert // Called by the range constructor to implement [23.1.1]/9 781*404b540aSrobert template<typename _Integer> 782*404b540aSrobert void _M_initialize_dispatch(_Integer __n,_Integer __value,__true_type)783*404b540aSrobert _M_initialize_dispatch(_Integer __n, _Integer __value, __true_type) 784*404b540aSrobert { 785*404b540aSrobert this->_M_impl._M_start = _M_allocate(__n); 786*404b540aSrobert this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n; 787*404b540aSrobert std::__uninitialized_fill_n_a(this->_M_impl._M_start, __n, __value, 788*404b540aSrobert _M_get_Tp_allocator()); 789*404b540aSrobert this->_M_impl._M_finish = this->_M_impl._M_end_of_storage; 790*404b540aSrobert } 791*404b540aSrobert 792*404b540aSrobert // Called by the range constructor to implement [23.1.1]/9 793*404b540aSrobert template<typename _InputIterator> 794*404b540aSrobert void _M_initialize_dispatch(_InputIterator __first,_InputIterator __last,__false_type)795*404b540aSrobert _M_initialize_dispatch(_InputIterator __first, _InputIterator __last, 796*404b540aSrobert __false_type) 797*404b540aSrobert { 798*404b540aSrobert typedef typename std::iterator_traits<_InputIterator>:: 799*404b540aSrobert iterator_category _IterCategory; 800*404b540aSrobert _M_range_initialize(__first, __last, _IterCategory()); 801*404b540aSrobert } 802*404b540aSrobert 803*404b540aSrobert // Called by the second initialize_dispatch above 804*404b540aSrobert template<typename _InputIterator> 805*404b540aSrobert void _M_range_initialize(_InputIterator __first,_InputIterator __last,std::input_iterator_tag)806*404b540aSrobert _M_range_initialize(_InputIterator __first, 807*404b540aSrobert _InputIterator __last, std::input_iterator_tag) 808*404b540aSrobert { 809*404b540aSrobert for (; __first != __last; ++__first) 810*404b540aSrobert push_back(*__first); 811*404b540aSrobert } 812*404b540aSrobert 813*404b540aSrobert // Called by the second initialize_dispatch above 814*404b540aSrobert template<typename _ForwardIterator> 815*404b540aSrobert void _M_range_initialize(_ForwardIterator __first,_ForwardIterator __last,std::forward_iterator_tag)816*404b540aSrobert _M_range_initialize(_ForwardIterator __first, 817*404b540aSrobert _ForwardIterator __last, std::forward_iterator_tag) 818*404b540aSrobert { 819*404b540aSrobert const size_type __n = std::distance(__first, __last); 820*404b540aSrobert this->_M_impl._M_start = this->_M_allocate(__n); 821*404b540aSrobert this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n; 822*404b540aSrobert this->_M_impl._M_finish = 823*404b540aSrobert std::__uninitialized_copy_a(__first, __last, 824*404b540aSrobert this->_M_impl._M_start, 825*404b540aSrobert _M_get_Tp_allocator()); 826*404b540aSrobert } 827*404b540aSrobert 828*404b540aSrobert 829*404b540aSrobert // Internal assign functions follow. The *_aux functions do the actual 830*404b540aSrobert // assignment work for the range versions. 831*404b540aSrobert 832*404b540aSrobert // Called by the range assign to implement [23.1.1]/9 833*404b540aSrobert template<typename _Integer> 834*404b540aSrobert void _M_assign_dispatch(_Integer __n,_Integer __val,__true_type)835*404b540aSrobert _M_assign_dispatch(_Integer __n, _Integer __val, __true_type) 836*404b540aSrobert { 837*404b540aSrobert _M_fill_assign(static_cast<size_type>(__n), 838*404b540aSrobert static_cast<value_type>(__val)); 839*404b540aSrobert } 840*404b540aSrobert 841*404b540aSrobert // Called by the range assign to implement [23.1.1]/9 842*404b540aSrobert template<typename _InputIterator> 843*404b540aSrobert void _M_assign_dispatch(_InputIterator __first,_InputIterator __last,__false_type)844*404b540aSrobert _M_assign_dispatch(_InputIterator __first, _InputIterator __last, 845*404b540aSrobert __false_type) 846*404b540aSrobert { 847*404b540aSrobert typedef typename std::iterator_traits<_InputIterator>:: 848*404b540aSrobert iterator_category _IterCategory; 849*404b540aSrobert _M_assign_aux(__first, __last, _IterCategory()); 850*404b540aSrobert } 851*404b540aSrobert 852*404b540aSrobert // Called by the second assign_dispatch above 853*404b540aSrobert template<typename _InputIterator> 854*404b540aSrobert void 855*404b540aSrobert _M_assign_aux(_InputIterator __first, _InputIterator __last, 856*404b540aSrobert std::input_iterator_tag); 857*404b540aSrobert 858*404b540aSrobert // Called by the second assign_dispatch above 859*404b540aSrobert template<typename _ForwardIterator> 860*404b540aSrobert void 861*404b540aSrobert _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last, 862*404b540aSrobert std::forward_iterator_tag); 863*404b540aSrobert 864*404b540aSrobert // Called by assign(n,t), and the range assign when it turns out 865*404b540aSrobert // to be the same thing. 866*404b540aSrobert void 867*404b540aSrobert _M_fill_assign(size_type __n, const value_type& __val); 868*404b540aSrobert 869*404b540aSrobert 870*404b540aSrobert // Internal insert functions follow. 871*404b540aSrobert 872*404b540aSrobert // Called by the range insert to implement [23.1.1]/9 873*404b540aSrobert template<typename _Integer> 874*404b540aSrobert void _M_insert_dispatch(iterator __pos,_Integer __n,_Integer __val,__true_type)875*404b540aSrobert _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __val, 876*404b540aSrobert __true_type) 877*404b540aSrobert { 878*404b540aSrobert _M_fill_insert(__pos, static_cast<size_type>(__n), 879*404b540aSrobert static_cast<value_type>(__val)); 880*404b540aSrobert } 881*404b540aSrobert 882*404b540aSrobert // Called by the range insert to implement [23.1.1]/9 883*404b540aSrobert template<typename _InputIterator> 884*404b540aSrobert void _M_insert_dispatch(iterator __pos,_InputIterator __first,_InputIterator __last,__false_type)885*404b540aSrobert _M_insert_dispatch(iterator __pos, _InputIterator __first, 886*404b540aSrobert _InputIterator __last, __false_type) 887*404b540aSrobert { 888*404b540aSrobert typedef typename std::iterator_traits<_InputIterator>:: 889*404b540aSrobert iterator_category _IterCategory; 890*404b540aSrobert _M_range_insert(__pos, __first, __last, _IterCategory()); 891*404b540aSrobert } 892*404b540aSrobert 893*404b540aSrobert // Called by the second insert_dispatch above 894*404b540aSrobert template<typename _InputIterator> 895*404b540aSrobert void 896*404b540aSrobert _M_range_insert(iterator __pos, _InputIterator __first, 897*404b540aSrobert _InputIterator __last, std::input_iterator_tag); 898*404b540aSrobert 899*404b540aSrobert // Called by the second insert_dispatch above 900*404b540aSrobert template<typename _ForwardIterator> 901*404b540aSrobert void 902*404b540aSrobert _M_range_insert(iterator __pos, _ForwardIterator __first, 903*404b540aSrobert _ForwardIterator __last, std::forward_iterator_tag); 904*404b540aSrobert 905*404b540aSrobert // Called by insert(p,n,x), and the range insert when it turns out to be 906*404b540aSrobert // the same thing. 907*404b540aSrobert void 908*404b540aSrobert _M_fill_insert(iterator __pos, size_type __n, const value_type& __x); 909*404b540aSrobert 910*404b540aSrobert // Called by insert(p,x) 911*404b540aSrobert void 912*404b540aSrobert _M_insert_aux(iterator __position, const value_type& __x); 913*404b540aSrobert 914*404b540aSrobert // Internal erase functions follow. 915*404b540aSrobert 916*404b540aSrobert // Called by erase(q1,q2), clear(), resize(), _M_fill_assign, 917*404b540aSrobert // _M_assign_aux. 918*404b540aSrobert void _M_erase_at_end(pointer __pos)919*404b540aSrobert _M_erase_at_end(pointer __pos) 920*404b540aSrobert { 921*404b540aSrobert std::_Destroy(__pos, this->_M_impl._M_finish, _M_get_Tp_allocator()); 922*404b540aSrobert this->_M_impl._M_finish = __pos; 923*404b540aSrobert } 924*404b540aSrobert }; 925*404b540aSrobert 926*404b540aSrobert 927*404b540aSrobert /** 928*404b540aSrobert * @brief Vector equality comparison. 929*404b540aSrobert * @param x A %vector. 930*404b540aSrobert * @param y A %vector of the same type as @a x. 931*404b540aSrobert * @return True iff the size and elements of the vectors are equal. 932*404b540aSrobert * 933*404b540aSrobert * This is an equivalence relation. It is linear in the size of the 934*404b540aSrobert * vectors. Vectors are considered equivalent if their sizes are equal, 935*404b540aSrobert * and if corresponding elements compare equal. 936*404b540aSrobert */ 937*404b540aSrobert template<typename _Tp, typename _Alloc> 938*404b540aSrobert inline bool 939*404b540aSrobert operator==(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) 940*404b540aSrobert { return (__x.size() == __y.size() 941*404b540aSrobert && std::equal(__x.begin(), __x.end(), __y.begin())); } 942*404b540aSrobert 943*404b540aSrobert /** 944*404b540aSrobert * @brief Vector ordering relation. 945*404b540aSrobert * @param x A %vector. 946*404b540aSrobert * @param y A %vector of the same type as @a x. 947*404b540aSrobert * @return True iff @a x is lexicographically less than @a y. 948*404b540aSrobert * 949*404b540aSrobert * This is a total ordering relation. It is linear in the size of the 950*404b540aSrobert * vectors. The elements must be comparable with @c <. 951*404b540aSrobert * 952*404b540aSrobert * See std::lexicographical_compare() for how the determination is made. 953*404b540aSrobert */ 954*404b540aSrobert template<typename _Tp, typename _Alloc> 955*404b540aSrobert inline bool 956*404b540aSrobert operator<(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) 957*404b540aSrobert { return std::lexicographical_compare(__x.begin(), __x.end(), 958*404b540aSrobert __y.begin(), __y.end()); } 959*404b540aSrobert 960*404b540aSrobert /// Based on operator== 961*404b540aSrobert template<typename _Tp, typename _Alloc> 962*404b540aSrobert inline bool 963*404b540aSrobert operator!=(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) 964*404b540aSrobert { return !(__x == __y); } 965*404b540aSrobert 966*404b540aSrobert /// Based on operator< 967*404b540aSrobert template<typename _Tp, typename _Alloc> 968*404b540aSrobert inline bool 969*404b540aSrobert operator>(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) 970*404b540aSrobert { return __y < __x; } 971*404b540aSrobert 972*404b540aSrobert /// Based on operator< 973*404b540aSrobert template<typename _Tp, typename _Alloc> 974*404b540aSrobert inline bool 975*404b540aSrobert operator<=(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) 976*404b540aSrobert { return !(__y < __x); } 977*404b540aSrobert 978*404b540aSrobert /// Based on operator< 979*404b540aSrobert template<typename _Tp, typename _Alloc> 980*404b540aSrobert inline bool 981*404b540aSrobert operator>=(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y) 982*404b540aSrobert { return !(__x < __y); } 983*404b540aSrobert 984*404b540aSrobert /// See std::vector::swap(). 985*404b540aSrobert template<typename _Tp, typename _Alloc> 986*404b540aSrobert inline void swap(vector<_Tp,_Alloc> & __x,vector<_Tp,_Alloc> & __y)987*404b540aSrobert swap(vector<_Tp, _Alloc>& __x, vector<_Tp, _Alloc>& __y) 988*404b540aSrobert { __x.swap(__y); } 989*404b540aSrobert 990*404b540aSrobert _GLIBCXX_END_NESTED_NAMESPACE 991*404b540aSrobert 992*404b540aSrobert #endif /* _VECTOR_H */ 993