]> gcc.gnu.org Git - gcc.git/blame - libstdc++-v3/include/bits/stl_vector.h
*: Use headername alias to associate private includes to public includes.
[gcc.git] / libstdc++-v3 / include / bits / stl_vector.h
CommitLineData
42526146
PE
1// Vector implementation -*- C++ -*-
2
79667f82 3// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
31905f34 4// Free Software Foundation, Inc.
42526146
PE
5//
6// This file is part of the GNU ISO C++ Library. This library is free
7// software; you can redistribute it and/or modify it under the
8// terms of the GNU General Public License as published by the
748086b7 9// Free Software Foundation; either version 3, or (at your option)
42526146
PE
10// any later version.
11
12// This library is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16
748086b7
JJ
17// Under Section 7 of GPL version 3, you are granted additional
18// permissions described in the GCC Runtime Library Exception, version
19// 3.1, as published by the Free Software Foundation.
42526146 20
748086b7
JJ
21// You should have received a copy of the GNU General Public License and
22// a copy of the GCC Runtime Library Exception along with this program;
23// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24// <http://www.gnu.org/licenses/>.
42526146 25
725dc051
BK
26/*
27 *
28 * Copyright (c) 1994
29 * Hewlett-Packard Company
30 *
31 * Permission to use, copy, modify, distribute and sell this software
32 * and its documentation for any purpose is hereby granted without fee,
33 * provided that the above copyright notice appear in all copies and
34 * that both that copyright notice and this permission notice appear
35 * in supporting documentation. Hewlett-Packard Company makes no
36 * representations about the suitability of this software for any
37 * purpose. It is provided "as is" without express or implied warranty.
38 *
39 *
40 * Copyright (c) 1996
41 * Silicon Graphics Computer Systems, Inc.
42 *
43 * Permission to use, copy, modify, distribute and sell this software
44 * and its documentation for any purpose is hereby granted without fee,
45 * provided that the above copyright notice appear in all copies and
46 * that both that copyright notice and this permission notice appear
47 * in supporting documentation. Silicon Graphics makes no
48 * representations about the suitability of this software for any
49 * purpose. It is provided "as is" without express or implied warranty.
50 */
51
f910786b 52/** @file bits/stl_vector.h
729e3d3f 53 * This is an internal header file, included by other library headers.
f910786b 54 * Do not attempt to use it directly. @headername{vector}
725dc051
BK
55 */
56
046d30f4
PC
57#ifndef _STL_VECTOR_H
58#define _STL_VECTOR_H 1
725dc051 59
30a20a1e 60#include <bits/stl_iterator_base_funcs.h>
e2c09482 61#include <bits/functexcept.h>
30a20a1e 62#include <bits/concept_check.h>
988499f4 63#include <initializer_list>
725dc051 64
c2ba9709 65_GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
3cbc7af0 66
4312e020 67 /// See bits/stl_deque.h's _Deque_base for an explanation.
af5fb6ab 68 template<typename _Tp, typename _Alloc>
3971a4d2 69 struct _Vector_base
83144cfc 70 {
4fd20a8f
PC
71 typedef typename _Alloc::template rebind<_Tp>::other _Tp_alloc_type;
72
03f9ea44 73 struct _Vector_impl
4fd20a8f 74 : public _Tp_alloc_type
874e7baa 75 {
08bf5bb3
BW
76 typename _Tp_alloc_type::pointer _M_start;
77 typename _Tp_alloc_type::pointer _M_finish;
78 typename _Tp_alloc_type::pointer _M_end_of_storage;
78b36b70
PC
79
80 _Vector_impl()
81 : _Tp_alloc_type(), _M_start(0), _M_finish(0), _M_end_of_storage(0)
82 { }
83
4fd20a8f
PC
84 _Vector_impl(_Tp_alloc_type const& __a)
85 : _Tp_alloc_type(__a), _M_start(0), _M_finish(0), _M_end_of_storage(0)
03f9ea44
DM
86 { }
87 };
88
af5fb6ab 89 public:
8a1d8dd9
MA
90 typedef _Alloc allocator_type;
91
8d46ce60
PC
92 _Tp_alloc_type&
93 _M_get_Tp_allocator()
94 { return *static_cast<_Tp_alloc_type*>(&this->_M_impl); }
95
96 const _Tp_alloc_type&
4fd20a8f
PC
97 _M_get_Tp_allocator() const
98 { return *static_cast<const _Tp_alloc_type*>(&this->_M_impl); }
99
8a1d8dd9 100 allocator_type
874e7baa 101 get_allocator() const
31905f34 102 { return allocator_type(_M_get_Tp_allocator()); }
af5fb6ab 103
78b36b70
PC
104 _Vector_base()
105 : _M_impl() { }
106
874e7baa 107 _Vector_base(const allocator_type& __a)
78b36b70 108 : _M_impl(__a) { }
ed6814f7 109
dc2cf706
PC
110 _Vector_base(size_t __n)
111 : _M_impl()
112 {
113 this->_M_impl._M_start = this->_M_allocate(__n);
114 this->_M_impl._M_finish = this->_M_impl._M_start;
115 this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n;
116 }
117
af5fb6ab 118 _Vector_base(size_t __n, const allocator_type& __a)
874e7baa 119 : _M_impl(__a)
af5fb6ab 120 {
03f9ea44
DM
121 this->_M_impl._M_start = this->_M_allocate(__n);
122 this->_M_impl._M_finish = this->_M_impl._M_start;
123 this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n;
af5fb6ab 124 }
ed6814f7 125
053cc380
PC
126#ifdef __GXX_EXPERIMENTAL_CXX0X__
127 _Vector_base(_Vector_base&& __x)
128 : _M_impl(__x._M_get_Tp_allocator())
129 {
130 this->_M_impl._M_start = __x._M_impl._M_start;
131 this->_M_impl._M_finish = __x._M_impl._M_finish;
132 this->_M_impl._M_end_of_storage = __x._M_impl._M_end_of_storage;
133 __x._M_impl._M_start = 0;
134 __x._M_impl._M_finish = 0;
135 __x._M_impl._M_end_of_storage = 0;
136 }
137#endif
138
ed6814f7 139 ~_Vector_base()
874e7baa
PC
140 { _M_deallocate(this->_M_impl._M_start, this->_M_impl._M_end_of_storage
141 - this->_M_impl._M_start); }
8a1d8dd9
MA
142
143 public:
03f9ea44 144 _Vector_impl _M_impl;
ed6814f7 145
08bf5bb3 146 typename _Tp_alloc_type::pointer
874e7baa 147 _M_allocate(size_t __n)
ccd04b9f 148 { return __n != 0 ? _M_impl.allocate(__n) : 0; }
ed6814f7 149
8a1d8dd9 150 void
08bf5bb3 151 _M_deallocate(typename _Tp_alloc_type::pointer __p, size_t __n)
368b7a30
PC
152 {
153 if (__p)
874e7baa
PC
154 _M_impl.deallocate(__p, __n);
155 }
af5fb6ab 156 };
ed6814f7
BI
157
158
3971a4d2 159 /**
e135a038
BK
160 * @brief A standard container which offers fixed time access to
161 * individual elements in any order.
ad2a4e2b 162 *
aac2878e 163 * @ingroup sequences
ad2a4e2b 164 *
3971a4d2
PE
165 * Meets the requirements of a <a href="tables.html#65">container</a>, a
166 * <a href="tables.html#66">reversible container</a>, and a
167 * <a href="tables.html#67">sequence</a>, including the
168 * <a href="tables.html#68">optional sequence requirements</a> with the
169 * %exception of @c push_front and @c pop_front.
ad2a4e2b 170 *
e135a038
BK
171 * In some terminology a %vector can be described as a dynamic
172 * C-style array, it offers fast and efficient access to individual
173 * elements in any order and saves the user from worrying about
174 * memory and size allocation. Subscripting ( @c [] ) access is
175 * also provided as with C-style arrays.
ad2a4e2b 176 */
6323b34e 177 template<typename _Tp, typename _Alloc = std::allocator<_Tp> >
3971a4d2 178 class vector : protected _Vector_base<_Tp, _Alloc>
af5fb6ab
BK
179 {
180 // Concept requirements.
4fd20a8f 181 typedef typename _Alloc::value_type _Alloc_value_type;
3d7c150e 182 __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
4fd20a8f
PC
183 __glibcxx_class_requires2(_Tp, _Alloc_value_type, _SameTypeConcept)
184
185 typedef _Vector_base<_Tp, _Alloc> _Base;
4fd20a8f 186 typedef typename _Base::_Tp_alloc_type _Tp_alloc_type;
ed6814f7 187
af5fb6ab 188 public:
7338fc64 189 typedef _Tp value_type;
4fd20a8f
PC
190 typedef typename _Tp_alloc_type::pointer pointer;
191 typedef typename _Tp_alloc_type::const_pointer const_pointer;
192 typedef typename _Tp_alloc_type::reference reference;
193 typedef typename _Tp_alloc_type::const_reference const_reference;
37d5c6ba
BK
194 typedef __gnu_cxx::__normal_iterator<pointer, vector> iterator;
195 typedef __gnu_cxx::__normal_iterator<const_pointer, vector>
af5fb6ab 196 const_iterator;
7338fc64
PC
197 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
198 typedef std::reverse_iterator<iterator> reverse_iterator;
199 typedef size_t size_type;
200 typedef ptrdiff_t difference_type;
4fd20a8f 201 typedef _Alloc allocator_type;
ed6814f7 202
af5fb6ab 203 protected:
af5fb6ab
BK
204 using _Base::_M_allocate;
205 using _Base::_M_deallocate;
03f9ea44 206 using _Base::_M_impl;
4fd20a8f 207 using _Base::_M_get_Tp_allocator;
ed6814f7 208
af5fb6ab
BK
209 public:
210 // [23.2.4.1] construct/copy/destroy
211 // (assign() and get_allocator() are also listed in this section)
212 /**
213 * @brief Default constructor creates no elements.
214 */
78b36b70
PC
215 vector()
216 : _Base() { }
217
218 /**
219 * @brief Creates a %vector with no elements.
220 * @param a An allocator object.
221 */
af5fb6ab 222 explicit
78b36b70
PC
223 vector(const allocator_type& __a)
224 : _Base(__a) { }
ed6814f7 225
dc2cf706
PC
226#ifdef __GXX_EXPERIMENTAL_CXX0X__
227 /**
228 * @brief Creates a %vector with default constructed elements.
229 * @param n The number of elements to initially create.
230 *
231 * This constructor fills the %vector with @a n default
232 * constructed elements.
233 */
234 explicit
235 vector(size_type __n)
236 : _Base(__n)
237 { _M_default_initialize(__n); }
238
239 /**
240 * @brief Creates a %vector with copies of an exemplar element.
241 * @param n The number of elements to initially create.
242 * @param value An element to copy.
243 * @param a An allocator.
244 *
245 * This constructor fills the %vector with @a n copies of @a value.
246 */
247 vector(size_type __n, const value_type& __value,
248 const allocator_type& __a = allocator_type())
249 : _Base(__n, __a)
250 { _M_fill_initialize(__n, __value); }
251#else
af5fb6ab 252 /**
78b36b70 253 * @brief Creates a %vector with copies of an exemplar element.
af5fb6ab
BK
254 * @param n The number of elements to initially create.
255 * @param value An element to copy.
78b36b70 256 * @param a An allocator.
ed6814f7 257 *
af5fb6ab
BK
258 * This constructor fills the %vector with @a n copies of @a value.
259 */
2fecaef4
PC
260 explicit
261 vector(size_type __n, const value_type& __value = value_type(),
af5fb6ab 262 const allocator_type& __a = allocator_type())
3971a4d2 263 : _Base(__n, __a)
f4c5578f 264 { _M_fill_initialize(__n, __value); }
dc2cf706 265#endif
ed6814f7 266
af5fb6ab
BK
267 /**
268 * @brief %Vector copy constructor.
269 * @param x A %vector of identical element and allocator types.
ed6814f7 270 *
af5fb6ab
BK
271 * The newly-created %vector uses a copy of the allocation
272 * object used by @a x. All the elements of @a x are copied,
273 * but any extra memory in
274 * @a x (for fast expansion) will not be copied.
275 */
276 vector(const vector& __x)
d2cc7f92 277 : _Base(__x.size(), __x._M_get_Tp_allocator())
1985f1cd
MA
278 { this->_M_impl._M_finish =
279 std::__uninitialized_copy_a(__x.begin(), __x.end(),
280 this->_M_impl._M_start,
4fd20a8f 281 _M_get_Tp_allocator());
1985f1cd 282 }
ed6814f7 283
78b36b70
PC
284#ifdef __GXX_EXPERIMENTAL_CXX0X__
285 /**
286 * @brief %Vector move constructor.
287 * @param x A %vector of identical element and allocator types.
288 *
289 * The newly-created %vector contains the exact contents of @a x.
290 * The contents of @a x are a valid, but unspecified %vector.
291 */
292 vector(vector&& __x)
5f1fd346 293 : _Base(std::move(__x)) { }
988499f4
JM
294
295 /**
296 * @brief Builds a %vector from an initializer list.
297 * @param l An initializer_list.
298 * @param a An allocator.
299 *
300 * Create a %vector consisting of copies of the elements in the
301 * initializer_list @a l.
302 *
303 * This will call the element type's copy constructor N times
304 * (where N is @a l.size()) and do no memory reallocation.
305 */
306 vector(initializer_list<value_type> __l,
307 const allocator_type& __a = allocator_type())
b798df05
PC
308 : _Base(__a)
309 {
310 _M_range_initialize(__l.begin(), __l.end(),
311 random_access_iterator_tag());
312 }
78b36b70
PC
313#endif
314
af5fb6ab
BK
315 /**
316 * @brief Builds a %vector from a range.
317 * @param first An input iterator.
318 * @param last An input iterator.
78b36b70 319 * @param a An allocator.
ed6814f7 320 *
af5fb6ab
BK
321 * Create a %vector consisting of copies of the elements from
322 * [first,last).
323 *
e135a038
BK
324 * If the iterators are forward, bidirectional, or
325 * random-access, then this will call the elements' copy
326 * constructor N times (where N is distance(first,last)) and do
327 * no memory reallocation. But if only input iterators are
328 * used, then this will do at most 2N calls to the copy
329 * constructor, and logN memory reallocations.
af5fb6ab
BK
330 */
331 template<typename _InputIterator>
332 vector(_InputIterator __first, _InputIterator __last,
333 const allocator_type& __a = allocator_type())
334 : _Base(__a)
3971a4d2 335 {
af5fb6ab 336 // Check whether it's an integral type. If so, it's not an iterator.
c0736a9d 337 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
af5fb6ab
BK
338 _M_initialize_dispatch(__first, __last, _Integral());
339 }
ed6814f7 340
af5fb6ab 341 /**
e135a038
BK
342 * The dtor only erases the elements, and note that if the
343 * elements themselves are pointers, the pointed-to memory is
344 * not touched in any way. Managing the pointer is the user's
28dac70a 345 * responsibility.
af5fb6ab 346 */
874e7baa 347 ~vector()
1985f1cd 348 { std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish,
bc9053ab 349 _M_get_Tp_allocator()); }
ed6814f7 350
af5fb6ab
BK
351 /**
352 * @brief %Vector assignment operator.
353 * @param x A %vector of identical element and allocator types.
ed6814f7 354 *
af5fb6ab
BK
355 * All the elements of @a x are copied, but any extra memory in
356 * @a x (for fast expansion) will not be copied. Unlike the
357 * copy constructor, the allocator object is not copied.
358 */
359 vector&
360 operator=(const vector& __x);
ed6814f7 361
78b36b70
PC
362#ifdef __GXX_EXPERIMENTAL_CXX0X__
363 /**
364 * @brief %Vector move assignment operator.
365 * @param x A %vector of identical element and allocator types.
366 *
367 * The contents of @a x are moved into this %vector (without copying).
368 * @a x is a valid, but unspecified %vector.
369 */
370 vector&
371 operator=(vector&& __x)
cbc6c888 372 {
0462fd5e
PC
373 // NB: DR 1204.
374 // NB: DR 675.
375 this->clear();
376 this->swap(__x);
78b36b70
PC
377 return *this;
378 }
988499f4
JM
379
380 /**
381 * @brief %Vector list assignment operator.
382 * @param l An initializer_list.
383 *
384 * This function fills a %vector with copies of the elements in the
385 * initializer list @a l.
386 *
387 * Note that the assignment completely changes the %vector and
388 * that the resulting %vector's size is the same as the number
389 * of elements assigned. Old data may be lost.
390 */
391 vector&
392 operator=(initializer_list<value_type> __l)
393 {
394 this->assign(__l.begin(), __l.end());
395 return *this;
396 }
78b36b70
PC
397#endif
398
af5fb6ab
BK
399 /**
400 * @brief Assigns a given value to a %vector.
401 * @param n Number of elements to be assigned.
402 * @param val Value to be assigned.
403 *
404 * This function fills a %vector with @a n copies of the given
405 * value. Note that the assignment completely changes the
406 * %vector and that the resulting %vector's size is the same as
407 * the number of elements assigned. Old data may be lost.
408 */
409 void
ed6814f7 410 assign(size_type __n, const value_type& __val)
af5fb6ab 411 { _M_fill_assign(__n, __val); }
ed6814f7 412
af5fb6ab
BK
413 /**
414 * @brief Assigns a range to a %vector.
415 * @param first An input iterator.
416 * @param last An input iterator.
417 *
418 * This function fills a %vector with copies of the elements in the
419 * range [first,last).
420 *
421 * Note that the assignment completely changes the %vector and
422 * that the resulting %vector's size is the same as the number
423 * of elements assigned. Old data may be lost.
424 */
425 template<typename _InputIterator>
426 void
427 assign(_InputIterator __first, _InputIterator __last)
3971a4d2 428 {
af5fb6ab 429 // Check whether it's an integral type. If so, it's not an iterator.
c0736a9d 430 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
af5fb6ab
BK
431 _M_assign_dispatch(__first, __last, _Integral());
432 }
ed6814f7 433
988499f4
JM
434#ifdef __GXX_EXPERIMENTAL_CXX0X__
435 /**
436 * @brief Assigns an initializer list to a %vector.
437 * @param l An initializer_list.
438 *
439 * This function fills a %vector with copies of the elements in the
440 * initializer list @a l.
441 *
442 * Note that the assignment completely changes the %vector and
443 * that the resulting %vector's size is the same as the number
444 * of elements assigned. Old data may be lost.
445 */
446 void
447 assign(initializer_list<value_type> __l)
448 { this->assign(__l.begin(), __l.end()); }
449#endif
450
af5fb6ab 451 /// Get a copy of the memory allocation object.
8a1d8dd9 452 using _Base::get_allocator;
ed6814f7 453
af5fb6ab
BK
454 // iterators
455 /**
e135a038
BK
456 * Returns a read/write iterator that points to the first
457 * element in the %vector. Iteration is done in ordinary
458 * element order.
af5fb6ab
BK
459 */
460 iterator
874e7baa 461 begin()
bc9053ab 462 { return iterator(this->_M_impl._M_start); }
ed6814f7 463
af5fb6ab
BK
464 /**
465 * Returns a read-only (constant) iterator that points to the
466 * first element in the %vector. Iteration is done in ordinary
467 * element order.
468 */
469 const_iterator
874e7baa 470 begin() const
bc9053ab 471 { return const_iterator(this->_M_impl._M_start); }
ed6814f7 472
af5fb6ab
BK
473 /**
474 * Returns a read/write iterator that points one past the last
475 * element in the %vector. Iteration is done in ordinary
476 * element order.
477 */
478 iterator
874e7baa 479 end()
bc9053ab 480 { return iterator(this->_M_impl._M_finish); }
ed6814f7 481
af5fb6ab 482 /**
e135a038
BK
483 * Returns a read-only (constant) iterator that points one past
484 * the last element in the %vector. Iteration is done in
485 * ordinary element order.
af5fb6ab
BK
486 */
487 const_iterator
874e7baa 488 end() const
bc9053ab 489 { return const_iterator(this->_M_impl._M_finish); }
ed6814f7 490
af5fb6ab
BK
491 /**
492 * Returns a read/write reverse iterator that points to the
493 * last element in the %vector. Iteration is done in reverse
494 * element order.
495 */
496 reverse_iterator
874e7baa
PC
497 rbegin()
498 { return reverse_iterator(end()); }
ed6814f7 499
af5fb6ab
BK
500 /**
501 * Returns a read-only (constant) reverse iterator that points
502 * to the last element in the %vector. Iteration is done in
503 * reverse element order.
504 */
505 const_reverse_iterator
874e7baa
PC
506 rbegin() const
507 { return const_reverse_iterator(end()); }
ed6814f7 508
af5fb6ab 509 /**
e135a038
BK
510 * Returns a read/write reverse iterator that points to one
511 * before the first element in the %vector. Iteration is done
512 * in reverse element order.
af5fb6ab
BK
513 */
514 reverse_iterator
874e7baa
PC
515 rend()
516 { return reverse_iterator(begin()); }
ed6814f7 517
af5fb6ab
BK
518 /**
519 * Returns a read-only (constant) reverse iterator that points
520 * to one before the first element in the %vector. Iteration
521 * is done in reverse element order.
522 */
523 const_reverse_iterator
874e7baa
PC
524 rend() const
525 { return const_reverse_iterator(begin()); }
ed6814f7 526
0cd50f89
PC
527#ifdef __GXX_EXPERIMENTAL_CXX0X__
528 /**
529 * Returns a read-only (constant) iterator that points to the
530 * first element in the %vector. Iteration is done in ordinary
531 * element order.
532 */
533 const_iterator
534 cbegin() const
535 { return const_iterator(this->_M_impl._M_start); }
536
537 /**
538 * Returns a read-only (constant) iterator that points one past
539 * the last element in the %vector. Iteration is done in
540 * ordinary element order.
541 */
542 const_iterator
543 cend() const
544 { return const_iterator(this->_M_impl._M_finish); }
545
546 /**
547 * Returns a read-only (constant) reverse iterator that points
548 * to the last element in the %vector. Iteration is done in
549 * reverse element order.
550 */
551 const_reverse_iterator
552 crbegin() const
553 { return const_reverse_iterator(end()); }
554
555 /**
556 * Returns a read-only (constant) reverse iterator that points
557 * to one before the first element in the %vector. Iteration
558 * is done in reverse element order.
559 */
560 const_reverse_iterator
561 crend() const
562 { return const_reverse_iterator(begin()); }
563#endif
564
af5fb6ab
BK
565 // [23.2.4.2] capacity
566 /** Returns the number of elements in the %vector. */
567 size_type
874e7baa 568 size() const
bc9053ab 569 { return size_type(this->_M_impl._M_finish - this->_M_impl._M_start); }
ed6814f7 570
af5fb6ab
BK
571 /** Returns the size() of the largest possible %vector. */
572 size_type
874e7baa 573 max_size() const
1f9c69a9 574 { return _M_get_Tp_allocator().max_size(); }
ed6814f7 575
dc2cf706
PC
576#ifdef __GXX_EXPERIMENTAL_CXX0X__
577 /**
578 * @brief Resizes the %vector to the specified number of elements.
579 * @param new_size Number of elements the %vector should contain.
580 *
581 * This function will %resize the %vector to the specified
582 * number of elements. If the number is smaller than the
583 * %vector's current size the %vector is truncated, otherwise
584 * default constructed elements are appended.
585 */
586 void
587 resize(size_type __new_size)
588 {
589 if (__new_size > size())
590 _M_default_append(__new_size - size());
591 else if (__new_size < size())
592 _M_erase_at_end(this->_M_impl._M_start + __new_size);
593 }
594
af5fb6ab
BK
595 /**
596 * @brief Resizes the %vector to the specified number of elements.
597 * @param new_size Number of elements the %vector should contain.
598 * @param x Data with which new elements should be populated.
599 *
600 * This function will %resize the %vector to the specified
601 * number of elements. If the number is smaller than the
602 * %vector's current size the %vector is truncated, otherwise
603 * the %vector is extended and new elements are populated with
604 * given data.
605 */
3971a4d2 606 void
dc2cf706 607 resize(size_type __new_size, const value_type& __x)
3971a4d2 608 {
dc2cf706
PC
609 if (__new_size > size())
610 insert(end(), __new_size - size(), __x);
611 else if (__new_size < size())
bc9053ab 612 _M_erase_at_end(this->_M_impl._M_start + __new_size);
dc2cf706
PC
613 }
614#else
615 /**
616 * @brief Resizes the %vector to the specified number of elements.
617 * @param new_size Number of elements the %vector should contain.
618 * @param x Data with which new elements should be populated.
619 *
620 * This function will %resize the %vector to the specified
621 * number of elements. If the number is smaller than the
622 * %vector's current size the %vector is truncated, otherwise
623 * the %vector is extended and new elements are populated with
624 * given data.
625 */
626 void
627 resize(size_type __new_size, value_type __x = value_type())
628 {
629 if (__new_size > size())
af5fb6ab 630 insert(end(), __new_size - size(), __x);
dc2cf706
PC
631 else if (__new_size < size())
632 _M_erase_at_end(this->_M_impl._M_start + __new_size);
3971a4d2 633 }
dc2cf706 634#endif
ed6814f7 635
79667f82
PC
636#ifdef __GXX_EXPERIMENTAL_CXX0X__
637 /** A non-binding request to reduce capacity() to size(). */
638 void
639 shrink_to_fit()
640 { std::__shrink_to_fit<vector>::_S_do_it(*this); }
641#endif
642
af5fb6ab 643 /**
e135a038
BK
644 * Returns the total number of elements that the %vector can
645 * hold before needing to allocate more memory.
af5fb6ab
BK
646 */
647 size_type
648 capacity() const
bc9053ab
PC
649 { return size_type(this->_M_impl._M_end_of_storage
650 - this->_M_impl._M_start); }
ed6814f7 651
af5fb6ab
BK
652 /**
653 * Returns true if the %vector is empty. (Thus begin() would
654 * equal end().)
655 */
656 bool
874e7baa
PC
657 empty() const
658 { return begin() == end(); }
ed6814f7 659
af5fb6ab
BK
660 /**
661 * @brief Attempt to preallocate enough memory for specified number of
662 * elements.
663 * @param n Number of elements required.
664 * @throw std::length_error If @a n exceeds @c max_size().
665 *
666 * This function attempts to reserve enough memory for the
667 * %vector to hold the specified number of elements. If the
668 * number requested is more than max_size(), length_error is
669 * thrown.
670 *
671 * The advantage of this function is that if optimal code is a
672 * necessity and the user can determine the number of elements
673 * that will be required, the user can reserve the memory in
674 * %advance, and thus prevent a possible reallocation of memory
675 * and copying of %vector data.
676 */
677 void
678 reserve(size_type __n);
ed6814f7 679
af5fb6ab
BK
680 // element access
681 /**
682 * @brief Subscript access to the data contained in the %vector.
e135a038
BK
683 * @param n The index of the element for which data should be
684 * accessed.
af5fb6ab
BK
685 * @return Read/write reference to data.
686 *
687 * This operator allows for easy, array-style, data access.
688 * Note that data access with this operator is unchecked and
689 * out_of_range lookups are not defined. (For checked lookups
690 * see at().)
691 */
692 reference
874e7baa 693 operator[](size_type __n)
bc9053ab 694 { return *(this->_M_impl._M_start + __n); }
ed6814f7 695
af5fb6ab
BK
696 /**
697 * @brief Subscript access to the data contained in the %vector.
698 * @param n The index of the element for which data should be
699 * accessed.
700 * @return Read-only (constant) reference to data.
701 *
702 * This operator allows for easy, array-style, data access.
703 * Note that data access with this operator is unchecked and
704 * out_of_range lookups are not defined. (For checked lookups
705 * see at().)
706 */
707 const_reference
874e7baa 708 operator[](size_type __n) const
bc9053ab 709 { return *(this->_M_impl._M_start + __n); }
ed6814f7 710
af5fb6ab 711 protected:
4312e020 712 /// Safety check used only from at().
3971a4d2 713 void
af5fb6ab 714 _M_range_check(size_type __n) const
3971a4d2 715 {
af5fb6ab 716 if (__n >= this->size())
988ad90d 717 __throw_out_of_range(__N("vector::_M_range_check"));
3971a4d2 718 }
ed6814f7 719
af5fb6ab
BK
720 public:
721 /**
722 * @brief Provides access to the data contained in the %vector.
723 * @param n The index of the element for which data should be
724 * accessed.
725 * @return Read/write reference to data.
726 * @throw std::out_of_range If @a n is an invalid index.
727 *
e135a038
BK
728 * This function provides for safer data access. The parameter
729 * is first checked that it is in the range of the vector. The
730 * function throws out_of_range if the check fails.
af5fb6ab
BK
731 */
732 reference
874e7baa
PC
733 at(size_type __n)
734 {
735 _M_range_check(__n);
736 return (*this)[__n];
737 }
ed6814f7 738
af5fb6ab
BK
739 /**
740 * @brief Provides access to the data contained in the %vector.
741 * @param n The index of the element for which data should be
742 * accessed.
743 * @return Read-only (constant) reference to data.
744 * @throw std::out_of_range If @a n is an invalid index.
745 *
746 * This function provides for safer data access. The parameter
747 * is first checked that it is in the range of the vector. The
748 * function throws out_of_range if the check fails.
749 */
750 const_reference
874e7baa
PC
751 at(size_type __n) const
752 {
753 _M_range_check(__n);
754 return (*this)[__n];
755 }
ed6814f7 756
af5fb6ab
BK
757 /**
758 * Returns a read/write reference to the data at the first
759 * element of the %vector.
760 */
761 reference
874e7baa
PC
762 front()
763 { return *begin(); }
ed6814f7 764
af5fb6ab
BK
765 /**
766 * Returns a read-only (constant) reference to the data at the first
767 * element of the %vector.
768 */
769 const_reference
874e7baa
PC
770 front() const
771 { return *begin(); }
ed6814f7 772
af5fb6ab 773 /**
e135a038
BK
774 * Returns a read/write reference to the data at the last
775 * element of the %vector.
af5fb6ab
BK
776 */
777 reference
874e7baa
PC
778 back()
779 { return *(end() - 1); }
780
af5fb6ab 781 /**
e135a038
BK
782 * Returns a read-only (constant) reference to the data at the
783 * last element of the %vector.
af5fb6ab
BK
784 */
785 const_reference
874e7baa
PC
786 back() const
787 { return *(end() - 1); }
ed6814f7 788
8b5f07a2
PC
789 // _GLIBCXX_RESOLVE_LIB_DEFECTS
790 // DR 464. Suggestion for new member functions in standard containers.
791 // data access
792 /**
793 * Returns a pointer such that [data(), data() + size()) is a valid
794 * range. For a non-empty %vector, data() == &front().
795 */
2fb16a39
PC
796#ifdef __GXX_EXPERIMENTAL_CXX0X__
797 _Tp*
798#else
8b5f07a2 799 pointer
2fb16a39 800#endif
8b5f07a2 801 data()
2fb16a39 802 { return std::__addressof(front()); }
8b5f07a2 803
2fb16a39
PC
804#ifdef __GXX_EXPERIMENTAL_CXX0X__
805 const _Tp*
806#else
8b5f07a2 807 const_pointer
2fb16a39 808#endif
8b5f07a2 809 data() const
2fb16a39 810 { return std::__addressof(front()); }
8b5f07a2 811
af5fb6ab
BK
812 // [23.2.4.3] modifiers
813 /**
814 * @brief Add data to the end of the %vector.
815 * @param x Data to be added.
816 *
817 * This is a typical stack operation. The function creates an
818 * element at the end of the %vector and assigns the given data
819 * to it. Due to the nature of a %vector this operation can be
820 * done in constant time if the %vector has preallocated space
821 * available.
822 */
3971a4d2 823 void
af5fb6ab 824 push_back(const value_type& __x)
3971a4d2 825 {
03f9ea44 826 if (this->_M_impl._M_finish != this->_M_impl._M_end_of_storage)
af5fb6ab 827 {
1985f1cd 828 this->_M_impl.construct(this->_M_impl._M_finish, __x);
03f9ea44 829 ++this->_M_impl._M_finish;
af5fb6ab
BK
830 }
831 else
832 _M_insert_aux(end(), __x);
3971a4d2 833 }
4dc3e453
PC
834
835#ifdef __GXX_EXPERIMENTAL_CXX0X__
836 void
837 push_back(value_type&& __x)
838 { emplace_back(std::move(__x)); }
839
6eef7402
CJ
840 template<typename... _Args>
841 void
4dc3e453 842 emplace_back(_Args&&... __args);
6eef7402 843#endif
ed6814f7 844
af5fb6ab
BK
845 /**
846 * @brief Removes last element.
847 *
848 * This is a typical stack operation. It shrinks the %vector by one.
849 *
e135a038
BK
850 * Note that no data is returned, and if the last element's
851 * data is needed, it should be retrieved before pop_back() is
852 * called.
af5fb6ab 853 */
3971a4d2 854 void
af5fb6ab 855 pop_back()
3971a4d2 856 {
03f9ea44 857 --this->_M_impl._M_finish;
1985f1cd 858 this->_M_impl.destroy(this->_M_impl._M_finish);
3971a4d2 859 }
ed6814f7 860
6eef7402
CJ
861#ifdef __GXX_EXPERIMENTAL_CXX0X__
862 /**
863 * @brief Inserts an object in %vector before specified iterator.
864 * @param position An iterator into the %vector.
865 * @param args Arguments.
866 * @return An iterator that points to the inserted data.
867 *
868 * This function will insert an object of type T constructed
869 * with T(std::forward<Args>(args)...) before the specified location.
870 * Note that this kind of operation could be expensive for a %vector
871 * and if it is frequently used the user should consider using
872 * std::list.
873 */
874 template<typename... _Args>
875 iterator
876 emplace(iterator __position, _Args&&... __args);
877#endif
878
af5fb6ab
BK
879 /**
880 * @brief Inserts given value into %vector before specified iterator.
881 * @param position An iterator into the %vector.
882 * @param x Data to be inserted.
883 * @return An iterator that points to the inserted data.
884 *
885 * This function will insert a copy of the given value before
886 * the specified location. Note that this kind of operation
887 * could be expensive for a %vector and if it is frequently
888 * used the user should consider using std::list.
889 */
890 iterator
891 insert(iterator __position, const value_type& __x);
3a9fdf30 892
6eef7402
CJ
893#ifdef __GXX_EXPERIMENTAL_CXX0X__
894 /**
895 * @brief Inserts given rvalue into %vector before specified iterator.
896 * @param position An iterator into the %vector.
897 * @param x Data to be inserted.
898 * @return An iterator that points to the inserted data.
899 *
900 * This function will insert a copy of the given rvalue before
901 * the specified location. Note that this kind of operation
902 * could be expensive for a %vector and if it is frequently
903 * used the user should consider using std::list.
904 */
905 iterator
360b7bff
PC
906 insert(iterator __position, value_type&& __x)
907 { return emplace(__position, std::move(__x)); }
988499f4
JM
908
909 /**
910 * @brief Inserts an initializer_list into the %vector.
911 * @param position An iterator into the %vector.
912 * @param l An initializer_list.
913 *
914 * This function will insert copies of the data in the
915 * initializer_list @a l into the %vector before the location
916 * specified by @a position.
917 *
918 * Note that this kind of operation could be expensive for a
919 * %vector and if it is frequently used the user should
920 * consider using std::list.
921 */
922 void
923 insert(iterator __position, initializer_list<value_type> __l)
924 { this->insert(__position, __l.begin(), __l.end()); }
6eef7402
CJ
925#endif
926
af5fb6ab
BK
927 /**
928 * @brief Inserts a number of copies of given data into the %vector.
929 * @param position An iterator into the %vector.
930 * @param n Number of elements to be inserted.
931 * @param x Data to be inserted.
932 *
933 * This function will insert a specified number of copies of
934 * the given data before the location specified by @a position.
935 *
936 * Note that this kind of operation could be expensive for a
937 * %vector and if it is frequently used the user should
938 * consider using std::list.
939 */
940 void
08addde6
PE
941 insert(iterator __position, size_type __n, const value_type& __x)
942 { _M_fill_insert(__position, __n, __x); }
ed6814f7 943
af5fb6ab
BK
944 /**
945 * @brief Inserts a range into the %vector.
08addde6 946 * @param position An iterator into the %vector.
af5fb6ab
BK
947 * @param first An input iterator.
948 * @param last An input iterator.
949 *
950 * This function will insert copies of the data in the range
951 * [first,last) into the %vector before the location specified
952 * by @a pos.
953 *
954 * Note that this kind of operation could be expensive for a
955 * %vector and if it is frequently used the user should
956 * consider using std::list.
957 */
958 template<typename _InputIterator>
959 void
ed6814f7 960 insert(iterator __position, _InputIterator __first,
e135a038 961 _InputIterator __last)
af5fb6ab
BK
962 {
963 // Check whether it's an integral type. If so, it's not an iterator.
c0736a9d 964 typedef typename std::__is_integer<_InputIterator>::__type _Integral;
08addde6 965 _M_insert_dispatch(__position, __first, __last, _Integral());
af5fb6ab 966 }
ed6814f7 967
af5fb6ab
BK
968 /**
969 * @brief Remove element at given position.
970 * @param position Iterator pointing to element to be erased.
971 * @return An iterator pointing to the next element (or end()).
972 *
973 * This function will erase the element at the given position and thus
974 * shorten the %vector by one.
975 *
976 * Note This operation could be expensive and if it is
977 * frequently used the user should consider using std::list.
978 * The user is also cautioned that this function only erases
979 * the element, and that if the element is itself a pointer,
980 * the pointed-to memory is not touched in any way. Managing
28dac70a 981 * the pointer is the user's responsibility.
af5fb6ab
BK
982 */
983 iterator
984 erase(iterator __position);
ed6814f7 985
af5fb6ab
BK
986 /**
987 * @brief Remove a range of elements.
988 * @param first Iterator pointing to the first element to be erased.
989 * @param last Iterator pointing to one past the last element to be
990 * erased.
991 * @return An iterator pointing to the element pointed to by @a last
992 * prior to erasing (or end()).
993 *
994 * This function will erase the elements in the range [first,last) and
995 * shorten the %vector accordingly.
996 *
997 * Note This operation could be expensive and if it is
998 * frequently used the user should consider using std::list.
999 * The user is also cautioned that this function only erases
1000 * the elements, and that if the elements themselves are
1001 * pointers, the pointed-to memory is not touched in any way.
28dac70a 1002 * Managing the pointer is the user's responsibility.
af5fb6ab
BK
1003 */
1004 iterator
1005 erase(iterator __first, iterator __last);
ed6814f7 1006
af5fb6ab
BK
1007 /**
1008 * @brief Swaps data with another %vector.
1009 * @param x A %vector of the same element and allocator types.
1010 *
1011 * This exchanges the elements between two vectors in constant time.
1012 * (Three pointers, so it should be quite fast.)
1013 * Note that the global std::swap() function is specialized such that
1014 * std::swap(v1,v2) will feed to this function.
1015 */
3971a4d2 1016 void
af5fb6ab 1017 swap(vector& __x)
3971a4d2 1018 {
03f9ea44
DM
1019 std::swap(this->_M_impl._M_start, __x._M_impl._M_start);
1020 std::swap(this->_M_impl._M_finish, __x._M_impl._M_finish);
874e7baa
PC
1021 std::swap(this->_M_impl._M_end_of_storage,
1022 __x._M_impl._M_end_of_storage);
f7ace77f
PC
1023
1024 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1025 // 431. Swapping containers with unequal allocators.
1026 std::__alloc_swap<_Tp_alloc_type>::_S_do_it(_M_get_Tp_allocator(),
1027 __x._M_get_Tp_allocator());
3971a4d2 1028 }
ed6814f7 1029
af5fb6ab
BK
1030 /**
1031 * Erases all the elements. Note that this function only erases the
1032 * elements, and that if the elements themselves are pointers, the
1033 * pointed-to memory is not touched in any way. Managing the pointer is
28dac70a 1034 * the user's responsibility.
af5fb6ab 1035 */
3971a4d2 1036 void
874e7baa 1037 clear()
bc9053ab 1038 { _M_erase_at_end(this->_M_impl._M_start); }
ed6814f7 1039
af5fb6ab
BK
1040 protected:
1041 /**
af5fb6ab
BK
1042 * Memory expansion handler. Uses the member allocation function to
1043 * obtain @a n bytes of memory, and then copies [first,last) into it.
af5fb6ab
BK
1044 */
1045 template<typename _ForwardIterator>
1046 pointer
1047 _M_allocate_and_copy(size_type __n,
1048 _ForwardIterator __first, _ForwardIterator __last)
1049 {
f2ffecb1 1050 pointer __result = this->_M_allocate(__n);
bc2631e0 1051 __try
af5fb6ab 1052 {
1985f1cd 1053 std::__uninitialized_copy_a(__first, __last, __result,
4fd20a8f 1054 _M_get_Tp_allocator());
af5fb6ab
BK
1055 return __result;
1056 }
bc2631e0 1057 __catch(...)
af5fb6ab
BK
1058 {
1059 _M_deallocate(__result, __n);
1060 __throw_exception_again;
1061 }
1062 }
ed6814f7
BI
1063
1064
af5fb6ab 1065 // Internal constructor functions follow.
ed6814f7 1066
af5fb6ab 1067 // Called by the range constructor to implement [23.1.1]/9
25959e29
PC
1068
1069 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1070 // 438. Ambiguity in the "do the right thing" clause
af5fb6ab
BK
1071 template<typename _Integer>
1072 void
1073 _M_initialize_dispatch(_Integer __n, _Integer __value, __true_type)
1074 {
25959e29
PC
1075 this->_M_impl._M_start = _M_allocate(static_cast<size_type>(__n));
1076 this->_M_impl._M_end_of_storage =
1077 this->_M_impl._M_start + static_cast<size_type>(__n);
f4c5578f 1078 _M_fill_initialize(static_cast<size_type>(__n), __value);
af5fb6ab 1079 }
ed6814f7 1080
af5fb6ab 1081 // Called by the range constructor to implement [23.1.1]/9
08addde6 1082 template<typename _InputIterator>
af5fb6ab 1083 void
08addde6 1084 _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
af5fb6ab
BK
1085 __false_type)
1086 {
6323b34e
PC
1087 typedef typename std::iterator_traits<_InputIterator>::
1088 iterator_category _IterCategory;
af5fb6ab
BK
1089 _M_range_initialize(__first, __last, _IterCategory());
1090 }
ed6814f7 1091
af5fb6ab
BK
1092 // Called by the second initialize_dispatch above
1093 template<typename _InputIterator>
1094 void
1095 _M_range_initialize(_InputIterator __first,
6323b34e 1096 _InputIterator __last, std::input_iterator_tag)
af5fb6ab 1097 {
43da93a7 1098 for (; __first != __last; ++__first)
af5fb6ab
BK
1099 push_back(*__first);
1100 }
ed6814f7 1101
af5fb6ab
BK
1102 // Called by the second initialize_dispatch above
1103 template<typename _ForwardIterator>
ed6814f7 1104 void
af5fb6ab 1105 _M_range_initialize(_ForwardIterator __first,
6323b34e 1106 _ForwardIterator __last, std::forward_iterator_tag)
af5fb6ab 1107 {
43da93a7 1108 const size_type __n = std::distance(__first, __last);
03f9ea44
DM
1109 this->_M_impl._M_start = this->_M_allocate(__n);
1110 this->_M_impl._M_end_of_storage = this->_M_impl._M_start + __n;
1985f1cd
MA
1111 this->_M_impl._M_finish =
1112 std::__uninitialized_copy_a(__first, __last,
1113 this->_M_impl._M_start,
4fd20a8f 1114 _M_get_Tp_allocator());
af5fb6ab 1115 }
ed6814f7 1116
f4c5578f
PC
1117 // Called by the first initialize_dispatch above and by the
1118 // vector(n,value,a) constructor.
266a2cba 1119 void
f4c5578f
PC
1120 _M_fill_initialize(size_type __n, const value_type& __value)
1121 {
1122 std::__uninitialized_fill_n_a(this->_M_impl._M_start, __n, __value,
1123 _M_get_Tp_allocator());
1124 this->_M_impl._M_finish = this->_M_impl._M_end_of_storage;
1125 }
1126
dc2cf706
PC
1127#ifdef __GXX_EXPERIMENTAL_CXX0X__
1128 // Called by the vector(n) constructor.
1129 void
1130 _M_default_initialize(size_type __n)
1131 {
1132 std::__uninitialized_default_n_a(this->_M_impl._M_start, __n,
1133 _M_get_Tp_allocator());
1134 this->_M_impl._M_finish = this->_M_impl._M_end_of_storage;
1135 }
1136#endif
ed6814f7 1137
af5fb6ab
BK
1138 // Internal assign functions follow. The *_aux functions do the actual
1139 // assignment work for the range versions.
ed6814f7 1140
af5fb6ab 1141 // Called by the range assign to implement [23.1.1]/9
25959e29
PC
1142
1143 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1144 // 438. Ambiguity in the "do the right thing" clause
af5fb6ab
BK
1145 template<typename _Integer>
1146 void
1147 _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
25959e29 1148 { _M_fill_assign(__n, __val); }
ed6814f7 1149
af5fb6ab 1150 // Called by the range assign to implement [23.1.1]/9
08addde6 1151 template<typename _InputIterator>
af5fb6ab 1152 void
ed6814f7 1153 _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
e135a038 1154 __false_type)
af5fb6ab 1155 {
6323b34e
PC
1156 typedef typename std::iterator_traits<_InputIterator>::
1157 iterator_category _IterCategory;
af5fb6ab
BK
1158 _M_assign_aux(__first, __last, _IterCategory());
1159 }
ed6814f7 1160
af5fb6ab
BK
1161 // Called by the second assign_dispatch above
1162 template<typename _InputIterator>
ed6814f7 1163 void
af5fb6ab 1164 _M_assign_aux(_InputIterator __first, _InputIterator __last,
6323b34e 1165 std::input_iterator_tag);
ed6814f7 1166
af5fb6ab
BK
1167 // Called by the second assign_dispatch above
1168 template<typename _ForwardIterator>
ed6814f7 1169 void
af5fb6ab 1170 _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
6323b34e 1171 std::forward_iterator_tag);
ed6814f7 1172
af5fb6ab
BK
1173 // Called by assign(n,t), and the range assign when it turns out
1174 // to be the same thing.
3971a4d2 1175 void
af5fb6ab 1176 _M_fill_assign(size_type __n, const value_type& __val);
ed6814f7
BI
1177
1178
af5fb6ab 1179 // Internal insert functions follow.
ed6814f7 1180
af5fb6ab 1181 // Called by the range insert to implement [23.1.1]/9
25959e29
PC
1182
1183 // _GLIBCXX_RESOLVE_LIB_DEFECTS
1184 // 438. Ambiguity in the "do the right thing" clause
af5fb6ab
BK
1185 template<typename _Integer>
1186 void
1187 _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __val,
1188 __true_type)
25959e29 1189 { _M_fill_insert(__pos, __n, __val); }
ed6814f7 1190
af5fb6ab
BK
1191 // Called by the range insert to implement [23.1.1]/9
1192 template<typename _InputIterator>
1193 void
1194 _M_insert_dispatch(iterator __pos, _InputIterator __first,
1195 _InputIterator __last, __false_type)
1196 {
6323b34e
PC
1197 typedef typename std::iterator_traits<_InputIterator>::
1198 iterator_category _IterCategory;
af5fb6ab
BK
1199 _M_range_insert(__pos, __first, __last, _IterCategory());
1200 }
ed6814f7 1201
af5fb6ab
BK
1202 // Called by the second insert_dispatch above
1203 template<typename _InputIterator>
1204 void
ed6814f7 1205 _M_range_insert(iterator __pos, _InputIterator __first,
6323b34e 1206 _InputIterator __last, std::input_iterator_tag);
ed6814f7 1207
af5fb6ab
BK
1208 // Called by the second insert_dispatch above
1209 template<typename _ForwardIterator>
1210 void
ed6814f7 1211 _M_range_insert(iterator __pos, _ForwardIterator __first,
6323b34e 1212 _ForwardIterator __last, std::forward_iterator_tag);
ed6814f7 1213
af5fb6ab
BK
1214 // Called by insert(p,n,x), and the range insert when it turns out to be
1215 // the same thing.
1216 void
1217 _M_fill_insert(iterator __pos, size_type __n, const value_type& __x);
ed6814f7 1218
dc2cf706
PC
1219#ifdef __GXX_EXPERIMENTAL_CXX0X__
1220 // Called by resize(n).
1221 void
1222 _M_default_append(size_type __n);
1223#endif
1224
af5fb6ab 1225 // Called by insert(p,x)
6eef7402 1226#ifndef __GXX_EXPERIMENTAL_CXX0X__
af5fb6ab
BK
1227 void
1228 _M_insert_aux(iterator __position, const value_type& __x);
6eef7402
CJ
1229#else
1230 template<typename... _Args>
1231 void
1232 _M_insert_aux(iterator __position, _Args&&... __args);
1233#endif
bc9053ab 1234
be1088fa
ML
1235 // Called by the latter.
1236 size_type
1237 _M_check_len(size_type __n, const char* __s) const
1238 {
1239 if (max_size() - size() < __n)
1240 __throw_length_error(__N(__s));
1241
1242 const size_type __len = size() + std::max(size(), __n);
1243 return (__len < size() || __len > max_size()) ? max_size() : __len;
1244 }
1245
bc9053ab
PC
1246 // Internal erase functions follow.
1247
1248 // Called by erase(q1,q2), clear(), resize(), _M_fill_assign,
1249 // _M_assign_aux.
1250 void
1251 _M_erase_at_end(pointer __pos)
1252 {
1253 std::_Destroy(__pos, this->_M_impl._M_finish, _M_get_Tp_allocator());
1254 this->_M_impl._M_finish = __pos;
1255 }
af5fb6ab 1256 };
ed6814f7
BI
1257
1258
3971a4d2
PE
1259 /**
1260 * @brief Vector equality comparison.
1261 * @param x A %vector.
1262 * @param y A %vector of the same type as @a x.
1263 * @return True iff the size and elements of the vectors are equal.
1264 *
1265 * This is an equivalence relation. It is linear in the size of the
1266 * vectors. Vectors are considered equivalent if their sizes are equal,
1267 * and if corresponding elements compare equal.
1268 */
af5fb6ab 1269 template<typename _Tp, typename _Alloc>
3971a4d2 1270 inline bool
874e7baa
PC
1271 operator==(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
1272 { return (__x.size() == __y.size()
1273 && std::equal(__x.begin(), __x.end(), __y.begin())); }
ed6814f7 1274
3971a4d2
PE
1275 /**
1276 * @brief Vector ordering relation.
1277 * @param x A %vector.
1278 * @param y A %vector of the same type as @a x.
9536ca34 1279 * @return True iff @a x is lexicographically less than @a y.
3971a4d2
PE
1280 *
1281 * This is a total ordering relation. It is linear in the size of the
1282 * vectors. The elements must be comparable with @c <.
1283 *
9536ca34 1284 * See std::lexicographical_compare() for how the determination is made.
3971a4d2 1285 */
af5fb6ab 1286 template<typename _Tp, typename _Alloc>
3971a4d2 1287 inline bool
874e7baa
PC
1288 operator<(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
1289 { return std::lexicographical_compare(__x.begin(), __x.end(),
1290 __y.begin(), __y.end()); }
ed6814f7 1291
3971a4d2 1292 /// Based on operator==
af5fb6ab 1293 template<typename _Tp, typename _Alloc>
3971a4d2 1294 inline bool
874e7baa 1295 operator!=(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
3971a4d2 1296 { return !(__x == __y); }
ed6814f7 1297
3971a4d2 1298 /// Based on operator<
af5fb6ab 1299 template<typename _Tp, typename _Alloc>
3971a4d2 1300 inline bool
874e7baa 1301 operator>(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
3971a4d2 1302 { return __y < __x; }
ed6814f7 1303
3971a4d2 1304 /// Based on operator<
af5fb6ab 1305 template<typename _Tp, typename _Alloc>
3971a4d2 1306 inline bool
874e7baa 1307 operator<=(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
3971a4d2 1308 { return !(__y < __x); }
ed6814f7 1309
3971a4d2 1310 /// Based on operator<
af5fb6ab 1311 template<typename _Tp, typename _Alloc>
3971a4d2 1312 inline bool
874e7baa 1313 operator>=(const vector<_Tp, _Alloc>& __x, const vector<_Tp, _Alloc>& __y)
3971a4d2 1314 { return !(__x < __y); }
ed6814f7 1315
3971a4d2 1316 /// See std::vector::swap().
af5fb6ab 1317 template<typename _Tp, typename _Alloc>
3971a4d2 1318 inline void
874e7baa 1319 swap(vector<_Tp, _Alloc>& __x, vector<_Tp, _Alloc>& __y)
3971a4d2 1320 { __x.swap(__y); }
3cbc7af0
BK
1321
1322_GLIBCXX_END_NESTED_NAMESPACE
725dc051 1323
046d30f4 1324#endif /* _STL_VECTOR_H */
This page took 1.125867 seconds and 5 git commands to generate.