OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libstdc++-v3/] [include/] [bits/] [stl_vector.h] - Blame information for rev 748

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.