stl_deque.h

Go to the documentation of this file.
00001 // Deque implementation -*- C++ -*-
00002 
00003 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
00004 // Free Software Foundation, Inc.
00005 //
00006 // This file is part of the GNU ISO C++ Library.  This library is free
00007 // software; you can redistribute it and/or modify it under the
00008 // terms of the GNU General Public License as published by the
00009 // Free Software Foundation; either version 3, or (at your option)
00010 // any later version.
00011 
00012 // This library is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License for more details.
00016 
00017 // Under Section 7 of GPL version 3, you are granted additional
00018 // permissions described in the GCC Runtime Library Exception, version
00019 // 3.1, as published by the Free Software Foundation.
00020 
00021 // You should have received a copy of the GNU General Public License and
00022 // a copy of the GCC Runtime Library Exception along with this program;
00023 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00024 // <http://www.gnu.org/licenses/>.
00025 
00026 /*
00027  *
00028  * Copyright (c) 1994
00029  * Hewlett-Packard Company
00030  *
00031  * Permission to use, copy, modify, distribute and sell this software
00032  * and its documentation for any purpose is hereby granted without fee,
00033  * provided that the above copyright notice appear in all copies and
00034  * that both that copyright notice and this permission notice appear
00035  * in supporting documentation.  Hewlett-Packard Company makes no
00036  * representations about the suitability of this software for any
00037  * purpose.  It is provided "as is" without express or implied warranty.
00038  *
00039  *
00040  * Copyright (c) 1997
00041  * Silicon Graphics Computer Systems, Inc.
00042  *
00043  * Permission to use, copy, modify, distribute and sell this software
00044  * and its documentation for any purpose is hereby granted without fee,
00045  * provided that the above copyright notice appear in all copies and
00046  * that both that copyright notice and this permission notice appear
00047  * in supporting documentation.  Silicon Graphics makes no
00048  * representations about the suitability of this software for any
00049  * purpose.  It is provided "as is" without express or implied warranty.
00050  */
00051 
00052 /** @file stl_deque.h
00053  *  This is an internal header file, included by other library headers.
00054  *  You should not attempt to use it directly.
00055  */
00056 
00057 #ifndef _STL_DEQUE_H
00058 #define _STL_DEQUE_H 1
00059 
00060 #include <bits/concept_check.h>
00061 #include <bits/stl_iterator_base_types.h>
00062 #include <bits/stl_iterator_base_funcs.h>
00063 #include <initializer_list>
00064 
00065 _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
00066 
00067   /**
00068    *  @brief This function controls the size of memory nodes.
00069    *  @param  size  The size of an element.
00070    *  @return   The number (not byte size) of elements per node.
00071    *
00072    *  This function started off as a compiler kludge from SGI, but
00073    *  seems to be a useful wrapper around a repeated constant
00074    *  expression.  The @b 512 is tunable (and no other code needs to
00075    *  change), but no investigation has been done since inheriting the
00076    *  SGI code.  Touch _GLIBCXX_DEQUE_BUF_SIZE only if you know what
00077    *  you are doing, however: changing it breaks the binary
00078    *  compatibility!!
00079   */
00080 
00081 #ifndef _GLIBCXX_DEQUE_BUF_SIZE
00082 #define _GLIBCXX_DEQUE_BUF_SIZE 512
00083 #endif
00084 
00085   inline size_t
00086   __deque_buf_size(size_t __size)
00087   { return (__size < _GLIBCXX_DEQUE_BUF_SIZE
00088         ? size_t(_GLIBCXX_DEQUE_BUF_SIZE / __size) : size_t(1)); }
00089 
00090 
00091   /**
00092    *  @brief A deque::iterator.
00093    *
00094    *  Quite a bit of intelligence here.  Much of the functionality of
00095    *  deque is actually passed off to this class.  A deque holds two
00096    *  of these internally, marking its valid range.  Access to
00097    *  elements is done as offsets of either of those two, relying on
00098    *  operator overloading in this class.
00099    *
00100    *  All the functions are op overloads except for _M_set_node.
00101   */
00102   template<typename _Tp, typename _Ref, typename _Ptr>
00103     struct _Deque_iterator
00104     {
00105       typedef _Deque_iterator<_Tp, _Tp&, _Tp*>             iterator;
00106       typedef _Deque_iterator<_Tp, const _Tp&, const _Tp*> const_iterator;
00107 
00108       static size_t _S_buffer_size()
00109       { return __deque_buf_size(sizeof(_Tp)); }
00110 
00111       typedef std::random_access_iterator_tag iterator_category;
00112       typedef _Tp                             value_type;
00113       typedef _Ptr                            pointer;
00114       typedef _Ref                            reference;
00115       typedef size_t                          size_type;
00116       typedef ptrdiff_t                       difference_type;
00117       typedef _Tp**                           _Map_pointer;
00118       typedef _Deque_iterator                 _Self;
00119 
00120       _Tp* _M_cur;
00121       _Tp* _M_first;
00122       _Tp* _M_last;
00123       _Map_pointer _M_node;
00124 
00125       _Deque_iterator(_Tp* __x, _Map_pointer __y)
00126       : _M_cur(__x), _M_first(*__y),
00127         _M_last(*__y + _S_buffer_size()), _M_node(__y) { }
00128 
00129       _Deque_iterator()
00130       : _M_cur(0), _M_first(0), _M_last(0), _M_node(0) { }
00131 
00132       _Deque_iterator(const iterator& __x)
00133       : _M_cur(__x._M_cur), _M_first(__x._M_first),
00134         _M_last(__x._M_last), _M_node(__x._M_node) { }
00135 
00136       reference
00137       operator*() const
00138       { return *_M_cur; }
00139 
00140       pointer
00141       operator->() const
00142       { return _M_cur; }
00143 
00144       _Self&
00145       operator++()
00146       {
00147     ++_M_cur;
00148     if (_M_cur == _M_last)
00149       {
00150         _M_set_node(_M_node + 1);
00151         _M_cur = _M_first;
00152       }
00153     return *this;
00154       }
00155 
00156       _Self
00157       operator++(int)
00158       {
00159     _Self __tmp = *this;
00160     ++*this;
00161     return __tmp;
00162       }
00163 
00164       _Self&
00165       operator--()
00166       {
00167     if (_M_cur == _M_first)
00168       {
00169         _M_set_node(_M_node - 1);
00170         _M_cur = _M_last;
00171       }
00172     --_M_cur;
00173     return *this;
00174       }
00175 
00176       _Self
00177       operator--(int)
00178       {
00179     _Self __tmp = *this;
00180     --*this;
00181     return __tmp;
00182       }
00183 
00184       _Self&
00185       operator+=(difference_type __n)
00186       {
00187     const difference_type __offset = __n + (_M_cur - _M_first);
00188     if (__offset >= 0 && __offset < difference_type(_S_buffer_size()))
00189       _M_cur += __n;
00190     else
00191       {
00192         const difference_type __node_offset =
00193           __offset > 0 ? __offset / difference_type(_S_buffer_size())
00194                        : -difference_type((-__offset - 1)
00195                           / _S_buffer_size()) - 1;
00196         _M_set_node(_M_node + __node_offset);
00197         _M_cur = _M_first + (__offset - __node_offset
00198                  * difference_type(_S_buffer_size()));
00199       }
00200     return *this;
00201       }
00202 
00203       _Self
00204       operator+(difference_type __n) const
00205       {
00206     _Self __tmp = *this;
00207     return __tmp += __n;
00208       }
00209 
00210       _Self&
00211       operator-=(difference_type __n)
00212       { return *this += -__n; }
00213 
00214       _Self
00215       operator-(difference_type __n) const
00216       {
00217     _Self __tmp = *this;
00218     return __tmp -= __n;
00219       }
00220 
00221       reference
00222       operator[](difference_type __n) const
00223       { return *(*this + __n); }
00224 
00225       /** 
00226        *  Prepares to traverse new_node.  Sets everything except
00227        *  _M_cur, which should therefore be set by the caller
00228        *  immediately afterwards, based on _M_first and _M_last.
00229        */
00230       void
00231       _M_set_node(_Map_pointer __new_node)
00232       {
00233     _M_node = __new_node;
00234     _M_first = *__new_node;
00235     _M_last = _M_first + difference_type(_S_buffer_size());
00236       }
00237     };
00238 
00239   // Note: we also provide overloads whose operands are of the same type in
00240   // order to avoid ambiguous overload resolution when std::rel_ops operators
00241   // are in scope (for additional details, see libstdc++/3628)
00242   template<typename _Tp, typename _Ref, typename _Ptr>
00243     inline bool
00244     operator==(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
00245            const _Deque_iterator<_Tp, _Ref, _Ptr>& __y)
00246     { return __x._M_cur == __y._M_cur; }
00247 
00248   template<typename _Tp, typename _RefL, typename _PtrL,
00249        typename _RefR, typename _PtrR>
00250     inline bool
00251     operator==(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
00252            const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
00253     { return __x._M_cur == __y._M_cur; }
00254 
00255   template<typename _Tp, typename _Ref, typename _Ptr>
00256     inline bool
00257     operator!=(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
00258            const _Deque_iterator<_Tp, _Ref, _Ptr>& __y)
00259     { return !(__x == __y); }
00260 
00261   template<typename _Tp, typename _RefL, typename _PtrL,
00262        typename _RefR, typename _PtrR>
00263     inline bool
00264     operator!=(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
00265            const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
00266     { return !(__x == __y); }
00267 
00268   template<typename _Tp, typename _Ref, typename _Ptr>
00269     inline bool
00270     operator<(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
00271           const _Deque_iterator<_Tp, _Ref, _Ptr>& __y)
00272     { return (__x._M_node == __y._M_node) ? (__x._M_cur < __y._M_cur)
00273                                           : (__x._M_node < __y._M_node); }
00274 
00275   template<typename _Tp, typename _RefL, typename _PtrL,
00276        typename _RefR, typename _PtrR>
00277     inline bool
00278     operator<(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
00279           const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
00280     { return (__x._M_node == __y._M_node) ? (__x._M_cur < __y._M_cur)
00281                                       : (__x._M_node < __y._M_node); }
00282 
00283   template<typename _Tp, typename _Ref, typename _Ptr>
00284     inline bool
00285     operator>(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
00286           const _Deque_iterator<_Tp, _Ref, _Ptr>& __y)
00287     { return __y < __x; }
00288 
00289   template<typename _Tp, typename _RefL, typename _PtrL,
00290        typename _RefR, typename _PtrR>
00291     inline bool
00292     operator>(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
00293           const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
00294     { return __y < __x; }
00295 
00296   template<typename _Tp, typename _Ref, typename _Ptr>
00297     inline bool
00298     operator<=(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
00299            const _Deque_iterator<_Tp, _Ref, _Ptr>& __y)
00300     { return !(__y < __x); }
00301 
00302   template<typename _Tp, typename _RefL, typename _PtrL,
00303        typename _RefR, typename _PtrR>
00304     inline bool
00305     operator<=(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
00306            const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
00307     { return !(__y < __x); }
00308 
00309   template<typename _Tp, typename _Ref, typename _Ptr>
00310     inline bool
00311     operator>=(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
00312            const _Deque_iterator<_Tp, _Ref, _Ptr>& __y)
00313     { return !(__x < __y); }
00314 
00315   template<typename _Tp, typename _RefL, typename _PtrL,
00316        typename _RefR, typename _PtrR>
00317     inline bool
00318     operator>=(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
00319            const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
00320     { return !(__x < __y); }
00321 
00322   // _GLIBCXX_RESOLVE_LIB_DEFECTS
00323   // According to the resolution of DR179 not only the various comparison
00324   // operators but also operator- must accept mixed iterator/const_iterator
00325   // parameters.
00326   template<typename _Tp, typename _Ref, typename _Ptr>
00327     inline typename _Deque_iterator<_Tp, _Ref, _Ptr>::difference_type
00328     operator-(const _Deque_iterator<_Tp, _Ref, _Ptr>& __x,
00329           const _Deque_iterator<_Tp, _Ref, _Ptr>& __y)
00330     {
00331       return typename _Deque_iterator<_Tp, _Ref, _Ptr>::difference_type
00332     (_Deque_iterator<_Tp, _Ref, _Ptr>::_S_buffer_size())
00333     * (__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first)
00334     + (__y._M_last - __y._M_cur);
00335     }
00336 
00337   template<typename _Tp, typename _RefL, typename _PtrL,
00338        typename _RefR, typename _PtrR>
00339     inline typename _Deque_iterator<_Tp, _RefL, _PtrL>::difference_type
00340     operator-(const _Deque_iterator<_Tp, _RefL, _PtrL>& __x,
00341           const _Deque_iterator<_Tp, _RefR, _PtrR>& __y)
00342     {
00343       return typename _Deque_iterator<_Tp, _RefL, _PtrL>::difference_type
00344     (_Deque_iterator<_Tp, _RefL, _PtrL>::_S_buffer_size())
00345     * (__x._M_node - __y._M_node - 1) + (__x._M_cur - __x._M_first)
00346     + (__y._M_last - __y._M_cur);
00347     }
00348 
00349   template<typename _Tp, typename _Ref, typename _Ptr>
00350     inline _Deque_iterator<_Tp, _Ref, _Ptr>
00351     operator+(ptrdiff_t __n, const _Deque_iterator<_Tp, _Ref, _Ptr>& __x)
00352     { return __x + __n; }
00353 
00354   template<typename _Tp>
00355     void
00356     fill(const _Deque_iterator<_Tp, _Tp&, _Tp*>&,
00357      const _Deque_iterator<_Tp, _Tp&, _Tp*>&, const _Tp&);
00358 
00359   template<typename _Tp>
00360     _Deque_iterator<_Tp, _Tp&, _Tp*>
00361     copy(_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
00362      _Deque_iterator<_Tp, const _Tp&, const _Tp*>,
00363      _Deque_iterator<_Tp, _Tp&, _Tp*>);
00364 
00365   template<typename _Tp>
00366     inline _Deque_iterator<_Tp, _Tp&, _Tp*>
00367     copy(_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
00368      _Deque_iterator<_Tp, _Tp&, _Tp*> __last,
00369      _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
00370     { return std::copy(_Deque_iterator<_Tp, const _Tp&, const _Tp*>(__first),
00371                _Deque_iterator<_Tp, const _Tp&, const _Tp*>(__last),
00372                __result); }
00373 
00374   template<typename _Tp>
00375     _Deque_iterator<_Tp, _Tp&, _Tp*>
00376     copy_backward(_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
00377           _Deque_iterator<_Tp, const _Tp&, const _Tp*>,
00378           _Deque_iterator<_Tp, _Tp&, _Tp*>);
00379 
00380   template<typename _Tp>
00381     inline _Deque_iterator<_Tp, _Tp&, _Tp*>
00382     copy_backward(_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
00383           _Deque_iterator<_Tp, _Tp&, _Tp*> __last,
00384           _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
00385     { return std::copy_backward(_Deque_iterator<_Tp,
00386                 const _Tp&, const _Tp*>(__first),
00387                 _Deque_iterator<_Tp,
00388                 const _Tp&, const _Tp*>(__last),
00389                 __result); }
00390 
00391 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00392   template<typename _Tp>
00393     _Deque_iterator<_Tp, _Tp&, _Tp*>
00394     move(_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
00395      _Deque_iterator<_Tp, const _Tp&, const _Tp*>,
00396      _Deque_iterator<_Tp, _Tp&, _Tp*>);
00397 
00398   template<typename _Tp>
00399     inline _Deque_iterator<_Tp, _Tp&, _Tp*>
00400     move(_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
00401      _Deque_iterator<_Tp, _Tp&, _Tp*> __last,
00402      _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
00403     { return std::move(_Deque_iterator<_Tp, const _Tp&, const _Tp*>(__first),
00404                _Deque_iterator<_Tp, const _Tp&, const _Tp*>(__last),
00405                __result); }
00406 
00407   template<typename _Tp>
00408     _Deque_iterator<_Tp, _Tp&, _Tp*>
00409     move_backward(_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
00410           _Deque_iterator<_Tp, const _Tp&, const _Tp*>,
00411           _Deque_iterator<_Tp, _Tp&, _Tp*>);
00412 
00413   template<typename _Tp>
00414     inline _Deque_iterator<_Tp, _Tp&, _Tp*>
00415     move_backward(_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
00416           _Deque_iterator<_Tp, _Tp&, _Tp*> __last,
00417           _Deque_iterator<_Tp, _Tp&, _Tp*> __result)
00418     { return std::move_backward(_Deque_iterator<_Tp,
00419                 const _Tp&, const _Tp*>(__first),
00420                 _Deque_iterator<_Tp,
00421                 const _Tp&, const _Tp*>(__last),
00422                 __result); }
00423 #endif
00424 
00425   /**
00426    *  Deque base class.  This class provides the unified face for %deque's
00427    *  allocation.  This class's constructor and destructor allocate and
00428    *  deallocate (but do not initialize) storage.  This makes %exception
00429    *  safety easier.
00430    *
00431    *  Nothing in this class ever constructs or destroys an actual Tp element.
00432    *  (Deque handles that itself.)  Only/All memory management is performed
00433    *  here.
00434   */
00435   template<typename _Tp, typename _Alloc>
00436     class _Deque_base
00437     {
00438     public:
00439       typedef _Alloc                  allocator_type;
00440 
00441       allocator_type
00442       get_allocator() const
00443       { return allocator_type(_M_get_Tp_allocator()); }
00444 
00445       typedef _Deque_iterator<_Tp, _Tp&, _Tp*>             iterator;
00446       typedef _Deque_iterator<_Tp, const _Tp&, const _Tp*> const_iterator;
00447 
00448       _Deque_base()
00449       : _M_impl()
00450       { _M_initialize_map(0); }
00451 
00452       _Deque_base(size_t __num_elements)
00453       : _M_impl()
00454       { _M_initialize_map(__num_elements); }
00455 
00456       _Deque_base(const allocator_type& __a, size_t __num_elements)
00457       : _M_impl(__a)
00458       { _M_initialize_map(__num_elements); }
00459 
00460       _Deque_base(const allocator_type& __a)
00461       : _M_impl(__a)
00462       { }
00463 
00464 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00465       _Deque_base(_Deque_base&& __x)
00466       : _M_impl(__x._M_get_Tp_allocator())
00467       {
00468     _M_initialize_map(0);
00469     if (__x._M_impl._M_map)
00470       {
00471         std::swap(this->_M_impl._M_start, __x._M_impl._M_start);
00472         std::swap(this->_M_impl._M_finish, __x._M_impl._M_finish);
00473         std::swap(this->_M_impl._M_map, __x._M_impl._M_map);
00474         std::swap(this->_M_impl._M_map_size, __x._M_impl._M_map_size);
00475       }
00476       }
00477 #endif
00478 
00479       ~_Deque_base();
00480 
00481     protected:
00482       //This struct encapsulates the implementation of the std::deque
00483       //standard container and at the same time makes use of the EBO
00484       //for empty allocators.
00485       typedef typename _Alloc::template rebind<_Tp*>::other _Map_alloc_type;
00486 
00487       typedef typename _Alloc::template rebind<_Tp>::other  _Tp_alloc_type;
00488 
00489       struct _Deque_impl
00490       : public _Tp_alloc_type
00491       {
00492     _Tp** _M_map;
00493     size_t _M_map_size;
00494     iterator _M_start;
00495     iterator _M_finish;
00496 
00497     _Deque_impl()
00498     : _Tp_alloc_type(), _M_map(0), _M_map_size(0),
00499       _M_start(), _M_finish()
00500     { }
00501 
00502     _Deque_impl(const _Tp_alloc_type& __a)
00503     : _Tp_alloc_type(__a), _M_map(0), _M_map_size(0),
00504       _M_start(), _M_finish()
00505     { }
00506       };
00507 
00508       _Tp_alloc_type&
00509       _M_get_Tp_allocator()
00510       { return *static_cast<_Tp_alloc_type*>(&this->_M_impl); }
00511 
00512       const _Tp_alloc_type&
00513       _M_get_Tp_allocator() const
00514       { return *static_cast<const _Tp_alloc_type*>(&this->_M_impl); }
00515 
00516       _Map_alloc_type
00517       _M_get_map_allocator() const
00518       { return _Map_alloc_type(_M_get_Tp_allocator()); }
00519 
00520       _Tp*
00521       _M_allocate_node()
00522       { 
00523     return _M_impl._Tp_alloc_type::allocate(__deque_buf_size(sizeof(_Tp)));
00524       }
00525 
00526       void
00527       _M_deallocate_node(_Tp* __p)
00528       {
00529     _M_impl._Tp_alloc_type::deallocate(__p, __deque_buf_size(sizeof(_Tp)));
00530       }
00531 
00532       _Tp**
00533       _M_allocate_map(size_t __n)
00534       { return _M_get_map_allocator().allocate(__n); }
00535 
00536       void
00537       _M_deallocate_map(_Tp** __p, size_t __n)
00538       { _M_get_map_allocator().deallocate(__p, __n); }
00539 
00540     protected:
00541       void _M_initialize_map(size_t);
00542       void _M_create_nodes(_Tp** __nstart, _Tp** __nfinish);
00543       void _M_destroy_nodes(_Tp** __nstart, _Tp** __nfinish);
00544       enum { _S_initial_map_size = 8 };
00545 
00546       _Deque_impl _M_impl;
00547     };
00548 
00549   template<typename _Tp, typename _Alloc>
00550     _Deque_base<_Tp, _Alloc>::
00551     ~_Deque_base()
00552     {
00553       if (this->_M_impl._M_map)
00554     {
00555       _M_destroy_nodes(this->_M_impl._M_start._M_node,
00556                this->_M_impl._M_finish._M_node + 1);
00557       _M_deallocate_map(this->_M_impl._M_map, this->_M_impl._M_map_size);
00558     }
00559     }
00560 
00561   /**
00562    *  @brief Layout storage.
00563    *  @param  num_elements  The count of T's for which to allocate space
00564    *                        at first.
00565    *  @return   Nothing.
00566    *
00567    *  The initial underlying memory layout is a bit complicated...
00568   */
00569   template<typename _Tp, typename _Alloc>
00570     void
00571     _Deque_base<_Tp, _Alloc>::
00572     _M_initialize_map(size_t __num_elements)
00573     {
00574       const size_t __num_nodes = (__num_elements/ __deque_buf_size(sizeof(_Tp))
00575                   + 1);
00576 
00577       this->_M_impl._M_map_size = std::max((size_t) _S_initial_map_size,
00578                        size_t(__num_nodes + 2));
00579       this->_M_impl._M_map = _M_allocate_map(this->_M_impl._M_map_size);
00580 
00581       // For "small" maps (needing less than _M_map_size nodes), allocation
00582       // starts in the middle elements and grows outwards.  So nstart may be
00583       // the beginning of _M_map, but for small maps it may be as far in as
00584       // _M_map+3.
00585 
00586       _Tp** __nstart = (this->_M_impl._M_map
00587             + (this->_M_impl._M_map_size - __num_nodes) / 2);
00588       _Tp** __nfinish = __nstart + __num_nodes;
00589 
00590       __try
00591     { _M_create_nodes(__nstart, __nfinish); }
00592       __catch(...)
00593     {
00594       _M_deallocate_map(this->_M_impl._M_map, this->_M_impl._M_map_size);
00595       this->_M_impl._M_map = 0;
00596       this->_M_impl._M_map_size = 0;
00597       __throw_exception_again;
00598     }
00599 
00600       this->_M_impl._M_start._M_set_node(__nstart);
00601       this->_M_impl._M_finish._M_set_node(__nfinish - 1);
00602       this->_M_impl._M_start._M_cur = _M_impl._M_start._M_first;
00603       this->_M_impl._M_finish._M_cur = (this->_M_impl._M_finish._M_first
00604                     + __num_elements
00605                     % __deque_buf_size(sizeof(_Tp)));
00606     }
00607 
00608   template<typename _Tp, typename _Alloc>
00609     void
00610     _Deque_base<_Tp, _Alloc>::
00611     _M_create_nodes(_Tp** __nstart, _Tp** __nfinish)
00612     {
00613       _Tp** __cur;
00614       __try
00615     {
00616       for (__cur = __nstart; __cur < __nfinish; ++__cur)
00617         *__cur = this->_M_allocate_node();
00618     }
00619       __catch(...)
00620     {
00621       _M_destroy_nodes(__nstart, __cur);
00622       __throw_exception_again;
00623     }
00624     }
00625 
00626   template<typename _Tp, typename _Alloc>
00627     void
00628     _Deque_base<_Tp, _Alloc>::
00629     _M_destroy_nodes(_Tp** __nstart, _Tp** __nfinish)
00630     {
00631       for (_Tp** __n = __nstart; __n < __nfinish; ++__n)
00632     _M_deallocate_node(*__n);
00633     }
00634 
00635   /**
00636    *  @brief  A standard container using fixed-size memory allocation and
00637    *  constant-time manipulation of elements at either end.
00638    *
00639    *  @ingroup sequences
00640    *
00641    *  Meets the requirements of a <a href="tables.html#65">container</a>, a
00642    *  <a href="tables.html#66">reversible container</a>, and a
00643    *  <a href="tables.html#67">sequence</a>, including the
00644    *  <a href="tables.html#68">optional sequence requirements</a>.
00645    *
00646    *  In previous HP/SGI versions of deque, there was an extra template
00647    *  parameter so users could control the node size.  This extension turned
00648    *  out to violate the C++ standard (it can be detected using template
00649    *  template parameters), and it was removed.
00650    *
00651    *  Here's how a deque<Tp> manages memory.  Each deque has 4 members:
00652    *
00653    *  - Tp**        _M_map
00654    *  - size_t      _M_map_size
00655    *  - iterator    _M_start, _M_finish
00656    *
00657    *  map_size is at least 8.  %map is an array of map_size
00658    *  pointers-to-@anodes.  (The name %map has nothing to do with the
00659    *  std::map class, and @b nodes should not be confused with
00660    *  std::list's usage of @a node.)
00661    *
00662    *  A @a node has no specific type name as such, but it is referred
00663    *  to as @a node in this file.  It is a simple array-of-Tp.  If Tp
00664    *  is very large, there will be one Tp element per node (i.e., an
00665    *  @a array of one).  For non-huge Tp's, node size is inversely
00666    *  related to Tp size: the larger the Tp, the fewer Tp's will fit
00667    *  in a node.  The goal here is to keep the total size of a node
00668    *  relatively small and constant over different Tp's, to improve
00669    *  allocator efficiency.
00670    *
00671    *  Not every pointer in the %map array will point to a node.  If
00672    *  the initial number of elements in the deque is small, the
00673    *  /middle/ %map pointers will be valid, and the ones at the edges
00674    *  will be unused.  This same situation will arise as the %map
00675    *  grows: available %map pointers, if any, will be on the ends.  As
00676    *  new nodes are created, only a subset of the %map's pointers need
00677    *  to be copied @a outward.
00678    *
00679    *  Class invariants:
00680    * - For any nonsingular iterator i:
00681    *    - i.node points to a member of the %map array.  (Yes, you read that
00682    *      correctly:  i.node does not actually point to a node.)  The member of
00683    *      the %map array is what actually points to the node.
00684    *    - i.first == *(i.node)    (This points to the node (first Tp element).)
00685    *    - i.last  == i.first + node_size
00686    *    - i.cur is a pointer in the range [i.first, i.last).  NOTE:
00687    *      the implication of this is that i.cur is always a dereferenceable
00688    *      pointer, even if i is a past-the-end iterator.
00689    * - Start and Finish are always nonsingular iterators.  NOTE: this
00690    * means that an empty deque must have one node, a deque with <N
00691    * elements (where N is the node buffer size) must have one node, a
00692    * deque with N through (2N-1) elements must have two nodes, etc.
00693    * - For every node other than start.node and finish.node, every
00694    * element in the node is an initialized object.  If start.node ==
00695    * finish.node, then [start.cur, finish.cur) are initialized
00696    * objects, and the elements outside that range are uninitialized
00697    * storage.  Otherwise, [start.cur, start.last) and [finish.first,
00698    * finish.cur) are initialized objects, and [start.first, start.cur)
00699    * and [finish.cur, finish.last) are uninitialized storage.
00700    * - [%map, %map + map_size) is a valid, non-empty range.
00701    * - [start.node, finish.node] is a valid range contained within
00702    *   [%map, %map + map_size).
00703    * - A pointer in the range [%map, %map + map_size) points to an allocated
00704    *   node if and only if the pointer is in the range
00705    *   [start.node, finish.node].
00706    *
00707    *  Here's the magic:  nothing in deque is @b aware of the discontiguous
00708    *  storage!
00709    *
00710    *  The memory setup and layout occurs in the parent, _Base, and the iterator
00711    *  class is entirely responsible for @a leaping from one node to the next.
00712    *  All the implementation routines for deque itself work only through the
00713    *  start and finish iterators.  This keeps the routines simple and sane,
00714    *  and we can use other standard algorithms as well.
00715   */
00716   template<typename _Tp, typename _Alloc = std::allocator<_Tp> >
00717     class deque : protected _Deque_base<_Tp, _Alloc>
00718     {
00719       // concept requirements
00720       typedef typename _Alloc::value_type        _Alloc_value_type;
00721       __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
00722       __glibcxx_class_requires2(_Tp, _Alloc_value_type, _SameTypeConcept)
00723 
00724       typedef _Deque_base<_Tp, _Alloc>           _Base;
00725       typedef typename _Base::_Tp_alloc_type     _Tp_alloc_type;
00726 
00727     public:
00728       typedef _Tp                                        value_type;
00729       typedef typename _Tp_alloc_type::pointer           pointer;
00730       typedef typename _Tp_alloc_type::const_pointer     const_pointer;
00731       typedef typename _Tp_alloc_type::reference         reference;
00732       typedef typename _Tp_alloc_type::const_reference   const_reference;
00733       typedef typename _Base::iterator                   iterator;
00734       typedef typename _Base::const_iterator             const_iterator;
00735       typedef std::reverse_iterator<const_iterator>      const_reverse_iterator;
00736       typedef std::reverse_iterator<iterator>            reverse_iterator;
00737       typedef size_t                             size_type;
00738       typedef ptrdiff_t                          difference_type;
00739       typedef _Alloc                             allocator_type;
00740 
00741     protected:
00742       typedef pointer*                           _Map_pointer;
00743 
00744       static size_t _S_buffer_size()
00745       { return __deque_buf_size(sizeof(_Tp)); }
00746 
00747       // Functions controlling memory layout, and nothing else.
00748       using _Base::_M_initialize_map;
00749       using _Base::_M_create_nodes;
00750       using _Base::_M_destroy_nodes;
00751       using _Base::_M_allocate_node;
00752       using _Base::_M_deallocate_node;
00753       using _Base::_M_allocate_map;
00754       using _Base::_M_deallocate_map;
00755       using _Base::_M_get_Tp_allocator;
00756 
00757       /** 
00758        *  A total of four data members accumulated down the hierarchy.
00759        *  May be accessed via _M_impl.*
00760        */
00761       using _Base::_M_impl;
00762 
00763     public:
00764       // [23.2.1.1] construct/copy/destroy
00765       // (assign() and get_allocator() are also listed in this section)
00766       /**
00767        *  @brief  Default constructor creates no elements.
00768        */
00769       deque()
00770       : _Base() { }
00771 
00772       /**
00773        *  @brief  Creates a %deque with no elements.
00774        *  @param  a  An allocator object.
00775        */
00776       explicit
00777       deque(const allocator_type& __a)
00778       : _Base(__a, 0) { }
00779 
00780 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00781       /**
00782        *  @brief  Creates a %deque with default constructed elements.
00783        *  @param  n  The number of elements to initially create.
00784        *
00785        *  This constructor fills the %deque with @a n default
00786        *  constructed elements.
00787        */
00788       explicit
00789       deque(size_type __n)
00790       : _Base(__n)
00791       { _M_default_initialize(); }
00792 
00793       /**
00794        *  @brief  Creates a %deque with copies of an exemplar element.
00795        *  @param  n  The number of elements to initially create.
00796        *  @param  value  An element to copy.
00797        *  @param  a  An allocator.
00798        *
00799        *  This constructor fills the %deque with @a n copies of @a value.
00800        */
00801       deque(size_type __n, const value_type& __value,
00802         const allocator_type& __a = allocator_type())
00803       : _Base(__a, __n)
00804       { _M_fill_initialize(__value); }
00805 #else
00806       /**
00807        *  @brief  Creates a %deque with copies of an exemplar element.
00808        *  @param  n  The number of elements to initially create.
00809        *  @param  value  An element to copy.
00810        *  @param  a  An allocator.
00811        *
00812        *  This constructor fills the %deque with @a n copies of @a value.
00813        */
00814       explicit
00815       deque(size_type __n, const value_type& __value = value_type(),
00816         const allocator_type& __a = allocator_type())
00817       : _Base(__a, __n)
00818       { _M_fill_initialize(__value); }
00819 #endif
00820 
00821       /**
00822        *  @brief  %Deque copy constructor.
00823        *  @param  x  A %deque of identical element and allocator types.
00824        *
00825        *  The newly-created %deque uses a copy of the allocation object used
00826        *  by @a x.
00827        */
00828       deque(const deque& __x)
00829       : _Base(__x._M_get_Tp_allocator(), __x.size())
00830       { std::__uninitialized_copy_a(__x.begin(), __x.end(), 
00831                     this->_M_impl._M_start,
00832                     _M_get_Tp_allocator()); }
00833 
00834 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00835       /**
00836        *  @brief  %Deque move constructor.
00837        *  @param  x  A %deque of identical element and allocator types.
00838        *
00839        *  The newly-created %deque contains the exact contents of @a x.
00840        *  The contents of @a x are a valid, but unspecified %deque.
00841        */
00842       deque(deque&&  __x)
00843       : _Base(std::forward<_Base>(__x)) { }
00844 
00845       /**
00846        *  @brief  Builds a %deque from an initializer list.
00847        *  @param  l  An initializer_list.
00848        *  @param  a  An allocator object.
00849        *
00850        *  Create a %deque consisting of copies of the elements in the
00851        *  initializer_list @a l.
00852        *
00853        *  This will call the element type's copy constructor N times
00854        *  (where N is l.size()) and do no memory reallocation.
00855        */
00856       deque(initializer_list<value_type> __l,
00857         const allocator_type& __a = allocator_type())
00858       : _Base(__a)
00859       {
00860     _M_range_initialize(__l.begin(), __l.end(),
00861                 random_access_iterator_tag());
00862       }
00863 #endif
00864 
00865       /**
00866        *  @brief  Builds a %deque from a range.
00867        *  @param  first  An input iterator.
00868        *  @param  last  An input iterator.
00869        *  @param  a  An allocator object.
00870        *
00871        *  Create a %deque consisting of copies of the elements from [first,
00872        *  last).
00873        *
00874        *  If the iterators are forward, bidirectional, or random-access, then
00875        *  this will call the elements' copy constructor N times (where N is
00876        *  distance(first,last)) and do no memory reallocation.  But if only
00877        *  input iterators are used, then this will do at most 2N calls to the
00878        *  copy constructor, and logN memory reallocations.
00879        */
00880       template<typename _InputIterator>
00881         deque(_InputIterator __first, _InputIterator __last,
00882           const allocator_type& __a = allocator_type())
00883     : _Base(__a)
00884         {
00885       // Check whether it's an integral type.  If so, it's not an iterator.
00886       typedef typename std::__is_integer<_InputIterator>::__type _Integral;
00887       _M_initialize_dispatch(__first, __last, _Integral());
00888     }
00889 
00890       /**
00891        *  The dtor only erases the elements, and note that if the elements
00892        *  themselves are pointers, the pointed-to memory is not touched in any
00893        *  way.  Managing the pointer is the user's responsibility.
00894        */
00895       ~deque()
00896       { _M_destroy_data(begin(), end(), _M_get_Tp_allocator()); }
00897 
00898       /**
00899        *  @brief  %Deque assignment operator.
00900        *  @param  x  A %deque of identical element and allocator types.
00901        *
00902        *  All the elements of @a x are copied, but unlike the copy constructor,
00903        *  the allocator object is not copied.
00904        */
00905       deque&
00906       operator=(const deque& __x);
00907 
00908 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00909       /**
00910        *  @brief  %Deque move assignment operator.
00911        *  @param  x  A %deque of identical element and allocator types.
00912        *
00913        *  The contents of @a x are moved into this deque (without copying).
00914        *  @a x is a valid, but unspecified %deque.
00915        */
00916       deque&
00917       operator=(deque&& __x)
00918       {
00919     // NB: DR 1204.
00920     // NB: DR 675.
00921     this->clear();
00922     this->swap(__x);
00923     return *this;
00924       }
00925 
00926       /**
00927        *  @brief  Assigns an initializer list to a %deque.
00928        *  @param  l  An initializer_list.
00929        *
00930        *  This function fills a %deque with copies of the elements in the
00931        *  initializer_list @a l.
00932        *
00933        *  Note that the assignment completely changes the %deque and that the
00934        *  resulting %deque's size is the same as the number of elements
00935        *  assigned.  Old data may be lost.
00936        */
00937       deque&
00938       operator=(initializer_list<value_type> __l)
00939       {
00940     this->assign(__l.begin(), __l.end());
00941     return *this;
00942       }
00943 #endif
00944 
00945       /**
00946        *  @brief  Assigns a given value to a %deque.
00947        *  @param  n  Number of elements to be assigned.
00948        *  @param  val  Value to be assigned.
00949        *
00950        *  This function fills a %deque with @a n copies of the given
00951        *  value.  Note that the assignment completely changes the
00952        *  %deque and that the resulting %deque's size is the same as
00953        *  the number of elements assigned.  Old data may be lost.
00954        */
00955       void
00956       assign(size_type __n, const value_type& __val)
00957       { _M_fill_assign(__n, __val); }
00958 
00959       /**
00960        *  @brief  Assigns a range to a %deque.
00961        *  @param  first  An input iterator.
00962        *  @param  last   An input iterator.
00963        *
00964        *  This function fills a %deque with copies of the elements in the
00965        *  range [first,last).
00966        *
00967        *  Note that the assignment completely changes the %deque and that the
00968        *  resulting %deque's size is the same as the number of elements
00969        *  assigned.  Old data may be lost.
00970        */
00971       template<typename _InputIterator>
00972         void
00973         assign(_InputIterator __first, _InputIterator __last)
00974         {
00975       typedef typename std::__is_integer<_InputIterator>::__type _Integral;
00976       _M_assign_dispatch(__first, __last, _Integral());
00977     }
00978 
00979 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00980       /**
00981        *  @brief  Assigns an initializer list to a %deque.
00982        *  @param  l  An initializer_list.
00983        *
00984        *  This function fills a %deque with copies of the elements in the
00985        *  initializer_list @a l.
00986        *
00987        *  Note that the assignment completely changes the %deque and that the
00988        *  resulting %deque's size is the same as the number of elements
00989        *  assigned.  Old data may be lost.
00990        */
00991       void
00992       assign(initializer_list<value_type> __l)
00993       { this->assign(__l.begin(), __l.end()); }
00994 #endif
00995 
00996       /// Get a copy of the memory allocation object.
00997       allocator_type
00998       get_allocator() const
00999       { return _Base::get_allocator(); }
01000 
01001       // iterators
01002       /**
01003        *  Returns a read/write iterator that points to the first element in the
01004        *  %deque.  Iteration is done in ordinary element order.
01005        */
01006       iterator
01007       begin()
01008       { return this->_M_impl._M_start; }
01009 
01010       /**
01011        *  Returns a read-only (constant) iterator that points to the first
01012        *  element in the %deque.  Iteration is done in ordinary element order.
01013        */
01014       const_iterator
01015       begin() const
01016       { return this->_M_impl._M_start; }
01017 
01018       /**
01019        *  Returns a read/write iterator that points one past the last
01020        *  element in the %deque.  Iteration is done in ordinary
01021        *  element order.
01022        */
01023       iterator
01024       end()
01025       { return this->_M_impl._M_finish; }
01026 
01027       /**
01028        *  Returns a read-only (constant) iterator that points one past
01029        *  the last element in the %deque.  Iteration is done in
01030        *  ordinary element order.
01031        */
01032       const_iterator
01033       end() const
01034       { return this->_M_impl._M_finish; }
01035 
01036       /**
01037        *  Returns a read/write reverse iterator that points to the
01038        *  last element in the %deque.  Iteration is done in reverse
01039        *  element order.
01040        */
01041       reverse_iterator
01042       rbegin()
01043       { return reverse_iterator(this->_M_impl._M_finish); }
01044 
01045       /**
01046        *  Returns a read-only (constant) reverse iterator that points
01047        *  to the last element in the %deque.  Iteration is done in
01048        *  reverse element order.
01049        */
01050       const_reverse_iterator
01051       rbegin() const
01052       { return const_reverse_iterator(this->_M_impl._M_finish); }
01053 
01054       /**
01055        *  Returns a read/write reverse iterator that points to one
01056        *  before the first element in the %deque.  Iteration is done
01057        *  in reverse element order.
01058        */
01059       reverse_iterator
01060       rend()
01061       { return reverse_iterator(this->_M_impl._M_start); }
01062 
01063       /**
01064        *  Returns a read-only (constant) reverse iterator that points
01065        *  to one before the first element in the %deque.  Iteration is
01066        *  done in reverse element order.
01067        */
01068       const_reverse_iterator
01069       rend() const
01070       { return const_reverse_iterator(this->_M_impl._M_start); }
01071 
01072 #ifdef __GXX_EXPERIMENTAL_CXX0X__
01073       /**
01074        *  Returns a read-only (constant) iterator that points to the first
01075        *  element in the %deque.  Iteration is done in ordinary element order.
01076        */
01077       const_iterator
01078       cbegin() const
01079       { return this->_M_impl._M_start; }
01080 
01081       /**
01082        *  Returns a read-only (constant) iterator that points one past
01083        *  the last element in the %deque.  Iteration is done in
01084        *  ordinary element order.
01085        */
01086       const_iterator
01087       cend() const
01088       { return this->_M_impl._M_finish; }
01089 
01090       /**
01091        *  Returns a read-only (constant) reverse iterator that points
01092        *  to the last element in the %deque.  Iteration is done in
01093        *  reverse element order.
01094        */
01095       const_reverse_iterator
01096       crbegin() const
01097       { return const_reverse_iterator(this->_M_impl._M_finish); }
01098 
01099       /**
01100        *  Returns a read-only (constant) reverse iterator that points
01101        *  to one before the first element in the %deque.  Iteration is
01102        *  done in reverse element order.
01103        */
01104       const_reverse_iterator
01105       crend() const
01106       { return const_reverse_iterator(this->_M_impl._M_start); }
01107 #endif
01108 
01109       // [23.2.1.2] capacity
01110       /**  Returns the number of elements in the %deque.  */
01111       size_type
01112       size() const
01113       { return this->_M_impl._M_finish - this->_M_impl._M_start; }
01114 
01115       /**  Returns the size() of the largest possible %deque.  */
01116       size_type
01117       max_size() const
01118       { return _M_get_Tp_allocator().max_size(); }
01119 
01120 #ifdef __GXX_EXPERIMENTAL_CXX0X__
01121       /**
01122        *  @brief  Resizes the %deque to the specified number of elements.
01123        *  @param  new_size  Number of elements the %deque should contain.
01124        *
01125        *  This function will %resize the %deque to the specified
01126        *  number of elements.  If the number is smaller than the
01127        *  %deque's current size the %deque is truncated, otherwise
01128        *  default constructed elements are appended.
01129        */
01130       void
01131       resize(size_type __new_size)
01132       {
01133     const size_type __len = size();
01134     if (__new_size > __len)
01135       _M_default_append(__new_size - __len);
01136     else if (__new_size < __len)
01137       _M_erase_at_end(this->_M_impl._M_start
01138               + difference_type(__new_size));
01139       }
01140 
01141       /**
01142        *  @brief  Resizes the %deque to the specified number of elements.
01143        *  @param  new_size  Number of elements the %deque should contain.
01144        *  @param  x  Data with which new elements should be populated.
01145        *
01146        *  This function will %resize the %deque to the specified
01147        *  number of elements.  If the number is smaller than the
01148        *  %deque's current size the %deque is truncated, otherwise the
01149        *  %deque is extended and new elements are populated with given
01150        *  data.
01151        */
01152       void
01153       resize(size_type __new_size, const value_type& __x)
01154       {
01155     const size_type __len = size();
01156     if (__new_size > __len)
01157       insert(this->_M_impl._M_finish, __new_size - __len, __x);
01158     else if (__new_size < __len)
01159       _M_erase_at_end(this->_M_impl._M_start
01160               + difference_type(__new_size));
01161       }
01162 #else
01163       /**
01164        *  @brief  Resizes the %deque to the specified number of elements.
01165        *  @param  new_size  Number of elements the %deque should contain.
01166        *  @param  x  Data with which new elements should be populated.
01167        *
01168        *  This function will %resize the %deque to the specified
01169        *  number of elements.  If the number is smaller than the
01170        *  %deque's current size the %deque is truncated, otherwise the
01171        *  %deque is extended and new elements are populated with given
01172        *  data.
01173        */
01174       void
01175       resize(size_type __new_size, value_type __x = value_type())
01176       {
01177     const size_type __len = size();
01178     if (__new_size > __len)
01179       insert(this->_M_impl._M_finish, __new_size - __len, __x);
01180     else if (__new_size < __len)
01181       _M_erase_at_end(this->_M_impl._M_start
01182               + difference_type(__new_size));
01183       }
01184 #endif
01185 
01186 #ifdef __GXX_EXPERIMENTAL_CXX0X__
01187       /**  A non-binding request to reduce memory use.  */
01188       void
01189       shrink_to_fit()
01190       { std::__shrink_to_fit<deque>::_S_do_it(*this); }
01191 #endif
01192 
01193       /**
01194        *  Returns true if the %deque is empty.  (Thus begin() would
01195        *  equal end().)
01196        */
01197       bool
01198       empty() const
01199       { return this->_M_impl._M_finish == this->_M_impl._M_start; }
01200 
01201       // element access
01202       /**
01203        *  @brief Subscript access to the data contained in the %deque.
01204        *  @param n The index of the element for which data should be
01205        *  accessed.
01206        *  @return  Read/write reference to data.
01207        *
01208        *  This operator allows for easy, array-style, data access.
01209        *  Note that data access with this operator is unchecked and
01210        *  out_of_range lookups are not defined. (For checked lookups
01211        *  see at().)
01212        */
01213       reference
01214       operator[](size_type __n)
01215       { return this->_M_impl._M_start[difference_type(__n)]; }
01216 
01217       /**
01218        *  @brief Subscript access to the data contained in the %deque.
01219        *  @param n The index of the element for which data should be
01220        *  accessed.
01221        *  @return  Read-only (constant) reference to data.
01222        *
01223        *  This operator allows for easy, array-style, data access.
01224        *  Note that data access with this operator is unchecked and
01225        *  out_of_range lookups are not defined. (For checked lookups
01226        *  see at().)
01227        */
01228       const_reference
01229       operator[](size_type __n) const
01230       { return this->_M_impl._M_start[difference_type(__n)]; }
01231 
01232     protected:
01233       /// Safety check used only from at().
01234       void
01235       _M_range_check(size_type __n) const
01236       {
01237     if (__n >= this->size())
01238       __throw_out_of_range(__N("deque::_M_range_check"));
01239       }
01240 
01241     public:
01242       /**
01243        *  @brief  Provides access to the data contained in the %deque.
01244        *  @param n The index of the element for which data should be
01245        *  accessed.
01246        *  @return  Read/write reference to data.
01247        *  @throw  std::out_of_range  If @a n is an invalid index.
01248        *
01249        *  This function provides for safer data access.  The parameter
01250        *  is first checked that it is in the range of the deque.  The
01251        *  function throws out_of_range if the check fails.
01252        */
01253       reference
01254       at(size_type __n)
01255       {
01256     _M_range_check(__n);
01257     return (*this)[__n];
01258       }
01259 
01260       /**
01261        *  @brief  Provides access to the data contained in the %deque.
01262        *  @param n The index of the element for which data should be
01263        *  accessed.
01264        *  @return  Read-only (constant) reference to data.
01265        *  @throw  std::out_of_range  If @a n is an invalid index.
01266        *
01267        *  This function provides for safer data access.  The parameter is first
01268        *  checked that it is in the range of the deque.  The function throws
01269        *  out_of_range if the check fails.
01270        */
01271       const_reference
01272       at(size_type __n) const
01273       {
01274     _M_range_check(__n);
01275     return (*this)[__n];
01276       }
01277 
01278       /**
01279        *  Returns a read/write reference to the data at the first
01280        *  element of the %deque.
01281        */
01282       reference
01283       front()
01284       { return *begin(); }
01285 
01286       /**
01287        *  Returns a read-only (constant) reference to the data at the first
01288        *  element of the %deque.
01289        */
01290       const_reference
01291       front() const
01292       { return *begin(); }
01293 
01294       /**
01295        *  Returns a read/write reference to the data at the last element of the
01296        *  %deque.
01297        */
01298       reference
01299       back()
01300       {
01301     iterator __tmp = end();
01302     --__tmp;
01303     return *__tmp;
01304       }
01305 
01306       /**
01307        *  Returns a read-only (constant) reference to the data at the last
01308        *  element of the %deque.
01309        */
01310       const_reference
01311       back() const
01312       {
01313     const_iterator __tmp = end();
01314     --__tmp;
01315     return *__tmp;
01316       }
01317 
01318       // [23.2.1.2] modifiers
01319       /**
01320        *  @brief  Add data to the front of the %deque.
01321        *  @param  x  Data to be added.
01322        *
01323        *  This is a typical stack operation.  The function creates an
01324        *  element at the front of the %deque and assigns the given
01325        *  data to it.  Due to the nature of a %deque this operation
01326        *  can be done in constant time.
01327        */
01328       void
01329       push_front(const value_type& __x)
01330       {
01331     if (this->_M_impl._M_start._M_cur != this->_M_impl._M_start._M_first)
01332       {
01333         this->_M_impl.construct(this->_M_impl._M_start._M_cur - 1, __x);
01334         --this->_M_impl._M_start._M_cur;
01335       }
01336     else
01337       _M_push_front_aux(__x);
01338       }
01339 
01340 #ifdef __GXX_EXPERIMENTAL_CXX0X__
01341       void
01342       push_front(value_type&& __x)
01343       { emplace_front(std::move(__x)); }
01344 
01345       template<typename... _Args>
01346         void
01347         emplace_front(_Args&&... __args);
01348 #endif
01349 
01350       /**
01351        *  @brief  Add data to the end of the %deque.
01352        *  @param  x  Data to be added.
01353        *
01354        *  This is a typical stack operation.  The function creates an
01355        *  element at the end of the %deque and assigns the given data
01356        *  to it.  Due to the nature of a %deque this operation can be
01357        *  done in constant time.
01358        */
01359       void
01360       push_back(const value_type& __x)
01361       {
01362     if (this->_M_impl._M_finish._M_cur
01363         != this->_M_impl._M_finish._M_last - 1)
01364       {
01365         this->_M_impl.construct(this->_M_impl._M_finish._M_cur, __x);
01366         ++this->_M_impl._M_finish._M_cur;
01367       }
01368     else
01369       _M_push_back_aux(__x);
01370       }
01371 
01372 #ifdef __GXX_EXPERIMENTAL_CXX0X__
01373       void
01374       push_back(value_type&& __x)
01375       { emplace_back(std::move(__x)); }
01376 
01377       template<typename... _Args>
01378         void
01379         emplace_back(_Args&&... __args);
01380 #endif
01381 
01382       /**
01383        *  @brief  Removes first element.
01384        *
01385        *  This is a typical stack operation.  It shrinks the %deque by one.
01386        *
01387        *  Note that no data is returned, and if the first element's data is
01388        *  needed, it should be retrieved before pop_front() is called.
01389        */
01390       void
01391       pop_front()
01392       {
01393     if (this->_M_impl._M_start._M_cur
01394         != this->_M_impl._M_start._M_last - 1)
01395       {
01396         this->_M_impl.destroy(this->_M_impl._M_start._M_cur);
01397         ++this->_M_impl._M_start._M_cur;
01398       }
01399     else
01400       _M_pop_front_aux();
01401       }
01402 
01403       /**
01404        *  @brief  Removes last element.
01405        *
01406        *  This is a typical stack operation.  It shrinks the %deque by one.
01407        *
01408        *  Note that no data is returned, and if the last element's data is
01409        *  needed, it should be retrieved before pop_back() is called.
01410        */
01411       void
01412       pop_back()
01413       {
01414     if (this->_M_impl._M_finish._M_cur
01415         != this->_M_impl._M_finish._M_first)
01416       {
01417         --this->_M_impl._M_finish._M_cur;
01418         this->_M_impl.destroy(this->_M_impl._M_finish._M_cur);
01419       }
01420     else
01421       _M_pop_back_aux();
01422       }
01423 
01424 #ifdef __GXX_EXPERIMENTAL_CXX0X__
01425       /**
01426        *  @brief  Inserts an object in %deque before specified iterator.
01427        *  @param  position  An iterator into the %deque.
01428        *  @param  args  Arguments.
01429        *  @return  An iterator that points to the inserted data.
01430        *
01431        *  This function will insert an object of type T constructed
01432        *  with T(std::forward<Args>(args)...) before the specified location.
01433        */
01434       template<typename... _Args>
01435         iterator
01436         emplace(iterator __position, _Args&&... __args);
01437 #endif
01438 
01439       /**
01440        *  @brief  Inserts given value into %deque before specified iterator.
01441        *  @param  position  An iterator into the %deque.
01442        *  @param  x  Data to be inserted.
01443        *  @return  An iterator that points to the inserted data.
01444        *
01445        *  This function will insert a copy of the given value before the
01446        *  specified location.
01447        */
01448       iterator
01449       insert(iterator __position, const value_type& __x);
01450 
01451 #ifdef __GXX_EXPERIMENTAL_CXX0X__
01452       /**
01453        *  @brief  Inserts given rvalue into %deque before specified iterator.
01454        *  @param  position  An iterator into the %deque.
01455        *  @param  x  Data to be inserted.
01456        *  @return  An iterator that points to the inserted data.
01457        *
01458        *  This function will insert a copy of the given rvalue before the
01459        *  specified location.
01460        */
01461       iterator
01462       insert(iterator __position, value_type&& __x)
01463       { return emplace(__position, std::move(__x)); }
01464 
01465       /**
01466        *  @brief  Inserts an initializer list into the %deque.
01467        *  @param  p  An iterator into the %deque.
01468        *  @param  l  An initializer_list.
01469        *
01470        *  This function will insert copies of the data in the
01471        *  initializer_list @a l into the %deque before the location
01472        *  specified by @a p.  This is known as <em>list insert</em>.
01473        */
01474       void
01475       insert(iterator __p, initializer_list<value_type> __l)
01476       { this->insert(__p, __l.begin(), __l.end()); }
01477 #endif
01478 
01479       /**
01480        *  @brief  Inserts a number of copies of given data into the %deque.
01481        *  @param  position  An iterator into the %deque.
01482        *  @param  n  Number of elements to be inserted.
01483        *  @param  x  Data to be inserted.
01484        *
01485        *  This function will insert a specified number of copies of the given
01486        *  data before the location specified by @a position.
01487        */
01488       void
01489       insert(iterator __position, size_type __n, const value_type& __x)
01490       { _M_fill_insert(__position, __n, __x); }
01491 
01492       /**
01493        *  @brief  Inserts a range into the %deque.
01494        *  @param  position  An iterator into the %deque.
01495        *  @param  first  An input iterator.
01496        *  @param  last   An input iterator.
01497        *
01498        *  This function will insert copies of the data in the range
01499        *  [first,last) into the %deque before the location specified
01500        *  by @a pos.  This is known as <em>range insert</em>.
01501        */
01502       template<typename _InputIterator>
01503         void
01504         insert(iterator __position, _InputIterator __first,
01505            _InputIterator __last)
01506         {
01507       // Check whether it's an integral type.  If so, it's not an iterator.
01508       typedef typename std::__is_integer<_InputIterator>::__type _Integral;
01509       _M_insert_dispatch(__position, __first, __last, _Integral());
01510     }
01511 
01512       /**
01513        *  @brief  Remove element at given position.
01514        *  @param  position  Iterator pointing to element to be erased.
01515        *  @return  An iterator pointing to the next element (or end()).
01516        *
01517        *  This function will erase the element at the given position and thus
01518        *  shorten the %deque by one.
01519        *
01520        *  The user is cautioned that
01521        *  this function only erases the element, and that if the element is
01522        *  itself a pointer, the pointed-to memory is not touched in any way.
01523        *  Managing the pointer is the user's responsibility.
01524        */
01525       iterator
01526       erase(iterator __position);
01527 
01528       /**
01529        *  @brief  Remove a range of elements.
01530        *  @param  first  Iterator pointing to the first element to be erased.
01531        *  @param  last  Iterator pointing to one past the last element to be
01532        *                erased.
01533        *  @return  An iterator pointing to the element pointed to by @a last
01534        *           prior to erasing (or end()).
01535        *
01536        *  This function will erase the elements in the range [first,last) and
01537        *  shorten the %deque accordingly.
01538        *
01539        *  The user is cautioned that
01540        *  this function only erases the elements, and that if the elements
01541        *  themselves are pointers, the pointed-to memory is not touched in any
01542        *  way.  Managing the pointer is the user's responsibility.
01543        */
01544       iterator
01545       erase(iterator __first, iterator __last);
01546 
01547       /**
01548        *  @brief  Swaps data with another %deque.
01549        *  @param  x  A %deque of the same element and allocator types.
01550        *
01551        *  This exchanges the elements between two deques in constant time.
01552        *  (Four pointers, so it should be quite fast.)
01553        *  Note that the global std::swap() function is specialized such that
01554        *  std::swap(d1,d2) will feed to this function.
01555        */
01556       void
01557       swap(deque& __x)
01558       {
01559     std::swap(this->_M_impl._M_start, __x._M_impl._M_start);
01560     std::swap(this->_M_impl._M_finish, __x._M_impl._M_finish);
01561     std::swap(this->_M_impl._M_map, __x._M_impl._M_map);
01562     std::swap(this->_M_impl._M_map_size, __x._M_impl._M_map_size);
01563 
01564     // _GLIBCXX_RESOLVE_LIB_DEFECTS
01565     // 431. Swapping containers with unequal allocators.
01566     std::__alloc_swap<_Tp_alloc_type>::_S_do_it(_M_get_Tp_allocator(),
01567                             __x._M_get_Tp_allocator());
01568       }
01569 
01570       /**
01571        *  Erases all the elements.  Note that this function only erases the
01572        *  elements, and that if the elements themselves are pointers, the
01573        *  pointed-to memory is not touched in any way.  Managing the pointer is
01574        *  the user's responsibility.
01575        */
01576       void
01577       clear()
01578       { _M_erase_at_end(begin()); }
01579 
01580     protected:
01581       // Internal constructor functions follow.
01582 
01583       // called by the range constructor to implement [23.1.1]/9
01584 
01585       // _GLIBCXX_RESOLVE_LIB_DEFECTS
01586       // 438. Ambiguity in the "do the right thing" clause
01587       template<typename _Integer>
01588         void
01589         _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type)
01590         {
01591       _M_initialize_map(static_cast<size_type>(__n));
01592       _M_fill_initialize(__x);
01593     }
01594 
01595       // called by the range constructor to implement [23.1.1]/9
01596       template<typename _InputIterator>
01597         void
01598         _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
01599                    __false_type)
01600         {
01601       typedef typename std::iterator_traits<_InputIterator>::
01602         iterator_category _IterCategory;
01603       _M_range_initialize(__first, __last, _IterCategory());
01604     }
01605 
01606       // called by the second initialize_dispatch above
01607       //@{
01608       /**
01609        *  @brief Fills the deque with whatever is in [first,last).
01610        *  @param  first  An input iterator.
01611        *  @param  last  An input iterator.
01612        *  @return   Nothing.
01613        *
01614        *  If the iterators are actually forward iterators (or better), then the
01615        *  memory layout can be done all at once.  Else we move forward using
01616        *  push_back on each value from the iterator.
01617        */
01618       template<typename _InputIterator>
01619         void
01620         _M_range_initialize(_InputIterator __first, _InputIterator __last,
01621                 std::input_iterator_tag);
01622 
01623       // called by the second initialize_dispatch above
01624       template<typename _ForwardIterator>
01625         void
01626         _M_range_initialize(_ForwardIterator __first, _ForwardIterator __last,
01627                 std::forward_iterator_tag);
01628       //@}
01629 
01630       /**
01631        *  @brief Fills the %deque with copies of value.
01632        *  @param  value  Initial value.
01633        *  @return   Nothing.
01634        *  @pre _M_start and _M_finish have already been initialized,
01635        *  but none of the %deque's elements have yet been constructed.
01636        *
01637        *  This function is called only when the user provides an explicit size
01638        *  (with or without an explicit exemplar value).
01639        */
01640       void
01641       _M_fill_initialize(const value_type& __value);
01642 
01643 #ifdef __GXX_EXPERIMENTAL_CXX0X__
01644       // called by deque(n).
01645       void
01646       _M_default_initialize();
01647 #endif
01648 
01649       // Internal assign functions follow.  The *_aux functions do the actual
01650       // assignment work for the range versions.
01651 
01652       // called by the range assign to implement [23.1.1]/9
01653 
01654       // _GLIBCXX_RESOLVE_LIB_DEFECTS
01655       // 438. Ambiguity in the "do the right thing" clause
01656       template<typename _Integer>
01657         void
01658         _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
01659         { _M_fill_assign(__n, __val); }
01660 
01661       // called by the range assign to implement [23.1.1]/9
01662       template<typename _InputIterator>
01663         void
01664         _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
01665                __false_type)
01666         {
01667       typedef typename std::iterator_traits<_InputIterator>::
01668         iterator_category _IterCategory;
01669       _M_assign_aux(__first, __last, _IterCategory());
01670     }
01671 
01672       // called by the second assign_dispatch above
01673       template<typename _InputIterator>
01674         void
01675         _M_assign_aux(_InputIterator __first, _InputIterator __last,
01676               std::input_iterator_tag);
01677 
01678       // called by the second assign_dispatch above
01679       template<typename _ForwardIterator>
01680         void
01681         _M_assign_aux(_ForwardIterator __first, _ForwardIterator __last,
01682               std::forward_iterator_tag)
01683         {
01684       const size_type __len = std::distance(__first, __last);
01685       if (__len > size())
01686         {
01687           _ForwardIterator __mid = __first;
01688           std::advance(__mid, size());
01689           std::copy(__first, __mid, begin());
01690           insert(end(), __mid, __last);
01691         }
01692       else
01693         _M_erase_at_end(std::copy(__first, __last, begin()));
01694     }
01695 
01696       // Called by assign(n,t), and the range assign when it turns out
01697       // to be the same thing.
01698       void
01699       _M_fill_assign(size_type __n, const value_type& __val)
01700       {
01701     if (__n > size())
01702       {
01703         std::fill(begin(), end(), __val);
01704         insert(end(), __n - size(), __val);
01705       }
01706     else
01707       {
01708         _M_erase_at_end(begin() + difference_type(__n));
01709         std::fill(begin(), end(), __val);
01710       }
01711       }
01712 
01713       //@{
01714       /// Helper functions for push_* and pop_*.
01715 #ifndef __GXX_EXPERIMENTAL_CXX0X__
01716       void _M_push_back_aux(const value_type&);
01717 
01718       void _M_push_front_aux(const value_type&);
01719 #else
01720       template<typename... _Args>
01721         void _M_push_back_aux(_Args&&... __args);
01722 
01723       template<typename... _Args>
01724         void _M_push_front_aux(_Args&&... __args);
01725 #endif
01726 
01727       void _M_pop_back_aux();
01728 
01729       void _M_pop_front_aux();
01730       //@}
01731 
01732       // Internal insert functions follow.  The *_aux functions do the actual
01733       // insertion work when all shortcuts fail.
01734 
01735       // called by the range insert to implement [23.1.1]/9
01736 
01737       // _GLIBCXX_RESOLVE_LIB_DEFECTS
01738       // 438. Ambiguity in the "do the right thing" clause
01739       template<typename _Integer>
01740         void
01741         _M_insert_dispatch(iterator __pos,
01742                _Integer __n, _Integer __x, __true_type)
01743         { _M_fill_insert(__pos, __n, __x); }
01744 
01745       // called by the range insert to implement [23.1.1]/9
01746       template<typename _InputIterator>
01747         void
01748         _M_insert_dispatch(iterator __pos,
01749                _InputIterator __first, _InputIterator __last,
01750                __false_type)
01751         {
01752       typedef typename std::iterator_traits<_InputIterator>::
01753         iterator_category _IterCategory;
01754           _M_range_insert_aux(__pos, __first, __last, _IterCategory());
01755     }
01756 
01757       // called by the second insert_dispatch above
01758       template<typename _InputIterator>
01759         void
01760         _M_range_insert_aux(iterator __pos, _InputIterator __first,
01761                 _InputIterator __last, std::input_iterator_tag);
01762 
01763       // called by the second insert_dispatch above
01764       template<typename _ForwardIterator>
01765         void
01766         _M_range_insert_aux(iterator __pos, _ForwardIterator __first,
01767                 _ForwardIterator __last, std::forward_iterator_tag);
01768 
01769       // Called by insert(p,n,x), and the range insert when it turns out to be
01770       // the same thing.  Can use fill functions in optimal situations,
01771       // otherwise passes off to insert_aux(p,n,x).
01772       void
01773       _M_fill_insert(iterator __pos, size_type __n, const value_type& __x);
01774 
01775       // called by insert(p,x)
01776 #ifndef __GXX_EXPERIMENTAL_CXX0X__
01777       iterator
01778       _M_insert_aux(iterator __pos, const value_type& __x);
01779 #else
01780       template<typename... _Args>
01781         iterator
01782         _M_insert_aux(iterator __pos, _Args&&... __args);
01783 #endif
01784 
01785       // called by insert(p,n,x) via fill_insert
01786       void
01787       _M_insert_aux(iterator __pos, size_type __n, const value_type& __x);
01788 
01789       // called by range_insert_aux for forward iterators
01790       template<typename _ForwardIterator>
01791         void
01792         _M_insert_aux(iterator __pos,
01793               _ForwardIterator __first, _ForwardIterator __last,
01794               size_type __n);
01795 
01796 
01797       // Internal erase functions follow.
01798 
01799       void
01800       _M_destroy_data_aux(iterator __first, iterator __last);
01801 
01802       // Called by ~deque().
01803       // NB: Doesn't deallocate the nodes.
01804       template<typename _Alloc1>
01805         void
01806         _M_destroy_data(iterator __first, iterator __last, const _Alloc1&)
01807         { _M_destroy_data_aux(__first, __last); }
01808 
01809       void
01810       _M_destroy_data(iterator __first, iterator __last,
01811               const std::allocator<_Tp>&)
01812       {
01813     if (!__has_trivial_destructor(value_type))
01814       _M_destroy_data_aux(__first, __last);
01815       }
01816 
01817       // Called by erase(q1, q2).
01818       void
01819       _M_erase_at_begin(iterator __pos)
01820       {
01821     _M_destroy_data(begin(), __pos, _M_get_Tp_allocator());
01822     _M_destroy_nodes(this->_M_impl._M_start._M_node, __pos._M_node);
01823     this->_M_impl._M_start = __pos;
01824       }
01825 
01826       // Called by erase(q1, q2), resize(), clear(), _M_assign_aux,
01827       // _M_fill_assign, operator=.
01828       void
01829       _M_erase_at_end(iterator __pos)
01830       {
01831     _M_destroy_data(__pos, end(), _M_get_Tp_allocator());
01832     _M_destroy_nodes(__pos._M_node + 1,
01833              this->_M_impl._M_finish._M_node + 1);
01834     this->_M_impl._M_finish = __pos;
01835       }
01836 
01837 #ifdef __GXX_EXPERIMENTAL_CXX0X__
01838       // Called by resize(sz).
01839       void
01840       _M_default_append(size_type __n);
01841 #endif
01842 
01843       //@{
01844       /// Memory-handling helpers for the previous internal insert functions.
01845       iterator
01846       _M_reserve_elements_at_front(size_type __n)
01847       {
01848     const size_type __vacancies = this->_M_impl._M_start._M_cur
01849                                   - this->_M_impl._M_start._M_first;
01850     if (__n > __vacancies)
01851       _M_new_elements_at_front(__n - __vacancies);
01852     return this->_M_impl._M_start - difference_type(__n);
01853       }
01854 
01855       iterator
01856       _M_reserve_elements_at_back(size_type __n)
01857       {
01858     const size_type __vacancies = (this->_M_impl._M_finish._M_last
01859                        - this->_M_impl._M_finish._M_cur) - 1;
01860     if (__n > __vacancies)
01861       _M_new_elements_at_back(__n - __vacancies);
01862     return this->_M_impl._M_finish + difference_type(__n);
01863       }
01864 
01865       void
01866       _M_new_elements_at_front(size_type __new_elements);
01867 
01868       void
01869       _M_new_elements_at_back(size_type __new_elements);
01870       //@}
01871 
01872 
01873       //@{
01874       /**
01875        *  @brief Memory-handling helpers for the major %map.
01876        *
01877        *  Makes sure the _M_map has space for new nodes.  Does not
01878        *  actually add the nodes.  Can invalidate _M_map pointers.
01879        *  (And consequently, %deque iterators.)
01880        */
01881       void
01882       _M_reserve_map_at_back(size_type __nodes_to_add = 1)
01883       {
01884     if (__nodes_to_add + 1 > this->_M_impl._M_map_size
01885         - (this->_M_impl._M_finish._M_node - this->_M_impl._M_map))
01886       _M_reallocate_map(__nodes_to_add, false);
01887       }
01888 
01889       void
01890       _M_reserve_map_at_front(size_type __nodes_to_add = 1)
01891       {
01892     if (__nodes_to_add > size_type(this->_M_impl._M_start._M_node
01893                        - this->_M_impl._M_map))
01894       _M_reallocate_map(__nodes_to_add, true);
01895       }
01896 
01897       void
01898       _M_reallocate_map(size_type __nodes_to_add, bool __add_at_front);
01899       //@}
01900     };
01901 
01902 
01903   /**
01904    *  @brief  Deque equality comparison.
01905    *  @param  x  A %deque.
01906    *  @param  y  A %deque of the same type as @a x.
01907    *  @return  True iff the size and elements of the deques are equal.
01908    *
01909    *  This is an equivalence relation.  It is linear in the size of the
01910    *  deques.  Deques are considered equivalent if their sizes are equal,
01911    *  and if corresponding elements compare equal.
01912   */
01913   template<typename _Tp, typename _Alloc>
01914     inline bool
01915     operator==(const deque<_Tp, _Alloc>& __x,
01916                          const deque<_Tp, _Alloc>& __y)
01917     { return __x.size() == __y.size()
01918              && std::equal(__x.begin(), __x.end(), __y.begin()); }
01919 
01920   /**
01921    *  @brief  Deque ordering relation.
01922    *  @param  x  A %deque.
01923    *  @param  y  A %deque of the same type as @a x.
01924    *  @return  True iff @a x is lexicographically less than @a y.
01925    *
01926    *  This is a total ordering relation.  It is linear in the size of the
01927    *  deques.  The elements must be comparable with @c <.
01928    *
01929    *  See std::lexicographical_compare() for how the determination is made.
01930   */
01931   template<typename _Tp, typename _Alloc>
01932     inline bool
01933     operator<(const deque<_Tp, _Alloc>& __x,
01934           const deque<_Tp, _Alloc>& __y)
01935     { return std::lexicographical_compare(__x.begin(), __x.end(),
01936                       __y.begin(), __y.end()); }
01937 
01938   /// Based on operator==
01939   template<typename _Tp, typename _Alloc>
01940     inline bool
01941     operator!=(const deque<_Tp, _Alloc>& __x,
01942            const deque<_Tp, _Alloc>& __y)
01943     { return !(__x == __y); }
01944 
01945   /// Based on operator<
01946   template<typename _Tp, typename _Alloc>
01947     inline bool
01948     operator>(const deque<_Tp, _Alloc>& __x,
01949           const deque<_Tp, _Alloc>& __y)
01950     { return __y < __x; }
01951 
01952   /// Based on operator<
01953   template<typename _Tp, typename _Alloc>
01954     inline bool
01955     operator<=(const deque<_Tp, _Alloc>& __x,
01956            const deque<_Tp, _Alloc>& __y)
01957     { return !(__y < __x); }
01958 
01959   /// Based on operator<
01960   template<typename _Tp, typename _Alloc>
01961     inline bool
01962     operator>=(const deque<_Tp, _Alloc>& __x,
01963            const deque<_Tp, _Alloc>& __y)
01964     { return !(__x < __y); }
01965 
01966   /// See std::deque::swap().
01967   template<typename _Tp, typename _Alloc>
01968     inline void
01969     swap(deque<_Tp,_Alloc>& __x, deque<_Tp,_Alloc>& __y)
01970     { __x.swap(__y); }
01971 
01972 #undef _GLIBCXX_DEQUE_BUF_SIZE
01973 
01974 _GLIBCXX_END_NESTED_NAMESPACE
01975 
01976 #endif /* _STL_DEQUE_H */