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