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

Subversion Repositories altor32

[/] [altor32/] [trunk/] [gcc-x64/] [or1knd-elf/] [or1knd-elf/] [include/] [c++/] [4.8.0/] [bits/] [stl_deque.h] - Blame information for rev 35

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 35 ultra_embe
// Deque implementation -*- C++ -*-
2
 
3
// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
4
// 2011, 2012 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) 1997
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_deque.h
53
 *  This is an internal header file, included by other library headers.
54
 *  Do not attempt to use it directly. @headername{deque}
55
 */
56
 
57
#ifndef _STL_DEQUE_H
58
#define _STL_DEQUE_H 1
59
 
60
#include <bits/concept_check.h>
61
#include <bits/stl_iterator_base_types.h>
62
#include <bits/stl_iterator_base_funcs.h>
63
#if __cplusplus >= 201103L
64
#include <initializer_list>
65
#endif
66
 
67
namespace std _GLIBCXX_VISIBILITY(default)
68
{
69
_GLIBCXX_BEGIN_NAMESPACE_CONTAINER
70
 
71
  /**
72
   *  @brief This function controls the size of memory nodes.
73
   *  @param  __size  The size of an element.
74
   *  @return   The number (not byte size) of elements per node.
75
   *
76
   *  This function started off as a compiler kludge from SGI, but
77
   *  seems to be a useful wrapper around a repeated constant
78
   *  expression.  The @b 512 is tunable (and no other code needs to
79
   *  change), but no investigation has been done since inheriting the
80
   *  SGI code.  Touch _GLIBCXX_DEQUE_BUF_SIZE only if you know what
81
   *  you are doing, however: changing it breaks the binary
82
   *  compatibility!!
83
  */
84
 
85
#ifndef _GLIBCXX_DEQUE_BUF_SIZE
86
#define _GLIBCXX_DEQUE_BUF_SIZE 512
87
#endif
88
 
89
  inline size_t
90
  __deque_buf_size(size_t __size)
91
  { return (__size < _GLIBCXX_DEQUE_BUF_SIZE
92
            ? size_t(_GLIBCXX_DEQUE_BUF_SIZE / __size) : size_t(1)); }
93
 
94
 
95
  /**
96
   *  @brief A deque::iterator.
97
   *
98
   *  Quite a bit of intelligence here.  Much of the functionality of
99
   *  deque is actually passed off to this class.  A deque holds two
100
   *  of these internally, marking its valid range.  Access to
101
   *  elements is done as offsets of either of those two, relying on
102
   *  operator overloading in this class.
103
   *
104
   *  All the functions are op overloads except for _M_set_node.
105
  */
106
  template<typename _Tp, typename _Ref, typename _Ptr>
107
    struct _Deque_iterator
108
    {
109
      typedef _Deque_iterator<_Tp, _Tp&, _Tp*>             iterator;
110
      typedef _Deque_iterator<_Tp, const _Tp&, const _Tp*> const_iterator;
111
 
112
      static size_t _S_buffer_size()
113
      { return __deque_buf_size(sizeof(_Tp)); }
114
 
115
      typedef std::random_access_iterator_tag iterator_category;
116
      typedef _Tp                             value_type;
117
      typedef _Ptr                            pointer;
118
      typedef _Ref                            reference;
119
      typedef size_t                          size_type;
120
      typedef ptrdiff_t                       difference_type;
121
      typedef _Tp**                           _Map_pointer;
122
      typedef _Deque_iterator                 _Self;
123
 
124
      _Tp* _M_cur;
125
      _Tp* _M_first;
126
      _Tp* _M_last;
127
      _Map_pointer _M_node;
128
 
129
      _Deque_iterator(_Tp* __x, _Map_pointer __y)
130
      : _M_cur(__x), _M_first(*__y),
131
        _M_last(*__y + _S_buffer_size()), _M_node(__y) { }
132
 
133
      _Deque_iterator()
134
      : _M_cur(0), _M_first(0), _M_last(0), _M_node(0) { }
135
 
136
      _Deque_iterator(const iterator& __x)
137
      : _M_cur(__x._M_cur), _M_first(__x._M_first),
138
        _M_last(__x._M_last), _M_node(__x._M_node) { }
139
 
140
      reference
141
      operator*() const
142
      { return *_M_cur; }
143
 
144
      pointer
145
      operator->() const
146
      { return _M_cur; }
147
 
148
      _Self&
149
      operator++()
150
      {
151
        ++_M_cur;
152
        if (_M_cur == _M_last)
153
          {
154
            _M_set_node(_M_node + 1);
155
            _M_cur = _M_first;
156
          }
157
        return *this;
158
      }
159
 
160
      _Self
161
      operator++(int)
162
      {
163
        _Self __tmp = *this;
164
        ++*this;
165
        return __tmp;
166
      }
167
 
168
      _Self&
169
      operator--()
170
      {
171
        if (_M_cur == _M_first)
172
          {
173
            _M_set_node(_M_node - 1);
174
            _M_cur = _M_last;
175
          }
176
        --_M_cur;
177
        return *this;
178
      }
179
 
180
      _Self
181
      operator--(int)
182
      {
183
        _Self __tmp = *this;
184
        --*this;
185
        return __tmp;
186
      }
187
 
188
      _Self&
189
      operator+=(difference_type __n)
190
      {
191
        const difference_type __offset = __n + (_M_cur - _M_first);
192
        if (__offset >= 0 && __offset < difference_type(_S_buffer_size()))
193
          _M_cur += __n;
194
        else
195
          {
196
            const difference_type __node_offset =
197
              __offset > 0 ? __offset / difference_type(_S_buffer_size())
198
                           : -difference_type((-__offset - 1)
199
                                              / _S_buffer_size()) - 1;
200
            _M_set_node(_M_node + __node_offset);
201
            _M_cur = _M_first + (__offset - __node_offset
202
                                 * difference_type(_S_buffer_size()));
203
          }
204
        return *this;
205
      }
206
 
207
      _Self
208
      operator+(difference_type __n) const
209
      {
210
        _Self __tmp = *this;
211
        return __tmp += __n;
212
      }
213
 
214
      _Self&
215
      operator-=(difference_type __n)
216
      { return *this += -__n; }
217
 
218
      _Self
219
      operator-(difference_type __n) const
220
      {
221
        _Self __tmp = *this;
222
        return __tmp -= __n;
223
      }
224
 
225
      reference
226
      operator[](difference_type __n) const
227
      { return *(*this + __n); }
228
 
229
      /**
230
       *  Prepares to traverse new_node.  Sets everything except
231
       *  _M_cur, which should therefore be set by the caller
232
       *  immediately afterwards, based on _M_first and _M_last.
233
       */
234
      void
235
      _M_set_node(_Map_pointer __new_node)
236
      {
237
        _M_node = __new_node;
238
        _M_first = *__new_node;
239
        _M_last = _M_first + difference_type(_S_buffer_size());
240
      }
241
    };
242
 
243
  // Note: we also provide overloads whose operands are of the same type in
244
  // order to avoid ambiguous overload resolution when std::rel_ops operators
245
  // are in scope (for additional details, see libstdc++/3628)
246
  template<typename _Tp, typename _Ref, typename _Ptr>
247
    inline bool
248
    operator==(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
249
               const _Deque_iterator<_Tp, _Ref, _Ptr>& __y)
250
    { return __x._M_cur == __y._M_cur; }
251
 
252
  template<typename _Tp, typename _RefL, typename _PtrL,
253
           typename _RefR, typename _PtrR>
254
    inline bool
255
    operator==(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
256
               const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
257
    { return __x._M_cur == __y._M_cur; }
258
 
259
  template<typename _Tp, typename _Ref, typename _Ptr>
260
    inline bool
261
    operator!=(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
262
               const _Deque_iterator<_Tp, _Ref, _Ptr>& __y)
263
    { return !(__x == __y); }
264
 
265
  template<typename _Tp, typename _RefL, typename _PtrL,
266
           typename _RefR, typename _PtrR>
267
    inline bool
268
    operator!=(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
269
               const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
270
    { return !(__x == __y); }
271
 
272
  template<typename _Tp, typename _Ref, typename _Ptr>
273
    inline bool
274
    operator<(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
275
              const _Deque_iterator<_Tp, _Ref, _Ptr>& __y)
276
    { return (__x._M_node == __y._M_node) ? (__x._M_cur < __y._M_cur)
277
                                          : (__x._M_node < __y._M_node); }
278
 
279
  template<typename _Tp, typename _RefL, typename _PtrL,
280
           typename _RefR, typename _PtrR>
281
    inline bool
282
    operator<(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
283
              const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
284
    { return (__x._M_node == __y._M_node) ? (__x._M_cur < __y._M_cur)
285
                                          : (__x._M_node < __y._M_node); }
286
 
287
  template<typename _Tp, typename _Ref, typename _Ptr>
288
    inline bool
289
    operator>(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
290
              const _Deque_iterator<_Tp, _Ref, _Ptr>& __y)
291
    { return __y < __x; }
292
 
293
  template<typename _Tp, typename _RefL, typename _PtrL,
294
           typename _RefR, typename _PtrR>
295
    inline bool
296
    operator>(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
297
              const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
298
    { return __y < __x; }
299
 
300
  template<typename _Tp, typename _Ref, typename _Ptr>
301
    inline bool
302
    operator<=(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
303
               const _Deque_iterator<_Tp, _Ref, _Ptr>& __y)
304
    { return !(__y < __x); }
305
 
306
  template<typename _Tp, typename _RefL, typename _PtrL,
307
           typename _RefR, typename _PtrR>
308
    inline bool
309
    operator<=(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
310
               const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
311
    { return !(__y < __x); }
312
 
313
  template<typename _Tp, typename _Ref, typename _Ptr>
314
    inline bool
315
    operator>=(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
316
               const _Deque_iterator<_Tp, _Ref, _Ptr>& __y)
317
    { return !(__x < __y); }
318
 
319
  template<typename _Tp, typename _RefL, typename _PtrL,
320
           typename _RefR, typename _PtrR>
321
    inline bool
322
    operator>=(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
323
               const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
324
    { return !(__x < __y); }
325
 
326
  // _GLIBCXX_RESOLVE_LIB_DEFECTS
327
  // According to the resolution of DR179 not only the various comparison
328
  // operators but also operator- must accept mixed iterator/const_iterator
329
  // parameters.
330
  template<typename _Tp, typename _Ref, typename _Ptr>
331
    inline typename _Deque_iterator<_Tp, _Ref, _Ptr>::difference_type
332
    operator-(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
333
              const _Deque_iterator<_Tp, _Ref, _Ptr>& __y)
334
    {
335
      return typename _Deque_iterator<_Tp, _Ref, _Ptr>::difference_type
336
        (_Deque_iterator<_Tp, _Ref, _Ptr>::_S_buffer_size())
337
        * (__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first)
338
        + (__y._M_last - __y._M_cur);
339
    }
340
 
341
  template<typename _Tp, typename _RefL, typename _PtrL,
342
           typename _RefR, typename _PtrR>
343
    inline typename _Deque_iterator<_Tp, _RefL, _PtrL>::difference_type
344
    operator-(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
345
              const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
346
    {
347
      return typename _Deque_iterator<_Tp, _RefL, _PtrL>::difference_type
348
        (_Deque_iterator<_Tp, _RefL, _PtrL>::_S_buffer_size())
349
        * (__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first)
350
        + (__y._M_last - __y._M_cur);
351
    }
352
 
353
  template<typename _Tp, typename _Ref, typename _Ptr>
354
    inline _Deque_iterator<_Tp, _Ref, _Ptr>
355
    operator+(ptrdiff_t __n, const _Deque_iterator<_Tp, _Ref, _Ptr>& __x)
356
    { return __x + __n; }
357
 
358
  template<typename _Tp>
359
    void
360
    fill(const _Deque_iterator<_Tp, _Tp&, _Tp*>&,
361
         const _Deque_iterator<_Tp, _Tp&, _Tp*>&, const _Tp&);
362
 
363
  template<typename _Tp>
364
    _Deque_iterator<_Tp, _Tp&, _Tp*>
365
    copy(_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
366
         _Deque_iterator<_Tp, const _Tp&, const _Tp*>,
367
         _Deque_iterator<_Tp, _Tp&, _Tp*>);
368
 
369
  template<typename _Tp>
370
    inline _Deque_iterator<_Tp, _Tp&, _Tp*>
371
    copy(_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
372
         _Deque_iterator<_Tp, _Tp&, _Tp*> __last,
373
         _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
374
    { return std::copy(_Deque_iterator<_Tp, const _Tp&, const _Tp*>(__first),
375
                       _Deque_iterator<_Tp, const _Tp&, const _Tp*>(__last),
376
                       __result); }
377
 
378
  template<typename _Tp>
379
    _Deque_iterator<_Tp, _Tp&, _Tp*>
380
    copy_backward(_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
381
                  _Deque_iterator<_Tp, const _Tp&, const _Tp*>,
382
                  _Deque_iterator<_Tp, _Tp&, _Tp*>);
383
 
384
  template<typename _Tp>
385
    inline _Deque_iterator<_Tp, _Tp&, _Tp*>
386
    copy_backward(_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
387
                  _Deque_iterator<_Tp, _Tp&, _Tp*> __last,
388
                  _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
389
    { return std::copy_backward(_Deque_iterator<_Tp,
390
                                const _Tp&, const _Tp*>(__first),
391
                                _Deque_iterator<_Tp,
392
                                const _Tp&, const _Tp*>(__last),
393
                                __result); }
394
 
395
#if __cplusplus >= 201103L
396
  template<typename _Tp>
397
    _Deque_iterator<_Tp, _Tp&, _Tp*>
398
    move(_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
399
         _Deque_iterator<_Tp, const _Tp&, const _Tp*>,
400
         _Deque_iterator<_Tp, _Tp&, _Tp*>);
401
 
402
  template<typename _Tp>
403
    inline _Deque_iterator<_Tp, _Tp&, _Tp*>
404
    move(_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
405
         _Deque_iterator<_Tp, _Tp&, _Tp*> __last,
406
         _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
407
    { return std::move(_Deque_iterator<_Tp, const _Tp&, const _Tp*>(__first),
408
                       _Deque_iterator<_Tp, const _Tp&, const _Tp*>(__last),
409
                       __result); }
410
 
411
  template<typename _Tp>
412
    _Deque_iterator<_Tp, _Tp&, _Tp*>
413
    move_backward(_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
414
                  _Deque_iterator<_Tp, const _Tp&, const _Tp*>,
415
                  _Deque_iterator<_Tp, _Tp&, _Tp*>);
416
 
417
  template<typename _Tp>
418
    inline _Deque_iterator<_Tp, _Tp&, _Tp*>
419
    move_backward(_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
420
                  _Deque_iterator<_Tp, _Tp&, _Tp*> __last,
421
                  _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
422
    { return std::move_backward(_Deque_iterator<_Tp,
423
                                const _Tp&, const _Tp*>(__first),
424
                                _Deque_iterator<_Tp,
425
                                const _Tp&, const _Tp*>(__last),
426
                                __result); }
427
#endif
428
 
429
  /**
430
   *  Deque base class.  This class provides the unified face for %deque's
431
   *  allocation.  This class's constructor and destructor allocate and
432
   *  deallocate (but do not initialize) storage.  This makes %exception
433
   *  safety easier.
434
   *
435
   *  Nothing in this class ever constructs or destroys an actual Tp element.
436
   *  (Deque handles that itself.)  Only/All memory management is performed
437
   *  here.
438
  */
439
  template<typename _Tp, typename _Alloc>
440
    class _Deque_base
441
    {
442
    public:
443
      typedef _Alloc                  allocator_type;
444
 
445
      allocator_type
446
      get_allocator() const _GLIBCXX_NOEXCEPT
447
      { return allocator_type(_M_get_Tp_allocator()); }
448
 
449
      typedef _Deque_iterator<_Tp, _Tp&, _Tp*>             iterator;
450
      typedef _Deque_iterator<_Tp, const _Tp&, const _Tp*> const_iterator;
451
 
452
      _Deque_base()
453
      : _M_impl()
454
      { _M_initialize_map(0); }
455
 
456
      _Deque_base(size_t __num_elements)
457
      : _M_impl()
458
      { _M_initialize_map(__num_elements); }
459
 
460
      _Deque_base(const allocator_type& __a, size_t __num_elements)
461
      : _M_impl(__a)
462
      { _M_initialize_map(__num_elements); }
463
 
464
      _Deque_base(const allocator_type& __a)
465
      : _M_impl(__a)
466
      { }
467
 
468
#if __cplusplus >= 201103L
469
      _Deque_base(_Deque_base&& __x)
470
      : _M_impl(std::move(__x._M_get_Tp_allocator()))
471
      {
472
        _M_initialize_map(0);
473
        if (__x._M_impl._M_map)
474
          {
475
            std::swap(this->_M_impl._M_start, __x._M_impl._M_start);
476
            std::swap(this->_M_impl._M_finish, __x._M_impl._M_finish);
477
            std::swap(this->_M_impl._M_map, __x._M_impl._M_map);
478
            std::swap(this->_M_impl._M_map_size, __x._M_impl._M_map_size);
479
          }
480
      }
481
#endif
482
 
483
      ~_Deque_base();
484
 
485
    protected:
486
      //This struct encapsulates the implementation of the std::deque
487
      //standard container and at the same time makes use of the EBO
488
      //for empty allocators.
489
      typedef typename _Alloc::template rebind<_Tp*>::other _Map_alloc_type;
490
 
491
      typedef typename _Alloc::template rebind<_Tp>::other  _Tp_alloc_type;
492
 
493
      struct _Deque_impl
494
      : public _Tp_alloc_type
495
      {
496
        _Tp** _M_map;
497
        size_t _M_map_size;
498
        iterator _M_start;
499
        iterator _M_finish;
500
 
501
        _Deque_impl()
502
        : _Tp_alloc_type(), _M_map(0), _M_map_size(0),
503
          _M_start(), _M_finish()
504
        { }
505
 
506
        _Deque_impl(const _Tp_alloc_type& __a)
507
        : _Tp_alloc_type(__a), _M_map(0), _M_map_size(0),
508
          _M_start(), _M_finish()
509
        { }
510
 
511
#if __cplusplus >= 201103L
512
        _Deque_impl(_Tp_alloc_type&& __a)
513
        : _Tp_alloc_type(std::move(__a)), _M_map(0), _M_map_size(0),
514
          _M_start(), _M_finish()
515
        { }
516
#endif
517
      };
518
 
519
      _Tp_alloc_type&
520
      _M_get_Tp_allocator() _GLIBCXX_NOEXCEPT
521
      { return *static_cast<_Tp_alloc_type*>(&this->_M_impl); }
522
 
523
      const _Tp_alloc_type&
524
      _M_get_Tp_allocator() const _GLIBCXX_NOEXCEPT
525
      { return *static_cast<const _Tp_alloc_type*>(&this->_M_impl); }
526
 
527
      _Map_alloc_type
528
      _M_get_map_allocator() const _GLIBCXX_NOEXCEPT
529
      { return _Map_alloc_type(_M_get_Tp_allocator()); }
530
 
531
      _Tp*
532
      _M_allocate_node()
533
      {
534
        return _M_impl._Tp_alloc_type::allocate(__deque_buf_size(sizeof(_Tp)));
535
      }
536
 
537
      void
538
      _M_deallocate_node(_Tp* __p)
539
      {
540
        _M_impl._Tp_alloc_type::deallocate(__p, __deque_buf_size(sizeof(_Tp)));
541
      }
542
 
543
      _Tp**
544
      _M_allocate_map(size_t __n)
545
      { return _M_get_map_allocator().allocate(__n); }
546
 
547
      void
548
      _M_deallocate_map(_Tp** __p, size_t __n)
549
      { _M_get_map_allocator().deallocate(__p, __n); }
550
 
551
    protected:
552
      void _M_initialize_map(size_t);
553
      void _M_create_nodes(_Tp** __nstart, _Tp** __nfinish);
554
      void _M_destroy_nodes(_Tp** __nstart, _Tp** __nfinish);
555
      enum { _S_initial_map_size = 8 };
556
 
557
      _Deque_impl _M_impl;
558
    };
559
 
560
  template<typename _Tp, typename _Alloc>
561
    _Deque_base<_Tp, _Alloc>::
562
    ~_Deque_base()
563
    {
564
      if (this->_M_impl._M_map)
565
        {
566
          _M_destroy_nodes(this->_M_impl._M_start._M_node,
567
                           this->_M_impl._M_finish._M_node + 1);
568
          _M_deallocate_map(this->_M_impl._M_map, this->_M_impl._M_map_size);
569
        }
570
    }
571
 
572
  /**
573
   *  @brief Layout storage.
574
   *  @param  __num_elements  The count of T's for which to allocate space
575
   *                        at first.
576
   *  @return   Nothing.
577
   *
578
   *  The initial underlying memory layout is a bit complicated...
579
  */
580
  template<typename _Tp, typename _Alloc>
581
    void
582
    _Deque_base<_Tp, _Alloc>::
583
    _M_initialize_map(size_t __num_elements)
584
    {
585
      const size_t __num_nodes = (__num_elements/ __deque_buf_size(sizeof(_Tp))
586
                                  + 1);
587
 
588
      this->_M_impl._M_map_size = std::max((size_t) _S_initial_map_size,
589
                                           size_t(__num_nodes + 2));
590
      this->_M_impl._M_map = _M_allocate_map(this->_M_impl._M_map_size);
591
 
592
      // For "small" maps (needing less than _M_map_size nodes), allocation
593
      // starts in the middle elements and grows outwards.  So nstart may be
594
      // the beginning of _M_map, but for small maps it may be as far in as
595
      // _M_map+3.
596
 
597
      _Tp** __nstart = (this->_M_impl._M_map
598
                        + (this->_M_impl._M_map_size - __num_nodes) / 2);
599
      _Tp** __nfinish = __nstart + __num_nodes;
600
 
601
      __try
602
        { _M_create_nodes(__nstart, __nfinish); }
603
      __catch(...)
604
        {
605
          _M_deallocate_map(this->_M_impl._M_map, this->_M_impl._M_map_size);
606
          this->_M_impl._M_map = 0;
607
          this->_M_impl._M_map_size = 0;
608
          __throw_exception_again;
609
        }
610
 
611
      this->_M_impl._M_start._M_set_node(__nstart);
612
      this->_M_impl._M_finish._M_set_node(__nfinish - 1);
613
      this->_M_impl._M_start._M_cur = _M_impl._M_start._M_first;
614
      this->_M_impl._M_finish._M_cur = (this->_M_impl._M_finish._M_first
615
                                        + __num_elements
616
                                        % __deque_buf_size(sizeof(_Tp)));
617
    }
618
 
619
  template<typename _Tp, typename _Alloc>
620
    void
621
    _Deque_base<_Tp, _Alloc>::
622
    _M_create_nodes(_Tp** __nstart, _Tp** __nfinish)
623
    {
624
      _Tp** __cur;
625
      __try
626
        {
627
          for (__cur = __nstart; __cur < __nfinish; ++__cur)
628
            *__cur = this->_M_allocate_node();
629
        }
630
      __catch(...)
631
        {
632
          _M_destroy_nodes(__nstart, __cur);
633
          __throw_exception_again;
634
        }
635
    }
636
 
637
  template<typename _Tp, typename _Alloc>
638
    void
639
    _Deque_base<_Tp, _Alloc>::
640
    _M_destroy_nodes(_Tp** __nstart, _Tp** __nfinish)
641
    {
642
      for (_Tp** __n = __nstart; __n < __nfinish; ++__n)
643
        _M_deallocate_node(*__n);
644
    }
645
 
646
  /**
647
   *  @brief  A standard container using fixed-size memory allocation and
648
   *  constant-time manipulation of elements at either end.
649
   *
650
   *  @ingroup sequences
651
   *
652
   *  @tparam _Tp  Type of element.
653
   *  @tparam _Alloc  Allocator type, defaults to allocator<_Tp>.
654
   *
655
   *  Meets the requirements of a <a href="tables.html#65">container</a>, a
656
   *  <a href="tables.html#66">reversible container</a>, and a
657
   *  <a href="tables.html#67">sequence</a>, including the
658
   *  <a href="tables.html#68">optional sequence requirements</a>.
659
   *
660
   *  In previous HP/SGI versions of deque, there was an extra template
661
   *  parameter so users could control the node size.  This extension turned
662
   *  out to violate the C++ standard (it can be detected using template
663
   *  template parameters), and it was removed.
664
   *
665
   *  Here's how a deque<Tp> manages memory.  Each deque has 4 members:
666
   *
667
   *  - Tp**        _M_map
668
   *  - size_t      _M_map_size
669
   *  - iterator    _M_start, _M_finish
670
   *
671
   *  map_size is at least 8.  %map is an array of map_size
672
   *  pointers-to-@a nodes.  (The name %map has nothing to do with the
673
   *  std::map class, and @b nodes should not be confused with
674
   *  std::list's usage of @a node.)
675
   *
676
   *  A @a node has no specific type name as such, but it is referred
677
   *  to as @a node in this file.  It is a simple array-of-Tp.  If Tp
678
   *  is very large, there will be one Tp element per node (i.e., an
679
   *  @a array of one).  For non-huge Tp's, node size is inversely
680
   *  related to Tp size: the larger the Tp, the fewer Tp's will fit
681
   *  in a node.  The goal here is to keep the total size of a node
682
   *  relatively small and constant over different Tp's, to improve
683
   *  allocator efficiency.
684
   *
685
   *  Not every pointer in the %map array will point to a node.  If
686
   *  the initial number of elements in the deque is small, the
687
   *  /middle/ %map pointers will be valid, and the ones at the edges
688
   *  will be unused.  This same situation will arise as the %map
689
   *  grows: available %map pointers, if any, will be on the ends.  As
690
   *  new nodes are created, only a subset of the %map's pointers need
691
   *  to be copied @a outward.
692
   *
693
   *  Class invariants:
694
   * - For any nonsingular iterator i:
695
   *    - i.node points to a member of the %map array.  (Yes, you read that
696
   *      correctly:  i.node does not actually point to a node.)  The member of
697
   *      the %map array is what actually points to the node.
698
   *    - i.first == *(i.node)    (This points to the node (first Tp element).)
699
   *    - i.last  == i.first + node_size
700
   *    - i.cur is a pointer in the range [i.first, i.last).  NOTE:
701
   *      the implication of this is that i.cur is always a dereferenceable
702
   *      pointer, even if i is a past-the-end iterator.
703
   * - Start and Finish are always nonsingular iterators.  NOTE: this
704
   * means that an empty deque must have one node, a deque with <N
705
   * elements (where N is the node buffer size) must have one node, a
706
   * deque with N through (2N-1) elements must have two nodes, etc.
707
   * - For every node other than start.node and finish.node, every
708
   * element in the node is an initialized object.  If start.node ==
709
   * finish.node, then [start.cur, finish.cur) are initialized
710
   * objects, and the elements outside that range are uninitialized
711
   * storage.  Otherwise, [start.cur, start.last) and [finish.first,
712
   * finish.cur) are initialized objects, and [start.first, start.cur)
713
   * and [finish.cur, finish.last) are uninitialized storage.
714
   * - [%map, %map + map_size) is a valid, non-empty range.
715
   * - [start.node, finish.node] is a valid range contained within
716
   *   [%map, %map + map_size).
717
   * - A pointer in the range [%map, %map + map_size) points to an allocated
718
   *   node if and only if the pointer is in the range
719
   *   [start.node, finish.node].
720
   *
721
   *  Here's the magic:  nothing in deque is @b aware of the discontiguous
722
   *  storage!
723
   *
724
   *  The memory setup and layout occurs in the parent, _Base, and the iterator
725
   *  class is entirely responsible for @a leaping from one node to the next.
726
   *  All the implementation routines for deque itself work only through the
727
   *  start and finish iterators.  This keeps the routines simple and sane,
728
   *  and we can use other standard algorithms as well.
729
  */
730
  template<typename _Tp, typename _Alloc = std::allocator<_Tp> >
731
    class deque : protected _Deque_base<_Tp, _Alloc>
732
    {
733
      // concept requirements
734
      typedef typename _Alloc::value_type        _Alloc_value_type;
735
      __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
736
      __glibcxx_class_requires2(_Tp, _Alloc_value_type, _SameTypeConcept)
737
 
738
      typedef _Deque_base<_Tp, _Alloc>           _Base;
739
      typedef typename _Base::_Tp_alloc_type     _Tp_alloc_type;
740
 
741
    public:
742
      typedef _Tp                                        value_type;
743
      typedef typename _Tp_alloc_type::pointer           pointer;
744
      typedef typename _Tp_alloc_type::const_pointer     const_pointer;
745
      typedef typename _Tp_alloc_type::reference         reference;
746
      typedef typename _Tp_alloc_type::const_reference   const_reference;
747
      typedef typename _Base::iterator                   iterator;
748
      typedef typename _Base::const_iterator             const_iterator;
749
      typedef std::reverse_iterator<const_iterator>      const_reverse_iterator;
750
      typedef std::reverse_iterator<iterator>            reverse_iterator;
751
      typedef size_t                             size_type;
752
      typedef ptrdiff_t                          difference_type;
753
      typedef _Alloc                             allocator_type;
754
 
755
    protected:
756
      typedef pointer*                           _Map_pointer;
757
 
758
      static size_t _S_buffer_size()
759
      { return __deque_buf_size(sizeof(_Tp)); }
760
 
761
      // Functions controlling memory layout, and nothing else.
762
      using _Base::_M_initialize_map;
763
      using _Base::_M_create_nodes;
764
      using _Base::_M_destroy_nodes;
765
      using _Base::_M_allocate_node;
766
      using _Base::_M_deallocate_node;
767
      using _Base::_M_allocate_map;
768
      using _Base::_M_deallocate_map;
769
      using _Base::_M_get_Tp_allocator;
770
 
771
      /**
772
       *  A total of four data members accumulated down the hierarchy.
773
       *  May be accessed via _M_impl.*
774
       */
775
      using _Base::_M_impl;
776
 
777
    public:
778
      // [23.2.1.1] construct/copy/destroy
779
      // (assign() and get_allocator() are also listed in this section)
780
      /**
781
       *  @brief  Default constructor creates no elements.
782
       */
783
      deque()
784
      : _Base() { }
785
 
786
      /**
787
       *  @brief  Creates a %deque with no elements.
788
       *  @param  __a  An allocator object.
789
       */
790
      explicit
791
      deque(const allocator_type& __a)
792
      : _Base(__a, 0) { }
793
 
794
#if __cplusplus >= 201103L
795
      /**
796
       *  @brief  Creates a %deque with default constructed elements.
797
       *  @param  __n  The number of elements to initially create.
798
       *
799
       *  This constructor fills the %deque with @a n default
800
       *  constructed elements.
801
       */
802
      explicit
803
      deque(size_type __n)
804
      : _Base(__n)
805
      { _M_default_initialize(); }
806
 
807
      /**
808
       *  @brief  Creates a %deque with copies of an exemplar element.
809
       *  @param  __n  The number of elements to initially create.
810
       *  @param  __value  An element to copy.
811
       *  @param  __a  An allocator.
812
       *
813
       *  This constructor fills the %deque with @a __n copies of @a __value.
814
       */
815
      deque(size_type __n, const value_type& __value,
816
            const allocator_type& __a = allocator_type())
817
      : _Base(__a, __n)
818
      { _M_fill_initialize(__value); }
819
#else
820
      /**
821
       *  @brief  Creates a %deque with copies of an exemplar element.
822
       *  @param  __n  The number of elements to initially create.
823
       *  @param  __value  An element to copy.
824
       *  @param  __a  An allocator.
825
       *
826
       *  This constructor fills the %deque with @a __n copies of @a __value.
827
       */
828
      explicit
829
      deque(size_type __n, const value_type& __value = value_type(),
830
            const allocator_type& __a = allocator_type())
831
      : _Base(__a, __n)
832
      { _M_fill_initialize(__value); }
833
#endif
834
 
835
      /**
836
       *  @brief  %Deque copy constructor.
837
       *  @param  __x  A %deque of identical element and allocator types.
838
       *
839
       *  The newly-created %deque uses a copy of the allocation object used
840
       *  by @a __x.
841
       */
842
      deque(const deque& __x)
843
      : _Base(__x._M_get_Tp_allocator(), __x.size())
844
      { std::__uninitialized_copy_a(__x.begin(), __x.end(),
845
                                    this->_M_impl._M_start,
846
                                    _M_get_Tp_allocator()); }
847
 
848
#if __cplusplus >= 201103L
849
      /**
850
       *  @brief  %Deque move constructor.
851
       *  @param  __x  A %deque of identical element and allocator types.
852
       *
853
       *  The newly-created %deque contains the exact contents of @a __x.
854
       *  The contents of @a __x are a valid, but unspecified %deque.
855
       */
856
      deque(deque&& __x)
857
      : _Base(std::move(__x)) { }
858
 
859
      /**
860
       *  @brief  Builds a %deque from an initializer list.
861
       *  @param  __l  An initializer_list.
862
       *  @param  __a  An allocator object.
863
       *
864
       *  Create a %deque consisting of copies of the elements in the
865
       *  initializer_list @a __l.
866
       *
867
       *  This will call the element type's copy constructor N times
868
       *  (where N is __l.size()) and do no memory reallocation.
869
       */
870
      deque(initializer_list<value_type> __l,
871
            const allocator_type& __a = allocator_type())
872
      : _Base(__a)
873
      {
874
        _M_range_initialize(__l.begin(), __l.end(),
875
                            random_access_iterator_tag());
876
      }
877
#endif
878
 
879
      /**
880
       *  @brief  Builds a %deque from a range.
881
       *  @param  __first  An input iterator.
882
       *  @param  __last  An input iterator.
883
       *  @param  __a  An allocator object.
884
       *
885
       *  Create a %deque consisting of copies of the elements from [__first,
886
       *  __last).
887
       *
888
       *  If the iterators are forward, bidirectional, or random-access, then
889
       *  this will call the elements' copy constructor N times (where N is
890
       *  distance(__first,__last)) and do no memory reallocation.  But if only
891
       *  input iterators are used, then this will do at most 2N calls to the
892
       *  copy constructor, and logN memory reallocations.
893
       */
894
#if __cplusplus >= 201103L
895
      template<typename _InputIterator,
896
               typename = std::_RequireInputIter<_InputIterator>>
897
        deque(_InputIterator __first, _InputIterator __last,
898
              const allocator_type& __a = allocator_type())
899
        : _Base(__a)
900
        { _M_initialize_dispatch(__first, __last, __false_type()); }
901
#else
902
      template<typename _InputIterator>
903
        deque(_InputIterator __first, _InputIterator __last,
904
              const allocator_type& __a = allocator_type())
905
        : _Base(__a)
906
        {
907
          // Check whether it's an integral type.  If so, it's not an iterator.
908
          typedef typename std::__is_integer<_InputIterator>::__type _Integral;
909
          _M_initialize_dispatch(__first, __last, _Integral());
910
        }
911
#endif
912
 
913
      /**
914
       *  The dtor only erases the elements, and note that if the elements
915
       *  themselves are pointers, the pointed-to memory is not touched in any
916
       *  way.  Managing the pointer is the user's responsibility.
917
       */
918
      ~deque() _GLIBCXX_NOEXCEPT
919
      { _M_destroy_data(begin(), end(), _M_get_Tp_allocator()); }
920
 
921
      /**
922
       *  @brief  %Deque assignment operator.
923
       *  @param  __x  A %deque of identical element and allocator types.
924
       *
925
       *  All the elements of @a x are copied, but unlike the copy constructor,
926
       *  the allocator object is not copied.
927
       */
928
      deque&
929
      operator=(const deque& __x);
930
 
931
#if __cplusplus >= 201103L
932
      /**
933
       *  @brief  %Deque move assignment operator.
934
       *  @param  __x  A %deque of identical element and allocator types.
935
       *
936
       *  The contents of @a __x are moved into this deque (without copying).
937
       *  @a __x is a valid, but unspecified %deque.
938
       */
939
      deque&
940
      operator=(deque&& __x)
941
      {
942
        // NB: DR 1204.
943
        // NB: DR 675.
944
        this->clear();
945
        this->swap(__x);
946
        return *this;
947
      }
948
 
949
      /**
950
       *  @brief  Assigns an initializer list to a %deque.
951
       *  @param  __l  An initializer_list.
952
       *
953
       *  This function fills a %deque with copies of the elements in the
954
       *  initializer_list @a __l.
955
       *
956
       *  Note that the assignment completely changes the %deque and that the
957
       *  resulting %deque's size is the same as the number of elements
958
       *  assigned.  Old data may be lost.
959
       */
960
      deque&
961
      operator=(initializer_list<value_type> __l)
962
      {
963
        this->assign(__l.begin(), __l.end());
964
        return *this;
965
      }
966
#endif
967
 
968
      /**
969
       *  @brief  Assigns a given value to a %deque.
970
       *  @param  __n  Number of elements to be assigned.
971
       *  @param  __val  Value to be assigned.
972
       *
973
       *  This function fills a %deque with @a n copies of the given
974
       *  value.  Note that the assignment completely changes the
975
       *  %deque and that the resulting %deque's size is the same as
976
       *  the number of elements assigned.  Old data may be lost.
977
       */
978
      void
979
      assign(size_type __n, const value_type& __val)
980
      { _M_fill_assign(__n, __val); }
981
 
982
      /**
983
       *  @brief  Assigns a range to a %deque.
984
       *  @param  __first  An input iterator.
985
       *  @param  __last   An input iterator.
986
       *
987
       *  This function fills a %deque with copies of the elements in the
988
       *  range [__first,__last).
989
       *
990
       *  Note that the assignment completely changes the %deque and that the
991
       *  resulting %deque's size is the same as the number of elements
992
       *  assigned.  Old data may be lost.
993
       */
994
#if __cplusplus >= 201103L
995
      template<typename _InputIterator,
996
               typename = std::_RequireInputIter<_InputIterator>>
997
        void
998
        assign(_InputIterator __first, _InputIterator __last)
999
        { _M_assign_dispatch(__first, __last, __false_type()); }
1000
#else
1001
      template<typename _InputIterator>
1002
        void
1003
        assign(_InputIterator __first, _InputIterator __last)
1004
        {
1005
          typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1006
          _M_assign_dispatch(__first, __last, _Integral());
1007
        }
1008
#endif
1009
 
1010
#if __cplusplus >= 201103L
1011
      /**
1012
       *  @brief  Assigns an initializer list to a %deque.
1013
       *  @param  __l  An initializer_list.
1014
       *
1015
       *  This function fills a %deque with copies of the elements in the
1016
       *  initializer_list @a __l.
1017
       *
1018
       *  Note that the assignment completely changes the %deque and that the
1019
       *  resulting %deque's size is the same as the number of elements
1020
       *  assigned.  Old data may be lost.
1021
       */
1022
      void
1023
      assign(initializer_list<value_type> __l)
1024
      { this->assign(__l.begin(), __l.end()); }
1025
#endif
1026
 
1027
      /// Get a copy of the memory allocation object.
1028
      allocator_type
1029
      get_allocator() const _GLIBCXX_NOEXCEPT
1030
      { return _Base::get_allocator(); }
1031
 
1032
      // iterators
1033
      /**
1034
       *  Returns a read/write iterator that points to the first element in the
1035
       *  %deque.  Iteration is done in ordinary element order.
1036
       */
1037
      iterator
1038
      begin() _GLIBCXX_NOEXCEPT
1039
      { return this->_M_impl._M_start; }
1040
 
1041
      /**
1042
       *  Returns a read-only (constant) iterator that points to the first
1043
       *  element in the %deque.  Iteration is done in ordinary element order.
1044
       */
1045
      const_iterator
1046
      begin() const _GLIBCXX_NOEXCEPT
1047
      { return this->_M_impl._M_start; }
1048
 
1049
      /**
1050
       *  Returns a read/write iterator that points one past the last
1051
       *  element in the %deque.  Iteration is done in ordinary
1052
       *  element order.
1053
       */
1054
      iterator
1055
      end() _GLIBCXX_NOEXCEPT
1056
      { return this->_M_impl._M_finish; }
1057
 
1058
      /**
1059
       *  Returns a read-only (constant) iterator that points one past
1060
       *  the last element in the %deque.  Iteration is done in
1061
       *  ordinary element order.
1062
       */
1063
      const_iterator
1064
      end() const _GLIBCXX_NOEXCEPT
1065
      { return this->_M_impl._M_finish; }
1066
 
1067
      /**
1068
       *  Returns a read/write reverse iterator that points to the
1069
       *  last element in the %deque.  Iteration is done in reverse
1070
       *  element order.
1071
       */
1072
      reverse_iterator
1073
      rbegin() _GLIBCXX_NOEXCEPT
1074
      { return reverse_iterator(this->_M_impl._M_finish); }
1075
 
1076
      /**
1077
       *  Returns a read-only (constant) reverse iterator that points
1078
       *  to the last element in the %deque.  Iteration is done in
1079
       *  reverse element order.
1080
       */
1081
      const_reverse_iterator
1082
      rbegin() const _GLIBCXX_NOEXCEPT
1083
      { return const_reverse_iterator(this->_M_impl._M_finish); }
1084
 
1085
      /**
1086
       *  Returns a read/write reverse iterator that points to one
1087
       *  before the first element in the %deque.  Iteration is done
1088
       *  in reverse element order.
1089
       */
1090
      reverse_iterator
1091
      rend() _GLIBCXX_NOEXCEPT
1092
      { return reverse_iterator(this->_M_impl._M_start); }
1093
 
1094
      /**
1095
       *  Returns a read-only (constant) reverse iterator that points
1096
       *  to one before the first element in the %deque.  Iteration is
1097
       *  done in reverse element order.
1098
       */
1099
      const_reverse_iterator
1100
      rend() const _GLIBCXX_NOEXCEPT
1101
      { return const_reverse_iterator(this->_M_impl._M_start); }
1102
 
1103
#if __cplusplus >= 201103L
1104
      /**
1105
       *  Returns a read-only (constant) iterator that points to the first
1106
       *  element in the %deque.  Iteration is done in ordinary element order.
1107
       */
1108
      const_iterator
1109
      cbegin() const noexcept
1110
      { return this->_M_impl._M_start; }
1111
 
1112
      /**
1113
       *  Returns a read-only (constant) iterator that points one past
1114
       *  the last element in the %deque.  Iteration is done in
1115
       *  ordinary element order.
1116
       */
1117
      const_iterator
1118
      cend() const noexcept
1119
      { return this->_M_impl._M_finish; }
1120
 
1121
      /**
1122
       *  Returns a read-only (constant) reverse iterator that points
1123
       *  to the last element in the %deque.  Iteration is done in
1124
       *  reverse element order.
1125
       */
1126
      const_reverse_iterator
1127
      crbegin() const noexcept
1128
      { return const_reverse_iterator(this->_M_impl._M_finish); }
1129
 
1130
      /**
1131
       *  Returns a read-only (constant) reverse iterator that points
1132
       *  to one before the first element in the %deque.  Iteration is
1133
       *  done in reverse element order.
1134
       */
1135
      const_reverse_iterator
1136
      crend() const noexcept
1137
      { return const_reverse_iterator(this->_M_impl._M_start); }
1138
#endif
1139
 
1140
      // [23.2.1.2] capacity
1141
      /**  Returns the number of elements in the %deque.  */
1142
      size_type
1143
      size() const _GLIBCXX_NOEXCEPT
1144
      { return this->_M_impl._M_finish - this->_M_impl._M_start; }
1145
 
1146
      /**  Returns the size() of the largest possible %deque.  */
1147
      size_type
1148
      max_size() const _GLIBCXX_NOEXCEPT
1149
      { return _M_get_Tp_allocator().max_size(); }
1150
 
1151
#if __cplusplus >= 201103L
1152
      /**
1153
       *  @brief  Resizes the %deque to the specified number of elements.
1154
       *  @param  __new_size  Number of elements the %deque should contain.
1155
       *
1156
       *  This function will %resize the %deque to the specified
1157
       *  number of elements.  If the number is smaller than the
1158
       *  %deque's current size the %deque is truncated, otherwise
1159
       *  default constructed elements are appended.
1160
       */
1161
      void
1162
      resize(size_type __new_size)
1163
      {
1164
        const size_type __len = size();
1165
        if (__new_size > __len)
1166
          _M_default_append(__new_size - __len);
1167
        else if (__new_size < __len)
1168
          _M_erase_at_end(this->_M_impl._M_start
1169
                          + difference_type(__new_size));
1170
      }
1171
 
1172
      /**
1173
       *  @brief  Resizes the %deque to the specified number of elements.
1174
       *  @param  __new_size  Number of elements the %deque should contain.
1175
       *  @param  __x  Data with which new elements should be populated.
1176
       *
1177
       *  This function will %resize the %deque to the specified
1178
       *  number of elements.  If the number is smaller than the
1179
       *  %deque's current size the %deque is truncated, otherwise the
1180
       *  %deque is extended and new elements are populated with given
1181
       *  data.
1182
       */
1183
      void
1184
      resize(size_type __new_size, const value_type& __x)
1185
      {
1186
        const size_type __len = size();
1187
        if (__new_size > __len)
1188
          insert(this->_M_impl._M_finish, __new_size - __len, __x);
1189
        else if (__new_size < __len)
1190
          _M_erase_at_end(this->_M_impl._M_start
1191
                          + difference_type(__new_size));
1192
      }
1193
#else
1194
      /**
1195
       *  @brief  Resizes the %deque to the specified number of elements.
1196
       *  @param  __new_size  Number of elements the %deque should contain.
1197
       *  @param  __x  Data with which new elements should be populated.
1198
       *
1199
       *  This function will %resize the %deque to the specified
1200
       *  number of elements.  If the number is smaller than the
1201
       *  %deque's current size the %deque is truncated, otherwise the
1202
       *  %deque is extended and new elements are populated with given
1203
       *  data.
1204
       */
1205
      void
1206
      resize(size_type __new_size, value_type __x = value_type())
1207
      {
1208
        const size_type __len = size();
1209
        if (__new_size > __len)
1210
          insert(this->_M_impl._M_finish, __new_size - __len, __x);
1211
        else if (__new_size < __len)
1212
          _M_erase_at_end(this->_M_impl._M_start
1213
                          + difference_type(__new_size));
1214
      }
1215
#endif
1216
 
1217
#if __cplusplus >= 201103L
1218
      /**  A non-binding request to reduce memory use.  */
1219
      void
1220
      shrink_to_fit()
1221
      { _M_shrink_to_fit(); }
1222
#endif
1223
 
1224
      /**
1225
       *  Returns true if the %deque is empty.  (Thus begin() would
1226
       *  equal end().)
1227
       */
1228
      bool
1229
      empty() const _GLIBCXX_NOEXCEPT
1230
      { return this->_M_impl._M_finish == this->_M_impl._M_start; }
1231
 
1232
      // element access
1233
      /**
1234
       *  @brief Subscript access to the data contained in the %deque.
1235
       *  @param __n The index of the element for which data should be
1236
       *  accessed.
1237
       *  @return  Read/write reference to data.
1238
       *
1239
       *  This operator allows for easy, array-style, data access.
1240
       *  Note that data access with this operator is unchecked and
1241
       *  out_of_range lookups are not defined. (For checked lookups
1242
       *  see at().)
1243
       */
1244
      reference
1245
      operator[](size_type __n)
1246
      { return this->_M_impl._M_start[difference_type(__n)]; }
1247
 
1248
      /**
1249
       *  @brief Subscript access to the data contained in the %deque.
1250
       *  @param __n The index of the element for which data should be
1251
       *  accessed.
1252
       *  @return  Read-only (constant) reference to data.
1253
       *
1254
       *  This operator allows for easy, array-style, data access.
1255
       *  Note that data access with this operator is unchecked and
1256
       *  out_of_range lookups are not defined. (For checked lookups
1257
       *  see at().)
1258
       */
1259
      const_reference
1260
      operator[](size_type __n) const
1261
      { return this->_M_impl._M_start[difference_type(__n)]; }
1262
 
1263
    protected:
1264
      /// Safety check used only from at().
1265
      void
1266
      _M_range_check(size_type __n) const
1267
      {
1268
        if (__n >= this->size())
1269
          __throw_out_of_range(__N("deque::_M_range_check"));
1270
      }
1271
 
1272
    public:
1273
      /**
1274
       *  @brief  Provides access to the data contained in the %deque.
1275
       *  @param __n The index of the element for which data should be
1276
       *  accessed.
1277
       *  @return  Read/write reference to data.
1278
       *  @throw  std::out_of_range  If @a __n is an invalid index.
1279
       *
1280
       *  This function provides for safer data access.  The parameter
1281
       *  is first checked that it is in the range of the deque.  The
1282
       *  function throws out_of_range if the check fails.
1283
       */
1284
      reference
1285
      at(size_type __n)
1286
      {
1287
        _M_range_check(__n);
1288
        return (*this)[__n];
1289
      }
1290
 
1291
      /**
1292
       *  @brief  Provides access to the data contained in the %deque.
1293
       *  @param __n The index of the element for which data should be
1294
       *  accessed.
1295
       *  @return  Read-only (constant) reference to data.
1296
       *  @throw  std::out_of_range  If @a __n is an invalid index.
1297
       *
1298
       *  This function provides for safer data access.  The parameter is first
1299
       *  checked that it is in the range of the deque.  The function throws
1300
       *  out_of_range if the check fails.
1301
       */
1302
      const_reference
1303
      at(size_type __n) const
1304
      {
1305
        _M_range_check(__n);
1306
        return (*this)[__n];
1307
      }
1308
 
1309
      /**
1310
       *  Returns a read/write reference to the data at the first
1311
       *  element of the %deque.
1312
       */
1313
      reference
1314
      front()
1315
      { return *begin(); }
1316
 
1317
      /**
1318
       *  Returns a read-only (constant) reference to the data at the first
1319
       *  element of the %deque.
1320
       */
1321
      const_reference
1322
      front() const
1323
      { return *begin(); }
1324
 
1325
      /**
1326
       *  Returns a read/write reference to the data at the last element of the
1327
       *  %deque.
1328
       */
1329
      reference
1330
      back()
1331
      {
1332
        iterator __tmp = end();
1333
        --__tmp;
1334
        return *__tmp;
1335
      }
1336
 
1337
      /**
1338
       *  Returns a read-only (constant) reference to the data at the last
1339
       *  element of the %deque.
1340
       */
1341
      const_reference
1342
      back() const
1343
      {
1344
        const_iterator __tmp = end();
1345
        --__tmp;
1346
        return *__tmp;
1347
      }
1348
 
1349
      // [23.2.1.2] modifiers
1350
      /**
1351
       *  @brief  Add data to the front of the %deque.
1352
       *  @param  __x  Data to be added.
1353
       *
1354
       *  This is a typical stack operation.  The function creates an
1355
       *  element at the front of the %deque and assigns the given
1356
       *  data to it.  Due to the nature of a %deque this operation
1357
       *  can be done in constant time.
1358
       */
1359
      void
1360
      push_front(const value_type& __x)
1361
      {
1362
        if (this->_M_impl._M_start._M_cur != this->_M_impl._M_start._M_first)
1363
          {
1364
            this->_M_impl.construct(this->_M_impl._M_start._M_cur - 1, __x);
1365
            --this->_M_impl._M_start._M_cur;
1366
          }
1367
        else
1368
          _M_push_front_aux(__x);
1369
      }
1370
 
1371
#if __cplusplus >= 201103L
1372
      void
1373
      push_front(value_type&& __x)
1374
      { emplace_front(std::move(__x)); }
1375
 
1376
      template<typename... _Args>
1377
        void
1378
        emplace_front(_Args&&... __args);
1379
#endif
1380
 
1381
      /**
1382
       *  @brief  Add data to the end of the %deque.
1383
       *  @param  __x  Data to be added.
1384
       *
1385
       *  This is a typical stack operation.  The function creates an
1386
       *  element at the end of the %deque and assigns the given data
1387
       *  to it.  Due to the nature of a %deque this operation can be
1388
       *  done in constant time.
1389
       */
1390
      void
1391
      push_back(const value_type& __x)
1392
      {
1393
        if (this->_M_impl._M_finish._M_cur
1394
            != this->_M_impl._M_finish._M_last - 1)
1395
          {
1396
            this->_M_impl.construct(this->_M_impl._M_finish._M_cur, __x);
1397
            ++this->_M_impl._M_finish._M_cur;
1398
          }
1399
        else
1400
          _M_push_back_aux(__x);
1401
      }
1402
 
1403
#if __cplusplus >= 201103L
1404
      void
1405
      push_back(value_type&& __x)
1406
      { emplace_back(std::move(__x)); }
1407
 
1408
      template<typename... _Args>
1409
        void
1410
        emplace_back(_Args&&... __args);
1411
#endif
1412
 
1413
      /**
1414
       *  @brief  Removes first element.
1415
       *
1416
       *  This is a typical stack operation.  It shrinks the %deque by one.
1417
       *
1418
       *  Note that no data is returned, and if the first element's data is
1419
       *  needed, it should be retrieved before pop_front() is called.
1420
       */
1421
      void
1422
      pop_front()
1423
      {
1424
        if (this->_M_impl._M_start._M_cur
1425
            != this->_M_impl._M_start._M_last - 1)
1426
          {
1427
            this->_M_impl.destroy(this->_M_impl._M_start._M_cur);
1428
            ++this->_M_impl._M_start._M_cur;
1429
          }
1430
        else
1431
          _M_pop_front_aux();
1432
      }
1433
 
1434
      /**
1435
       *  @brief  Removes last element.
1436
       *
1437
       *  This is a typical stack operation.  It shrinks the %deque by one.
1438
       *
1439
       *  Note that no data is returned, and if the last element's data is
1440
       *  needed, it should be retrieved before pop_back() is called.
1441
       */
1442
      void
1443
      pop_back()
1444
      {
1445
        if (this->_M_impl._M_finish._M_cur
1446
            != this->_M_impl._M_finish._M_first)
1447
          {
1448
            --this->_M_impl._M_finish._M_cur;
1449
            this->_M_impl.destroy(this->_M_impl._M_finish._M_cur);
1450
          }
1451
        else
1452
          _M_pop_back_aux();
1453
      }
1454
 
1455
#if __cplusplus >= 201103L
1456
      /**
1457
       *  @brief  Inserts an object in %deque before specified iterator.
1458
       *  @param  __position  An iterator into the %deque.
1459
       *  @param  __args  Arguments.
1460
       *  @return  An iterator that points to the inserted data.
1461
       *
1462
       *  This function will insert an object of type T constructed
1463
       *  with T(std::forward<Args>(args)...) before the specified location.
1464
       */
1465
      template<typename... _Args>
1466
        iterator
1467
        emplace(iterator __position, _Args&&... __args);
1468
#endif
1469
 
1470
      /**
1471
       *  @brief  Inserts given value into %deque before specified iterator.
1472
       *  @param  __position  An iterator into the %deque.
1473
       *  @param  __x  Data to be inserted.
1474
       *  @return  An iterator that points to the inserted data.
1475
       *
1476
       *  This function will insert a copy of the given value before the
1477
       *  specified location.
1478
       */
1479
      iterator
1480
      insert(iterator __position, const value_type& __x);
1481
 
1482
#if __cplusplus >= 201103L
1483
      /**
1484
       *  @brief  Inserts given rvalue into %deque before specified iterator.
1485
       *  @param  __position  An iterator into the %deque.
1486
       *  @param  __x  Data to be inserted.
1487
       *  @return  An iterator that points to the inserted data.
1488
       *
1489
       *  This function will insert a copy of the given rvalue before the
1490
       *  specified location.
1491
       */
1492
      iterator
1493
      insert(iterator __position, value_type&& __x)
1494
      { return emplace(__position, std::move(__x)); }
1495
 
1496
      /**
1497
       *  @brief  Inserts an initializer list into the %deque.
1498
       *  @param  __p  An iterator into the %deque.
1499
       *  @param  __l  An initializer_list.
1500
       *
1501
       *  This function will insert copies of the data in the
1502
       *  initializer_list @a __l into the %deque before the location
1503
       *  specified by @a __p.  This is known as <em>list insert</em>.
1504
       */
1505
      void
1506
      insert(iterator __p, initializer_list<value_type> __l)
1507
      { this->insert(__p, __l.begin(), __l.end()); }
1508
#endif
1509
 
1510
      /**
1511
       *  @brief  Inserts a number of copies of given data into the %deque.
1512
       *  @param  __position  An iterator into the %deque.
1513
       *  @param  __n  Number of elements to be inserted.
1514
       *  @param  __x  Data to be inserted.
1515
       *
1516
       *  This function will insert a specified number of copies of the given
1517
       *  data before the location specified by @a __position.
1518
       */
1519
      void
1520
      insert(iterator __position, size_type __n, const value_type& __x)
1521
      { _M_fill_insert(__position, __n, __x); }
1522
 
1523
      /**
1524
       *  @brief  Inserts a range into the %deque.
1525
       *  @param  __position  An iterator into the %deque.
1526
       *  @param  __first  An input iterator.
1527
       *  @param  __last   An input iterator.
1528
       *
1529
       *  This function will insert copies of the data in the range
1530
       *  [__first,__last) into the %deque before the location specified
1531
       *  by @a __position.  This is known as <em>range insert</em>.
1532
       */
1533
#if __cplusplus >= 201103L
1534
      template<typename _InputIterator,
1535
               typename = std::_RequireInputIter<_InputIterator>>
1536
        void
1537
        insert(iterator __position, _InputIterator __first,
1538
               _InputIterator __last)
1539
        { _M_insert_dispatch(__position, __first, __last, __false_type()); }
1540
#else
1541
      template<typename _InputIterator>
1542
        void
1543
        insert(iterator __position, _InputIterator __first,
1544
               _InputIterator __last)
1545
        {
1546
          // Check whether it's an integral type.  If so, it's not an iterator.
1547
          typedef typename std::__is_integer<_InputIterator>::__type _Integral;
1548
          _M_insert_dispatch(__position, __first, __last, _Integral());
1549
        }
1550
#endif
1551
 
1552
      /**
1553
       *  @brief  Remove element at given position.
1554
       *  @param  __position  Iterator pointing to element to be erased.
1555
       *  @return  An iterator pointing to the next element (or end()).
1556
       *
1557
       *  This function will erase the element at the given position and thus
1558
       *  shorten the %deque by one.
1559
       *
1560
       *  The user is cautioned that
1561
       *  this function only erases the element, and that if the element is
1562
       *  itself a pointer, the pointed-to memory is not touched in any way.
1563
       *  Managing the pointer is the user's responsibility.
1564
       */
1565
      iterator
1566
      erase(iterator __position);
1567
 
1568
      /**
1569
       *  @brief  Remove a range of elements.
1570
       *  @param  __first  Iterator pointing to the first element to be erased.
1571
       *  @param  __last  Iterator pointing to one past the last element to be
1572
       *                erased.
1573
       *  @return  An iterator pointing to the element pointed to by @a last
1574
       *           prior to erasing (or end()).
1575
       *
1576
       *  This function will erase the elements in the range
1577
       *  [__first,__last) and shorten the %deque accordingly.
1578
       *
1579
       *  The user is cautioned that
1580
       *  this function only erases the elements, and that if the elements
1581
       *  themselves are pointers, the pointed-to memory is not touched in any
1582
       *  way.  Managing the pointer is the user's responsibility.
1583
       */
1584
      iterator
1585
      erase(iterator __first, iterator __last);
1586
 
1587
      /**
1588
       *  @brief  Swaps data with another %deque.
1589
       *  @param  __x  A %deque of the same element and allocator types.
1590
       *
1591
       *  This exchanges the elements between two deques in constant time.
1592
       *  (Four pointers, so it should be quite fast.)
1593
       *  Note that the global std::swap() function is specialized such that
1594
       *  std::swap(d1,d2) will feed to this function.
1595
       */
1596
      void
1597
      swap(deque& __x)
1598
      {
1599
        std::swap(this->_M_impl._M_start, __x._M_impl._M_start);
1600
        std::swap(this->_M_impl._M_finish, __x._M_impl._M_finish);
1601
        std::swap(this->_M_impl._M_map, __x._M_impl._M_map);
1602
        std::swap(this->_M_impl._M_map_size, __x._M_impl._M_map_size);
1603
 
1604
        // _GLIBCXX_RESOLVE_LIB_DEFECTS
1605
        // 431. Swapping containers with unequal allocators.
1606
        std::__alloc_swap<_Tp_alloc_type>::_S_do_it(_M_get_Tp_allocator(),
1607
                                                    __x._M_get_Tp_allocator());
1608
      }
1609
 
1610
      /**
1611
       *  Erases all the elements.  Note that this function only erases the
1612
       *  elements, and that if the elements themselves are pointers, the
1613
       *  pointed-to memory is not touched in any way.  Managing the pointer is
1614
       *  the user's responsibility.
1615
       */
1616
      void
1617
      clear() _GLIBCXX_NOEXCEPT
1618
      { _M_erase_at_end(begin()); }
1619
 
1620
    protected:
1621
      // Internal constructor functions follow.
1622
 
1623
      // called by the range constructor to implement [23.1.1]/9
1624
 
1625
      // _GLIBCXX_RESOLVE_LIB_DEFECTS
1626
      // 438. Ambiguity in the "do the right thing" clause
1627
      template<typename _Integer>
1628
        void
1629
        _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type)
1630
        {
1631
          _M_initialize_map(static_cast<size_type>(__n));
1632
          _M_fill_initialize(__x);
1633
        }
1634
 
1635
      // called by the range constructor to implement [23.1.1]/9
1636
      template<typename _InputIterator>
1637
        void
1638
        _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
1639
                               __false_type)
1640
        {
1641
          typedef typename std::iterator_traits<_InputIterator>::
1642
            iterator_category _IterCategory;
1643
          _M_range_initialize(__first, __last, _IterCategory());
1644
        }
1645
 
1646
      // called by the second initialize_dispatch above
1647
      //@{
1648
      /**
1649
       *  @brief Fills the deque with whatever is in [first,last).
1650
       *  @param  __first  An input iterator.
1651
       *  @param  __last  An input iterator.
1652
       *  @return   Nothing.
1653
       *
1654
       *  If the iterators are actually forward iterators (or better), then the
1655
       *  memory layout can be done all at once.  Else we move forward using
1656
       *  push_back on each value from the iterator.
1657
       */
1658
      template<typename _InputIterator>
1659
        void
1660
        _M_range_initialize(_InputIterator __first, _InputIterator __last,
1661
                            std::input_iterator_tag);
1662
 
1663
      // called by the second initialize_dispatch above
1664
      template<typename _ForwardIterator>
1665
        void
1666
        _M_range_initialize(_ForwardIterator __first, _ForwardIterator __last,
1667
                            std::forward_iterator_tag);
1668
      //@}
1669
 
1670
      /**
1671
       *  @brief Fills the %deque with copies of value.
1672
       *  @param  __value  Initial value.
1673
       *  @return   Nothing.
1674
       *  @pre _M_start and _M_finish have already been initialized,
1675
       *  but none of the %deque's elements have yet been constructed.
1676
       *
1677
       *  This function is called only when the user provides an explicit size
1678
       *  (with or without an explicit exemplar value).
1679
       */
1680
      void
1681
      _M_fill_initialize(const value_type& __value);
1682
 
1683
#if __cplusplus >= 201103L
1684
      // called by deque(n).
1685
      void
1686
      _M_default_initialize();
1687
#endif
1688
 
1689
      // Internal assign functions follow.  The *_aux functions do the actual
1690
      // assignment work for the range versions.
1691
 
1692
      // called by the range assign to implement [23.1.1]/9
1693
 
1694
      // _GLIBCXX_RESOLVE_LIB_DEFECTS
1695
      // 438. Ambiguity in the "do the right thing" clause
1696
      template<typename _Integer>
1697
        void
1698
        _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
1699
        { _M_fill_assign(__n, __val); }
1700
 
1701
      // called by the range assign to implement [23.1.1]/9
1702
      template<typename _InputIterator>
1703
        void
1704
        _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
1705
                           __false_type)
1706
        {
1707
          typedef typename std::iterator_traits<_InputIterator>::
1708
            iterator_category _IterCategory;
1709
          _M_assign_aux(__first, __last, _IterCategory());
1710
        }
1711
 
1712
      // called by the second assign_dispatch above
1713
      template<typename _InputIterator>
1714
        void
1715
        _M_assign_aux(_InputIterator __first, _InputIterator __last,
1716
                      std::input_iterator_tag);
1717
 
1718
      // called by the second assign_dispatch above
1719
      template<typename _ForwardIterator>
1720
        void
1721
        _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
1722
                      std::forward_iterator_tag)
1723
        {
1724
          const size_type __len = std::distance(__first, __last);
1725
          if (__len > size())
1726
            {
1727
              _ForwardIterator __mid = __first;
1728
              std::advance(__mid, size());
1729
              std::copy(__first, __mid, begin());
1730
              insert(end(), __mid, __last);
1731
            }
1732
          else
1733
            _M_erase_at_end(std::copy(__first, __last, begin()));
1734
        }
1735
 
1736
      // Called by assign(n,t), and the range assign when it turns out
1737
      // to be the same thing.
1738
      void
1739
      _M_fill_assign(size_type __n, const value_type& __val)
1740
      {
1741
        if (__n > size())
1742
          {
1743
            std::fill(begin(), end(), __val);
1744
            insert(end(), __n - size(), __val);
1745
          }
1746
        else
1747
          {
1748
            _M_erase_at_end(begin() + difference_type(__n));
1749
            std::fill(begin(), end(), __val);
1750
          }
1751
      }
1752
 
1753
      //@{
1754
      /// Helper functions for push_* and pop_*.
1755
#if __cplusplus < 201103L
1756
      void _M_push_back_aux(const value_type&);
1757
 
1758
      void _M_push_front_aux(const value_type&);
1759
#else
1760
      template<typename... _Args>
1761
        void _M_push_back_aux(_Args&&... __args);
1762
 
1763
      template<typename... _Args>
1764
        void _M_push_front_aux(_Args&&... __args);
1765
#endif
1766
 
1767
      void _M_pop_back_aux();
1768
 
1769
      void _M_pop_front_aux();
1770
      //@}
1771
 
1772
      // Internal insert functions follow.  The *_aux functions do the actual
1773
      // insertion work when all shortcuts fail.
1774
 
1775
      // called by the range insert to implement [23.1.1]/9
1776
 
1777
      // _GLIBCXX_RESOLVE_LIB_DEFECTS
1778
      // 438. Ambiguity in the "do the right thing" clause
1779
      template<typename _Integer>
1780
        void
1781
        _M_insert_dispatch(iterator __pos,
1782
                           _Integer __n, _Integer __x, __true_type)
1783
        { _M_fill_insert(__pos, __n, __x); }
1784
 
1785
      // called by the range insert to implement [23.1.1]/9
1786
      template<typename _InputIterator>
1787
        void
1788
        _M_insert_dispatch(iterator __pos,
1789
                           _InputIterator __first, _InputIterator __last,
1790
                           __false_type)
1791
        {
1792
          typedef typename std::iterator_traits<_InputIterator>::
1793
            iterator_category _IterCategory;
1794
          _M_range_insert_aux(__pos, __first, __last, _IterCategory());
1795
        }
1796
 
1797
      // called by the second insert_dispatch above
1798
      template<typename _InputIterator>
1799
        void
1800
        _M_range_insert_aux(iterator __pos, _InputIterator __first,
1801
                            _InputIterator __last, std::input_iterator_tag);
1802
 
1803
      // called by the second insert_dispatch above
1804
      template<typename _ForwardIterator>
1805
        void
1806
        _M_range_insert_aux(iterator __pos, _ForwardIterator __first,
1807
                            _ForwardIterator __last, std::forward_iterator_tag);
1808
 
1809
      // Called by insert(p,n,x), and the range insert when it turns out to be
1810
      // the same thing.  Can use fill functions in optimal situations,
1811
      // otherwise passes off to insert_aux(p,n,x).
1812
      void
1813
      _M_fill_insert(iterator __pos, size_type __n, const value_type& __x);
1814
 
1815
      // called by insert(p,x)
1816
#if __cplusplus < 201103L
1817
      iterator
1818
      _M_insert_aux(iterator __pos, const value_type& __x);
1819
#else
1820
      template<typename... _Args>
1821
        iterator
1822
        _M_insert_aux(iterator __pos, _Args&&... __args);
1823
#endif
1824
 
1825
      // called by insert(p,n,x) via fill_insert
1826
      void
1827
      _M_insert_aux(iterator __pos, size_type __n, const value_type& __x);
1828
 
1829
      // called by range_insert_aux for forward iterators
1830
      template<typename _ForwardIterator>
1831
        void
1832
        _M_insert_aux(iterator __pos,
1833
                      _ForwardIterator __first, _ForwardIterator __last,
1834
                      size_type __n);
1835
 
1836
 
1837
      // Internal erase functions follow.
1838
 
1839
      void
1840
      _M_destroy_data_aux(iterator __first, iterator __last);
1841
 
1842
      // Called by ~deque().
1843
      // NB: Doesn't deallocate the nodes.
1844
      template<typename _Alloc1>
1845
        void
1846
        _M_destroy_data(iterator __first, iterator __last, const _Alloc1&)
1847
        { _M_destroy_data_aux(__first, __last); }
1848
 
1849
      void
1850
      _M_destroy_data(iterator __first, iterator __last,
1851
                      const std::allocator<_Tp>&)
1852
      {
1853
        if (!__has_trivial_destructor(value_type))
1854
          _M_destroy_data_aux(__first, __last);
1855
      }
1856
 
1857
      // Called by erase(q1, q2).
1858
      void
1859
      _M_erase_at_begin(iterator __pos)
1860
      {
1861
        _M_destroy_data(begin(), __pos, _M_get_Tp_allocator());
1862
        _M_destroy_nodes(this->_M_impl._M_start._M_node, __pos._M_node);
1863
        this->_M_impl._M_start = __pos;
1864
      }
1865
 
1866
      // Called by erase(q1, q2), resize(), clear(), _M_assign_aux,
1867
      // _M_fill_assign, operator=.
1868
      void
1869
      _M_erase_at_end(iterator __pos)
1870
      {
1871
        _M_destroy_data(__pos, end(), _M_get_Tp_allocator());
1872
        _M_destroy_nodes(__pos._M_node + 1,
1873
                         this->_M_impl._M_finish._M_node + 1);
1874
        this->_M_impl._M_finish = __pos;
1875
      }
1876
 
1877
#if __cplusplus >= 201103L
1878
      // Called by resize(sz).
1879
      void
1880
      _M_default_append(size_type __n);
1881
 
1882
      bool
1883
      _M_shrink_to_fit();
1884
#endif
1885
 
1886
      //@{
1887
      /// Memory-handling helpers for the previous internal insert functions.
1888
      iterator
1889
      _M_reserve_elements_at_front(size_type __n)
1890
      {
1891
        const size_type __vacancies = this->_M_impl._M_start._M_cur
1892
                                      - this->_M_impl._M_start._M_first;
1893
        if (__n > __vacancies)
1894
          _M_new_elements_at_front(__n - __vacancies);
1895
        return this->_M_impl._M_start - difference_type(__n);
1896
      }
1897
 
1898
      iterator
1899
      _M_reserve_elements_at_back(size_type __n)
1900
      {
1901
        const size_type __vacancies = (this->_M_impl._M_finish._M_last
1902
                                       - this->_M_impl._M_finish._M_cur) - 1;
1903
        if (__n > __vacancies)
1904
          _M_new_elements_at_back(__n - __vacancies);
1905
        return this->_M_impl._M_finish + difference_type(__n);
1906
      }
1907
 
1908
      void
1909
      _M_new_elements_at_front(size_type __new_elements);
1910
 
1911
      void
1912
      _M_new_elements_at_back(size_type __new_elements);
1913
      //@}
1914
 
1915
 
1916
      //@{
1917
      /**
1918
       *  @brief Memory-handling helpers for the major %map.
1919
       *
1920
       *  Makes sure the _M_map has space for new nodes.  Does not
1921
       *  actually add the nodes.  Can invalidate _M_map pointers.
1922
       *  (And consequently, %deque iterators.)
1923
       */
1924
      void
1925
      _M_reserve_map_at_back(size_type __nodes_to_add = 1)
1926
      {
1927
        if (__nodes_to_add + 1 > this->_M_impl._M_map_size
1928
            - (this->_M_impl._M_finish._M_node - this->_M_impl._M_map))
1929
          _M_reallocate_map(__nodes_to_add, false);
1930
      }
1931
 
1932
      void
1933
      _M_reserve_map_at_front(size_type __nodes_to_add = 1)
1934
      {
1935
        if (__nodes_to_add > size_type(this->_M_impl._M_start._M_node
1936
                                       - this->_M_impl._M_map))
1937
          _M_reallocate_map(__nodes_to_add, true);
1938
      }
1939
 
1940
      void
1941
      _M_reallocate_map(size_type __nodes_to_add, bool __add_at_front);
1942
      //@}
1943
    };
1944
 
1945
 
1946
  /**
1947
   *  @brief  Deque equality comparison.
1948
   *  @param  __x  A %deque.
1949
   *  @param  __y  A %deque of the same type as @a __x.
1950
   *  @return  True iff the size and elements of the deques are equal.
1951
   *
1952
   *  This is an equivalence relation.  It is linear in the size of the
1953
   *  deques.  Deques are considered equivalent if their sizes are equal,
1954
   *  and if corresponding elements compare equal.
1955
  */
1956
  template<typename _Tp, typename _Alloc>
1957
    inline bool
1958
    operator==(const deque<_Tp, _Alloc>& __x,
1959
                         const deque<_Tp, _Alloc>& __y)
1960
    { return __x.size() == __y.size()
1961
             && std::equal(__x.begin(), __x.end(), __y.begin()); }
1962
 
1963
  /**
1964
   *  @brief  Deque ordering relation.
1965
   *  @param  __x  A %deque.
1966
   *  @param  __y  A %deque of the same type as @a __x.
1967
   *  @return  True iff @a x is lexicographically less than @a __y.
1968
   *
1969
   *  This is a total ordering relation.  It is linear in the size of the
1970
   *  deques.  The elements must be comparable with @c <.
1971
   *
1972
   *  See std::lexicographical_compare() for how the determination is made.
1973
  */
1974
  template<typename _Tp, typename _Alloc>
1975
    inline bool
1976
    operator<(const deque<_Tp, _Alloc>& __x,
1977
              const deque<_Tp, _Alloc>& __y)
1978
    { return std::lexicographical_compare(__x.begin(), __x.end(),
1979
                                          __y.begin(), __y.end()); }
1980
 
1981
  /// Based on operator==
1982
  template<typename _Tp, typename _Alloc>
1983
    inline bool
1984
    operator!=(const deque<_Tp, _Alloc>& __x,
1985
               const deque<_Tp, _Alloc>& __y)
1986
    { return !(__x == __y); }
1987
 
1988
  /// Based on operator<
1989
  template<typename _Tp, typename _Alloc>
1990
    inline bool
1991
    operator>(const deque<_Tp, _Alloc>& __x,
1992
              const deque<_Tp, _Alloc>& __y)
1993
    { return __y < __x; }
1994
 
1995
  /// Based on operator<
1996
  template<typename _Tp, typename _Alloc>
1997
    inline bool
1998
    operator<=(const deque<_Tp, _Alloc>& __x,
1999
               const deque<_Tp, _Alloc>& __y)
2000
    { return !(__y < __x); }
2001
 
2002
  /// Based on operator<
2003
  template<typename _Tp, typename _Alloc>
2004
    inline bool
2005
    operator>=(const deque<_Tp, _Alloc>& __x,
2006
               const deque<_Tp, _Alloc>& __y)
2007
    { return !(__x < __y); }
2008
 
2009
  /// See std::deque::swap().
2010
  template<typename _Tp, typename _Alloc>
2011
    inline void
2012
    swap(deque<_Tp,_Alloc>& __x, deque<_Tp,_Alloc>& __y)
2013
    { __x.swap(__y); }
2014
 
2015
#undef _GLIBCXX_DEQUE_BUF_SIZE
2016
 
2017
_GLIBCXX_END_NAMESPACE_CONTAINER
2018
} // namespace std
2019
 
2020
#endif /* _STL_DEQUE_H */

powered by: WebSVN 2.1.0

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