stl_list.h

Go to the documentation of this file.
00001 // List 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) 1996,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_list.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_LIST_H
00058 #define _STL_LIST_H 1
00059 
00060 #include <bits/concept_check.h>
00061 #include <initializer_list>
00062 
00063 _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_D)
00064 
00065   // Supporting structures are split into common and templated types; the
00066   // latter publicly inherits from the former in an effort to reduce code
00067   // duplication.  This results in some "needless" static_cast'ing later on,
00068   // but it's all safe downcasting.
00069 
00070   /// Common part of a node in the %list. 
00071   struct _List_node_base
00072   {
00073     _List_node_base* _M_next;
00074     _List_node_base* _M_prev;
00075 
00076     static void
00077     swap(_List_node_base& __x, _List_node_base& __y) throw ();
00078 
00079     void
00080     _M_transfer(_List_node_base * const __first,
00081         _List_node_base * const __last) throw ();
00082 
00083     void
00084     _M_reverse() throw ();
00085 
00086     void
00087     _M_hook(_List_node_base * const __position) throw ();
00088 
00089     void
00090     _M_unhook() throw ();
00091   };
00092 
00093   /// An actual node in the %list.
00094   template<typename _Tp>
00095     struct _List_node : public _List_node_base
00096     {
00097       ///< User's data.
00098       _Tp _M_data;
00099 
00100 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00101       template<typename... _Args>
00102         _List_node(_Args&&... __args)
00103     : _List_node_base(), _M_data(std::forward<_Args>(__args)...) { }
00104 #endif
00105     };
00106 
00107   /**
00108    *  @brief A list::iterator.
00109    *
00110    *  All the functions are op overloads.
00111   */
00112   template<typename _Tp>
00113     struct _List_iterator
00114     {
00115       typedef _List_iterator<_Tp>                _Self;
00116       typedef _List_node<_Tp>                    _Node;
00117 
00118       typedef ptrdiff_t                          difference_type;
00119       typedef std::bidirectional_iterator_tag    iterator_category;
00120       typedef _Tp                                value_type;
00121       typedef _Tp*                               pointer;
00122       typedef _Tp&                               reference;
00123 
00124       _List_iterator()
00125       : _M_node() { }
00126 
00127       explicit
00128       _List_iterator(_List_node_base* __x)
00129       : _M_node(__x) { }
00130 
00131       // Must downcast from List_node_base to _List_node to get to _M_data.
00132       reference
00133       operator*() const
00134       { return static_cast<_Node*>(_M_node)->_M_data; }
00135 
00136       pointer
00137       operator->() const
00138       { return &static_cast<_Node*>(_M_node)->_M_data; }
00139 
00140       _Self&
00141       operator++()
00142       {
00143     _M_node = _M_node->_M_next;
00144     return *this;
00145       }
00146 
00147       _Self
00148       operator++(int)
00149       {
00150     _Self __tmp = *this;
00151     _M_node = _M_node->_M_next;
00152     return __tmp;
00153       }
00154 
00155       _Self&
00156       operator--()
00157       {
00158     _M_node = _M_node->_M_prev;
00159     return *this;
00160       }
00161 
00162       _Self
00163       operator--(int)
00164       {
00165     _Self __tmp = *this;
00166     _M_node = _M_node->_M_prev;
00167     return __tmp;
00168       }
00169 
00170       bool
00171       operator==(const _Self& __x) const
00172       { return _M_node == __x._M_node; }
00173 
00174       bool
00175       operator!=(const _Self& __x) const
00176       { return _M_node != __x._M_node; }
00177 
00178       // The only member points to the %list element.
00179       _List_node_base* _M_node;
00180     };
00181 
00182   /**
00183    *  @brief A list::const_iterator.
00184    *
00185    *  All the functions are op overloads.
00186   */
00187   template<typename _Tp>
00188     struct _List_const_iterator
00189     {
00190       typedef _List_const_iterator<_Tp>          _Self;
00191       typedef const _List_node<_Tp>              _Node;
00192       typedef _List_iterator<_Tp>                iterator;
00193 
00194       typedef ptrdiff_t                          difference_type;
00195       typedef std::bidirectional_iterator_tag    iterator_category;
00196       typedef _Tp                                value_type;
00197       typedef const _Tp*                         pointer;
00198       typedef const _Tp&                         reference;
00199 
00200       _List_const_iterator()
00201       : _M_node() { }
00202 
00203       explicit
00204       _List_const_iterator(const _List_node_base* __x)
00205       : _M_node(__x) { }
00206 
00207       _List_const_iterator(const iterator& __x)
00208       : _M_node(__x._M_node) { }
00209 
00210       // Must downcast from List_node_base to _List_node to get to
00211       // _M_data.
00212       reference
00213       operator*() const
00214       { return static_cast<_Node*>(_M_node)->_M_data; }
00215 
00216       pointer
00217       operator->() const
00218       { return &static_cast<_Node*>(_M_node)->_M_data; }
00219 
00220       _Self&
00221       operator++()
00222       {
00223     _M_node = _M_node->_M_next;
00224     return *this;
00225       }
00226 
00227       _Self
00228       operator++(int)
00229       {
00230     _Self __tmp = *this;
00231     _M_node = _M_node->_M_next;
00232     return __tmp;
00233       }
00234 
00235       _Self&
00236       operator--()
00237       {
00238     _M_node = _M_node->_M_prev;
00239     return *this;
00240       }
00241 
00242       _Self
00243       operator--(int)
00244       {
00245     _Self __tmp = *this;
00246     _M_node = _M_node->_M_prev;
00247     return __tmp;
00248       }
00249 
00250       bool
00251       operator==(const _Self& __x) const
00252       { return _M_node == __x._M_node; }
00253 
00254       bool
00255       operator!=(const _Self& __x) const
00256       { return _M_node != __x._M_node; }
00257 
00258       // The only member points to the %list element.
00259       const _List_node_base* _M_node;
00260     };
00261 
00262   template<typename _Val>
00263     inline bool
00264     operator==(const _List_iterator<_Val>& __x,
00265            const _List_const_iterator<_Val>& __y)
00266     { return __x._M_node == __y._M_node; }
00267 
00268   template<typename _Val>
00269     inline bool
00270     operator!=(const _List_iterator<_Val>& __x,
00271                const _List_const_iterator<_Val>& __y)
00272     { return __x._M_node != __y._M_node; }
00273 
00274 
00275   /// See bits/stl_deque.h's _Deque_base for an explanation.
00276   template<typename _Tp, typename _Alloc>
00277     class _List_base
00278     {
00279     protected:
00280       // NOTA BENE
00281       // The stored instance is not actually of "allocator_type"'s
00282       // type.  Instead we rebind the type to
00283       // Allocator<List_node<Tp>>, which according to [20.1.5]/4
00284       // should probably be the same.  List_node<Tp> is not the same
00285       // size as Tp (it's two pointers larger), and specializations on
00286       // Tp may go unused because List_node<Tp> is being bound
00287       // instead.
00288       //
00289       // We put this to the test in the constructors and in
00290       // get_allocator, where we use conversions between
00291       // allocator_type and _Node_alloc_type. The conversion is
00292       // required by table 32 in [20.1.5].
00293       typedef typename _Alloc::template rebind<_List_node<_Tp> >::other
00294         _Node_alloc_type;
00295 
00296       typedef typename _Alloc::template rebind<_Tp>::other _Tp_alloc_type;
00297 
00298       struct _List_impl 
00299       : public _Node_alloc_type
00300       {
00301     _List_node_base _M_node;
00302 
00303     _List_impl()
00304     : _Node_alloc_type(), _M_node()
00305     { }
00306 
00307     _List_impl(const _Node_alloc_type& __a)
00308     : _Node_alloc_type(__a), _M_node()
00309     { }
00310       };
00311 
00312       _List_impl _M_impl;
00313 
00314       _List_node<_Tp>*
00315       _M_get_node()
00316       { return _M_impl._Node_alloc_type::allocate(1); }
00317       
00318       void
00319       _M_put_node(_List_node<_Tp>* __p)
00320       { _M_impl._Node_alloc_type::deallocate(__p, 1); }
00321       
00322   public:
00323       typedef _Alloc allocator_type;
00324 
00325       _Node_alloc_type&
00326       _M_get_Node_allocator()
00327       { return *static_cast<_Node_alloc_type*>(&this->_M_impl); }
00328 
00329       const _Node_alloc_type&
00330       _M_get_Node_allocator() const
00331       { return *static_cast<const _Node_alloc_type*>(&this->_M_impl); }
00332 
00333       _Tp_alloc_type
00334       _M_get_Tp_allocator() const
00335       { return _Tp_alloc_type(_M_get_Node_allocator()); }
00336 
00337       allocator_type
00338       get_allocator() const
00339       { return allocator_type(_M_get_Node_allocator()); }
00340 
00341       _List_base()
00342       : _M_impl()
00343       { _M_init(); }
00344 
00345       _List_base(const allocator_type& __a)
00346       : _M_impl(__a)
00347       { _M_init(); }
00348 
00349 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00350       _List_base(_List_base&& __x)
00351       : _M_impl(__x._M_get_Node_allocator())
00352       {
00353     _M_init();
00354     _List_node_base::swap(this->_M_impl._M_node, __x._M_impl._M_node);  
00355       }
00356 #endif
00357 
00358       // This is what actually destroys the list.
00359       ~_List_base()
00360       { _M_clear(); }
00361 
00362       void
00363       _M_clear();
00364 
00365       void
00366       _M_init()
00367       {
00368         this->_M_impl._M_node._M_next = &this->_M_impl._M_node;
00369         this->_M_impl._M_node._M_prev = &this->_M_impl._M_node;
00370       }
00371     };
00372 
00373   /**
00374    *  @brief A standard container with linear time access to elements,
00375    *  and fixed time insertion/deletion at any point in the sequence.
00376    *
00377    *  @ingroup sequences
00378    *
00379    *  Meets the requirements of a <a href="tables.html#65">container</a>, a
00380    *  <a href="tables.html#66">reversible container</a>, and a
00381    *  <a href="tables.html#67">sequence</a>, including the
00382    *  <a href="tables.html#68">optional sequence requirements</a> with the
00383    *  %exception of @c at and @c operator[].
00384    *
00385    *  This is a @e doubly @e linked %list.  Traversal up and down the
00386    *  %list requires linear time, but adding and removing elements (or
00387    *  @e nodes) is done in constant time, regardless of where the
00388    *  change takes place.  Unlike std::vector and std::deque,
00389    *  random-access iterators are not provided, so subscripting ( @c
00390    *  [] ) access is not allowed.  For algorithms which only need
00391    *  sequential access, this lack makes no difference.
00392    *
00393    *  Also unlike the other standard containers, std::list provides
00394    *  specialized algorithms %unique to linked lists, such as
00395    *  splicing, sorting, and in-place reversal.
00396    *
00397    *  A couple points on memory allocation for list<Tp>:
00398    *
00399    *  First, we never actually allocate a Tp, we allocate
00400    *  List_node<Tp>'s and trust [20.1.5]/4 to DTRT.  This is to ensure
00401    *  that after elements from %list<X,Alloc1> are spliced into
00402    *  %list<X,Alloc2>, destroying the memory of the second %list is a
00403    *  valid operation, i.e., Alloc1 giveth and Alloc2 taketh away.
00404    *
00405    *  Second, a %list conceptually represented as
00406    *  @code
00407    *    A <---> B <---> C <---> D
00408    *  @endcode
00409    *  is actually circular; a link exists between A and D.  The %list
00410    *  class holds (as its only data member) a private list::iterator
00411    *  pointing to @e D, not to @e A!  To get to the head of the %list,
00412    *  we start at the tail and move forward by one.  When this member
00413    *  iterator's next/previous pointers refer to itself, the %list is
00414    *  %empty. 
00415   */
00416   template<typename _Tp, typename _Alloc = std::allocator<_Tp> >
00417     class list : protected _List_base<_Tp, _Alloc>
00418     {
00419       // concept requirements
00420       typedef typename _Alloc::value_type                _Alloc_value_type;
00421       __glibcxx_class_requires(_Tp, _SGIAssignableConcept)
00422       __glibcxx_class_requires2(_Tp, _Alloc_value_type, _SameTypeConcept)
00423 
00424       typedef _List_base<_Tp, _Alloc>                    _Base;
00425       typedef typename _Base::_Tp_alloc_type         _Tp_alloc_type;
00426 
00427     public:
00428       typedef _Tp                                        value_type;
00429       typedef typename _Tp_alloc_type::pointer           pointer;
00430       typedef typename _Tp_alloc_type::const_pointer     const_pointer;
00431       typedef typename _Tp_alloc_type::reference         reference;
00432       typedef typename _Tp_alloc_type::const_reference   const_reference;
00433       typedef _List_iterator<_Tp>                        iterator;
00434       typedef _List_const_iterator<_Tp>                  const_iterator;
00435       typedef std::reverse_iterator<const_iterator>      const_reverse_iterator;
00436       typedef std::reverse_iterator<iterator>            reverse_iterator;
00437       typedef size_t                                     size_type;
00438       typedef ptrdiff_t                                  difference_type;
00439       typedef _Alloc                                     allocator_type;
00440 
00441     protected:
00442       // Note that pointers-to-_Node's can be ctor-converted to
00443       // iterator types.
00444       typedef _List_node<_Tp>                _Node;
00445 
00446       using _Base::_M_impl;
00447       using _Base::_M_put_node;
00448       using _Base::_M_get_node;
00449       using _Base::_M_get_Tp_allocator;
00450       using _Base::_M_get_Node_allocator;
00451 
00452       /**
00453        *  @param  x  An instance of user data.
00454        *
00455        *  Allocates space for a new node and constructs a copy of @a x in it.
00456        */
00457 #ifndef __GXX_EXPERIMENTAL_CXX0X__
00458       _Node*
00459       _M_create_node(const value_type& __x)
00460       {
00461     _Node* __p = this->_M_get_node();
00462     __try
00463       {
00464         _M_get_Tp_allocator().construct(&__p->_M_data, __x);
00465       }
00466     __catch(...)
00467       {
00468         _M_put_node(__p);
00469         __throw_exception_again;
00470       }
00471     return __p;
00472       }
00473 #else
00474       template<typename... _Args>
00475         _Node*
00476         _M_create_node(_Args&&... __args)
00477     {
00478       _Node* __p = this->_M_get_node();
00479       __try
00480         {
00481           _M_get_Node_allocator().construct(__p,
00482                         std::forward<_Args>(__args)...);
00483         }
00484       __catch(...)
00485         {
00486           _M_put_node(__p);
00487           __throw_exception_again;
00488         }
00489       return __p;
00490     }
00491 #endif
00492 
00493     public:
00494       // [23.2.2.1] construct/copy/destroy
00495       // (assign() and get_allocator() are also listed in this section)
00496       /**
00497        *  @brief  Default constructor creates no elements.
00498        */
00499       list()
00500       : _Base() { }
00501 
00502       /**
00503        *  @brief  Creates a %list with no elements.
00504        *  @param  a  An allocator object.
00505        */
00506       explicit
00507       list(const allocator_type& __a)
00508       : _Base(__a) { }
00509 
00510       /**
00511        *  @brief  Creates a %list with copies of an exemplar element.
00512        *  @param  n  The number of elements to initially create.
00513        *  @param  value  An element to copy.
00514        *  @param  a  An allocator object.
00515        *
00516        *  This constructor fills the %list with @a n copies of @a value.
00517        */
00518       explicit
00519       list(size_type __n, const value_type& __value = value_type(),
00520        const allocator_type& __a = allocator_type())
00521       : _Base(__a)
00522       { _M_fill_initialize(__n, __value); }
00523 
00524       /**
00525        *  @brief  %List copy constructor.
00526        *  @param  x  A %list of identical element and allocator types.
00527        *
00528        *  The newly-created %list uses a copy of the allocation object used
00529        *  by @a x.
00530        */
00531       list(const list& __x)
00532       : _Base(__x._M_get_Node_allocator())
00533       { _M_initialize_dispatch(__x.begin(), __x.end(), __false_type()); }
00534 
00535 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00536       /**
00537        *  @brief  %List move constructor.
00538        *  @param  x  A %list of identical element and allocator types.
00539        *
00540        *  The newly-created %list contains the exact contents of @a x.
00541        *  The contents of @a x are a valid, but unspecified %list.
00542        */
00543       list(list&& __x)
00544       : _Base(std::forward<_Base>(__x)) { }
00545 
00546       /**
00547        *  @brief  Builds a %list from an initializer_list
00548        *  @param  l  An initializer_list of value_type.
00549        *  @param  a  An allocator object.
00550        *
00551        *  Create a %list consisting of copies of the elements in the
00552        *  initializer_list @a l.  This is linear in l.size().
00553        */
00554       list(initializer_list<value_type> __l,
00555            const allocator_type& __a = allocator_type())
00556       : _Base(__a)
00557       { _M_initialize_dispatch(__l.begin(), __l.end(), __false_type()); }
00558 #endif
00559 
00560       /**
00561        *  @brief  Builds a %list from a range.
00562        *  @param  first  An input iterator.
00563        *  @param  last  An input iterator.
00564        *  @param  a  An allocator object.
00565        *
00566        *  Create a %list consisting of copies of the elements from
00567        *  [@a first,@a last).  This is linear in N (where N is
00568        *  distance(@a first,@a last)).
00569        */
00570       template<typename _InputIterator>
00571         list(_InputIterator __first, _InputIterator __last,
00572          const allocator_type& __a = allocator_type())
00573         : _Base(__a)
00574         { 
00575       // Check whether it's an integral type.  If so, it's not an iterator.
00576       typedef typename std::__is_integer<_InputIterator>::__type _Integral;
00577       _M_initialize_dispatch(__first, __last, _Integral());
00578     }
00579 
00580       /**
00581        *  No explicit dtor needed as the _Base dtor takes care of
00582        *  things.  The _Base dtor only erases the elements, and note
00583        *  that if the elements themselves are pointers, the pointed-to
00584        *  memory is not touched in any way.  Managing the pointer is
00585        *  the user's responsibility.
00586        */
00587 
00588       /**
00589        *  @brief  %List assignment operator.
00590        *  @param  x  A %list of identical element and allocator types.
00591        *
00592        *  All the elements of @a x are copied, but unlike the copy
00593        *  constructor, the allocator object is not copied.
00594        */
00595       list&
00596       operator=(const list& __x);
00597 
00598 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00599       /**
00600        *  @brief  %List move assignment operator.
00601        *  @param  x  A %list of identical element and allocator types.
00602        *
00603        *  The contents of @a x are moved into this %list (without copying).
00604        *  @a x is a valid, but unspecified %list
00605        */
00606       list&
00607       operator=(list&& __x)
00608       {
00609     // NB: DR 1204.
00610     // NB: DR 675.
00611     this->clear();
00612     this->swap(__x);
00613     return *this;
00614       }
00615 
00616       /**
00617        *  @brief  %List initializer list assignment operator.
00618        *  @param  l  An initializer_list of value_type.
00619        *
00620        *  Replace the contents of the %list with copies of the elements
00621        *  in the initializer_list @a l.  This is linear in l.size().
00622        */
00623       list&
00624       operator=(initializer_list<value_type> __l)
00625       {
00626     this->assign(__l.begin(), __l.end());
00627     return *this;
00628       }
00629 #endif
00630 
00631       /**
00632        *  @brief  Assigns a given value to a %list.
00633        *  @param  n  Number of elements to be assigned.
00634        *  @param  val  Value to be assigned.
00635        *
00636        *  This function fills a %list with @a n copies of the given
00637        *  value.  Note that the assignment completely changes the %list
00638        *  and that the resulting %list's size is the same as the number
00639        *  of elements assigned.  Old data may be lost.
00640        */
00641       void
00642       assign(size_type __n, const value_type& __val)
00643       { _M_fill_assign(__n, __val); }
00644 
00645       /**
00646        *  @brief  Assigns a range to a %list.
00647        *  @param  first  An input iterator.
00648        *  @param  last   An input iterator.
00649        *
00650        *  This function fills a %list with copies of the elements in the
00651        *  range [@a first,@a last).
00652        *
00653        *  Note that the assignment completely changes the %list and
00654        *  that the resulting %list's size is the same as the number of
00655        *  elements assigned.  Old data may be lost.
00656        */
00657       template<typename _InputIterator>
00658         void
00659         assign(_InputIterator __first, _InputIterator __last)
00660         {
00661       // Check whether it's an integral type.  If so, it's not an iterator.
00662       typedef typename std::__is_integer<_InputIterator>::__type _Integral;
00663       _M_assign_dispatch(__first, __last, _Integral());
00664     }
00665 
00666 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00667       /**
00668        *  @brief  Assigns an initializer_list to a %list.
00669        *  @param  l  An initializer_list of value_type.
00670        *
00671        *  Replace the contents of the %list with copies of the elements
00672        *  in the initializer_list @a l.  This is linear in l.size().
00673        */
00674       void
00675       assign(initializer_list<value_type> __l)
00676       { this->assign(__l.begin(), __l.end()); }
00677 #endif
00678 
00679       /// Get a copy of the memory allocation object.
00680       allocator_type
00681       get_allocator() const
00682       { return _Base::get_allocator(); }
00683 
00684       // iterators
00685       /**
00686        *  Returns a read/write iterator that points to the first element in the
00687        *  %list.  Iteration is done in ordinary element order.
00688        */
00689       iterator
00690       begin()
00691       { return iterator(this->_M_impl._M_node._M_next); }
00692 
00693       /**
00694        *  Returns a read-only (constant) iterator that points to the
00695        *  first element in the %list.  Iteration is done in ordinary
00696        *  element order.
00697        */
00698       const_iterator
00699       begin() const
00700       { return const_iterator(this->_M_impl._M_node._M_next); }
00701 
00702       /**
00703        *  Returns a read/write iterator that points one past the last
00704        *  element in the %list.  Iteration is done in ordinary element
00705        *  order.
00706        */
00707       iterator
00708       end()
00709       { return iterator(&this->_M_impl._M_node); }
00710 
00711       /**
00712        *  Returns a read-only (constant) iterator that points one past
00713        *  the last element in the %list.  Iteration is done in ordinary
00714        *  element order.
00715        */
00716       const_iterator
00717       end() const
00718       { return const_iterator(&this->_M_impl._M_node); }
00719 
00720       /**
00721        *  Returns a read/write reverse iterator that points to the last
00722        *  element in the %list.  Iteration is done in reverse element
00723        *  order.
00724        */
00725       reverse_iterator
00726       rbegin()
00727       { return reverse_iterator(end()); }
00728 
00729       /**
00730        *  Returns a read-only (constant) reverse iterator that points to
00731        *  the last element in the %list.  Iteration is done in reverse
00732        *  element order.
00733        */
00734       const_reverse_iterator
00735       rbegin() const
00736       { return const_reverse_iterator(end()); }
00737 
00738       /**
00739        *  Returns a read/write reverse iterator that points to one
00740        *  before the first element in the %list.  Iteration is done in
00741        *  reverse element order.
00742        */
00743       reverse_iterator
00744       rend()
00745       { return reverse_iterator(begin()); }
00746 
00747       /**
00748        *  Returns a read-only (constant) reverse iterator that points to one
00749        *  before the first element in the %list.  Iteration is done in reverse
00750        *  element order.
00751        */
00752       const_reverse_iterator
00753       rend() const
00754       { return const_reverse_iterator(begin()); }
00755 
00756 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00757       /**
00758        *  Returns a read-only (constant) iterator that points to the
00759        *  first element in the %list.  Iteration is done in ordinary
00760        *  element order.
00761        */
00762       const_iterator
00763       cbegin() const
00764       { return const_iterator(this->_M_impl._M_node._M_next); }
00765 
00766       /**
00767        *  Returns a read-only (constant) iterator that points one past
00768        *  the last element in the %list.  Iteration is done in ordinary
00769        *  element order.
00770        */
00771       const_iterator
00772       cend() const
00773       { return const_iterator(&this->_M_impl._M_node); }
00774 
00775       /**
00776        *  Returns a read-only (constant) reverse iterator that points to
00777        *  the last element in the %list.  Iteration is done in reverse
00778        *  element order.
00779        */
00780       const_reverse_iterator
00781       crbegin() const
00782       { return const_reverse_iterator(end()); }
00783 
00784       /**
00785        *  Returns a read-only (constant) reverse iterator that points to one
00786        *  before the first element in the %list.  Iteration is done in reverse
00787        *  element order.
00788        */
00789       const_reverse_iterator
00790       crend() const
00791       { return const_reverse_iterator(begin()); }
00792 #endif
00793 
00794       // [23.2.2.2] capacity
00795       /**
00796        *  Returns true if the %list is empty.  (Thus begin() would equal
00797        *  end().)
00798        */
00799       bool
00800       empty() const
00801       { return this->_M_impl._M_node._M_next == &this->_M_impl._M_node; }
00802 
00803       /**  Returns the number of elements in the %list.  */
00804       size_type
00805       size() const
00806       { return std::distance(begin(), end()); }
00807 
00808       /**  Returns the size() of the largest possible %list.  */
00809       size_type
00810       max_size() const
00811       { return _M_get_Node_allocator().max_size(); }
00812 
00813       /**
00814        *  @brief Resizes the %list to the specified number of elements.
00815        *  @param new_size Number of elements the %list should contain.
00816        *  @param x Data with which new elements should be populated.
00817        *
00818        *  This function will %resize the %list to the specified number
00819        *  of elements.  If the number is smaller than the %list's
00820        *  current size the %list is truncated, otherwise the %list is
00821        *  extended and new elements are populated with given data.
00822        */
00823       void
00824       resize(size_type __new_size, value_type __x = value_type());
00825 
00826       // element access
00827       /**
00828        *  Returns a read/write reference to the data at the first
00829        *  element of the %list.
00830        */
00831       reference
00832       front()
00833       { return *begin(); }
00834 
00835       /**
00836        *  Returns a read-only (constant) reference to the data at the first
00837        *  element of the %list.
00838        */
00839       const_reference
00840       front() const
00841       { return *begin(); }
00842 
00843       /**
00844        *  Returns a read/write reference to the data at the last element
00845        *  of the %list.
00846        */
00847       reference
00848       back()
00849       { 
00850     iterator __tmp = end();
00851     --__tmp;
00852     return *__tmp;
00853       }
00854 
00855       /**
00856        *  Returns a read-only (constant) reference to the data at the last
00857        *  element of the %list.
00858        */
00859       const_reference
00860       back() const
00861       { 
00862     const_iterator __tmp = end();
00863     --__tmp;
00864     return *__tmp;
00865       }
00866 
00867       // [23.2.2.3] modifiers
00868       /**
00869        *  @brief  Add data to the front of the %list.
00870        *  @param  x  Data to be added.
00871        *
00872        *  This is a typical stack operation.  The function creates an
00873        *  element at the front of the %list and assigns the given data
00874        *  to it.  Due to the nature of a %list this operation can be
00875        *  done in constant time, and does not invalidate iterators and
00876        *  references.
00877        */
00878       void
00879       push_front(const value_type& __x)
00880       { this->_M_insert(begin(), __x); }
00881 
00882 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00883       void
00884       push_front(value_type&& __x)
00885       { this->_M_insert(begin(), std::move(__x)); }
00886 
00887       template<typename... _Args>
00888         void
00889         emplace_front(_Args&&... __args)
00890         { this->_M_insert(begin(), std::forward<_Args>(__args)...); }
00891 #endif
00892 
00893       /**
00894        *  @brief  Removes first element.
00895        *
00896        *  This is a typical stack operation.  It shrinks the %list by
00897        *  one.  Due to the nature of a %list this operation can be done
00898        *  in constant time, and only invalidates iterators/references to
00899        *  the element being removed.
00900        *
00901        *  Note that no data is returned, and if the first element's data
00902        *  is needed, it should be retrieved before pop_front() is
00903        *  called.
00904        */
00905       void
00906       pop_front()
00907       { this->_M_erase(begin()); }
00908 
00909       /**
00910        *  @brief  Add data to the end of the %list.
00911        *  @param  x  Data to be added.
00912        *
00913        *  This is a typical stack operation.  The function creates an
00914        *  element at the end of the %list and assigns the given data to
00915        *  it.  Due to the nature of a %list this operation can be done
00916        *  in constant time, and does not invalidate iterators and
00917        *  references.
00918        */
00919       void
00920       push_back(const value_type& __x)
00921       { this->_M_insert(end(), __x); }
00922 
00923 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00924       void
00925       push_back(value_type&& __x)
00926       { this->_M_insert(end(), std::move(__x)); }
00927 
00928       template<typename... _Args>
00929         void
00930         emplace_back(_Args&&... __args)
00931         { this->_M_insert(end(), std::forward<_Args>(__args)...); }
00932 #endif
00933 
00934       /**
00935        *  @brief  Removes last element.
00936        *
00937        *  This is a typical stack operation.  It shrinks the %list by
00938        *  one.  Due to the nature of a %list this operation can be done
00939        *  in constant time, and only invalidates iterators/references to
00940        *  the element being removed.
00941        *
00942        *  Note that no data is returned, and if the last element's data
00943        *  is needed, it should be retrieved before pop_back() is called.
00944        */
00945       void
00946       pop_back()
00947       { this->_M_erase(iterator(this->_M_impl._M_node._M_prev)); }
00948 
00949 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00950       /**
00951        *  @brief  Constructs object in %list before specified iterator.
00952        *  @param  position  A const_iterator into the %list.
00953        *  @param  args  Arguments.
00954        *  @return  An iterator that points to the inserted data.
00955        *
00956        *  This function will insert an object of type T constructed
00957        *  with T(std::forward<Args>(args)...) before the specified
00958        *  location.  Due to the nature of a %list this operation can
00959        *  be done in constant time, and does not invalidate iterators
00960        *  and references.
00961        */
00962       template<typename... _Args>
00963         iterator
00964         emplace(iterator __position, _Args&&... __args);
00965 #endif
00966 
00967       /**
00968        *  @brief  Inserts given value into %list before specified iterator.
00969        *  @param  position  An iterator into the %list.
00970        *  @param  x  Data to be inserted.
00971        *  @return  An iterator that points to the inserted data.
00972        *
00973        *  This function will insert a copy of the given value before
00974        *  the specified location.  Due to the nature of a %list this
00975        *  operation can be done in constant time, and does not
00976        *  invalidate iterators and references.
00977        */
00978       iterator
00979       insert(iterator __position, const value_type& __x);
00980 
00981 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00982       /**
00983        *  @brief  Inserts given rvalue into %list before specified iterator.
00984        *  @param  position  An iterator into the %list.
00985        *  @param  x  Data to be inserted.
00986        *  @return  An iterator that points to the inserted data.
00987        *
00988        *  This function will insert a copy of the given rvalue before
00989        *  the specified location.  Due to the nature of a %list this
00990        *  operation can be done in constant time, and does not
00991        *  invalidate iterators and references.
00992         */
00993       iterator
00994       insert(iterator __position, value_type&& __x)
00995       { return emplace(__position, std::move(__x)); }
00996 
00997       /**
00998        *  @brief  Inserts the contents of an initializer_list into %list
00999        *          before specified iterator.
01000        *  @param  p  An iterator into the %list.
01001        *  @param  l  An initializer_list of value_type.
01002        *
01003        *  This function will insert copies of the data in the
01004        *  initializer_list @a l into the %list before the location
01005        *  specified by @a p.
01006        *
01007        *  This operation is linear in the number of elements inserted and
01008        *  does not invalidate iterators and references.
01009        */
01010       void
01011       insert(iterator __p, initializer_list<value_type> __l)
01012       { this->insert(__p, __l.begin(), __l.end()); }
01013 #endif
01014 
01015       /**
01016        *  @brief  Inserts a number of copies of given data into the %list.
01017        *  @param  position  An iterator into the %list.
01018        *  @param  n  Number of elements to be inserted.
01019        *  @param  x  Data to be inserted.
01020        *
01021        *  This function will insert a specified number of copies of the
01022        *  given data before the location specified by @a position.
01023        *
01024        *  This operation is linear in the number of elements inserted and
01025        *  does not invalidate iterators and references.
01026        */
01027       void
01028       insert(iterator __position, size_type __n, const value_type& __x)
01029       {  
01030     list __tmp(__n, __x, _M_get_Node_allocator());
01031     splice(__position, __tmp);
01032       }
01033 
01034       /**
01035        *  @brief  Inserts a range into the %list.
01036        *  @param  position  An iterator into the %list.
01037        *  @param  first  An input iterator.
01038        *  @param  last   An input iterator.
01039        *
01040        *  This function will insert copies of the data in the range [@a
01041        *  first,@a last) into the %list before the location specified by
01042        *  @a position.
01043        *
01044        *  This operation is linear in the number of elements inserted and
01045        *  does not invalidate iterators and references.
01046        */
01047       template<typename _InputIterator>
01048         void
01049         insert(iterator __position, _InputIterator __first,
01050            _InputIterator __last)
01051         {
01052       list __tmp(__first, __last, _M_get_Node_allocator());
01053       splice(__position, __tmp);
01054     }
01055 
01056       /**
01057        *  @brief  Remove element at given position.
01058        *  @param  position  Iterator pointing to element to be erased.
01059        *  @return  An iterator pointing to the next element (or end()).
01060        *
01061        *  This function will erase the element at the given position and thus
01062        *  shorten the %list by one.
01063        *
01064        *  Due to the nature of a %list this operation can be done in
01065        *  constant time, and only invalidates iterators/references to
01066        *  the element being removed.  The user is also cautioned that
01067        *  this function only erases the element, and that if the element
01068        *  is itself a pointer, the pointed-to memory is not touched in
01069        *  any way.  Managing the pointer is the user's responsibility.
01070        */
01071       iterator
01072       erase(iterator __position);
01073 
01074       /**
01075        *  @brief  Remove a range of elements.
01076        *  @param  first  Iterator pointing to the first element to be erased.
01077        *  @param  last  Iterator pointing to one past the last element to be
01078        *                erased.
01079        *  @return  An iterator pointing to the element pointed to by @a last
01080        *           prior to erasing (or end()).
01081        *
01082        *  This function will erase the elements in the range @a
01083        *  [first,last) and shorten the %list accordingly.
01084        *
01085        *  This operation is linear time in the size of the range and only
01086        *  invalidates iterators/references to the element being removed.
01087        *  The user is also cautioned that this function only erases the
01088        *  elements, and that if the elements themselves are pointers, the
01089        *  pointed-to memory is not touched in any way.  Managing the pointer
01090        *  is the user's responsibility.
01091        */
01092       iterator
01093       erase(iterator __first, iterator __last)
01094       {
01095     while (__first != __last)
01096       __first = erase(__first);
01097     return __last;
01098       }
01099 
01100       /**
01101        *  @brief  Swaps data with another %list.
01102        *  @param  x  A %list of the same element and allocator types.
01103        *
01104        *  This exchanges the elements between two lists in constant
01105        *  time.  Note that the global std::swap() function is
01106        *  specialized such that std::swap(l1,l2) will feed to this
01107        *  function.
01108        */
01109       void
01110       swap(list& __x)
01111       {
01112     _List_node_base::swap(this->_M_impl._M_node, __x._M_impl._M_node);
01113 
01114     // _GLIBCXX_RESOLVE_LIB_DEFECTS
01115     // 431. Swapping containers with unequal allocators.
01116     std::__alloc_swap<typename _Base::_Node_alloc_type>::
01117       _S_do_it(_M_get_Node_allocator(), __x._M_get_Node_allocator());
01118       }
01119 
01120       /**
01121        *  Erases all the elements.  Note that this function only erases
01122        *  the elements, and that if the elements themselves are
01123        *  pointers, the pointed-to memory is not touched in any way.
01124        *  Managing the pointer is the user's responsibility.
01125        */
01126       void
01127       clear()
01128       {
01129         _Base::_M_clear();
01130         _Base::_M_init();
01131       }
01132 
01133       // [23.2.2.4] list operations
01134       /**
01135        *  @brief  Insert contents of another %list.
01136        *  @param  position  Iterator referencing the element to insert before.
01137        *  @param  x  Source list.
01138        *
01139        *  The elements of @a x are inserted in constant time in front of
01140        *  the element referenced by @a position.  @a x becomes an empty
01141        *  list.
01142        *
01143        *  Requires this != @a x.
01144        */
01145       void
01146 #ifdef __GXX_EXPERIMENTAL_CXX0X__
01147       splice(iterator __position, list&& __x)
01148 #else
01149       splice(iterator __position, list& __x)
01150 #endif
01151       {
01152     if (!__x.empty())
01153       {
01154         _M_check_equal_allocators(__x);
01155 
01156         this->_M_transfer(__position, __x.begin(), __x.end());
01157       }
01158       }
01159 
01160 #ifdef __GXX_EXPERIMENTAL_CXX0X__
01161       void
01162       splice(iterator __position, list& __x)
01163       { splice(__position, std::move(__x)); }
01164 #endif
01165 
01166       /**
01167        *  @brief  Insert element from another %list.
01168        *  @param  position  Iterator referencing the element to insert before.
01169        *  @param  x  Source list.
01170        *  @param  i  Iterator referencing the element to move.
01171        *
01172        *  Removes the element in list @a x referenced by @a i and
01173        *  inserts it into the current list before @a position.
01174        */
01175       void
01176 #ifdef __GXX_EXPERIMENTAL_CXX0X__
01177       splice(iterator __position, list&& __x, iterator __i)
01178 #else
01179       splice(iterator __position, list& __x, iterator __i)
01180 #endif
01181       {
01182     iterator __j = __i;
01183     ++__j;
01184     if (__position == __i || __position == __j)
01185       return;
01186 
01187     if (this != &__x)
01188       _M_check_equal_allocators(__x);
01189 
01190     this->_M_transfer(__position, __i, __j);
01191       }
01192 
01193 #ifdef __GXX_EXPERIMENTAL_CXX0X__
01194       void
01195       splice(iterator __position, list& __x, iterator __i)
01196       { splice(__position, std::move(__x), __i); }
01197 #endif
01198 
01199       /**
01200        *  @brief  Insert range from another %list.
01201        *  @param  position  Iterator referencing the element to insert before.
01202        *  @param  x  Source list.
01203        *  @param  first  Iterator referencing the start of range in x.
01204        *  @param  last  Iterator referencing the end of range in x.
01205        *
01206        *  Removes elements in the range [first,last) and inserts them
01207        *  before @a position in constant time.
01208        *
01209        *  Undefined if @a position is in [first,last).
01210        */
01211       void
01212 #ifdef __GXX_EXPERIMENTAL_CXX0X__
01213       splice(iterator __position, list&& __x, iterator __first,
01214          iterator __last)
01215 #else
01216       splice(iterator __position, list& __x, iterator __first,
01217          iterator __last)
01218 #endif
01219       {
01220     if (__first != __last)
01221       {
01222         if (this != &__x)
01223           _M_check_equal_allocators(__x);
01224 
01225         this->_M_transfer(__position, __first, __last);
01226       }
01227       }
01228 
01229 #ifdef __GXX_EXPERIMENTAL_CXX0X__
01230       void
01231       splice(iterator __position, list& __x, iterator __first, iterator __last)
01232       { splice(__position, std::move(__x), __first, __last); }
01233 #endif
01234 
01235       /**
01236        *  @brief  Remove all elements equal to value.
01237        *  @param  value  The value to remove.
01238        *
01239        *  Removes every element in the list equal to @a value.
01240        *  Remaining elements stay in list order.  Note that this
01241        *  function only erases the elements, and that if the elements
01242        *  themselves are pointers, the pointed-to memory is not
01243        *  touched in any way.  Managing the pointer is the user's
01244        *  responsibility.
01245        */
01246       void
01247       remove(const _Tp& __value);
01248 
01249       /**
01250        *  @brief  Remove all elements satisfying a predicate.
01251        *  @param  Predicate  Unary predicate function or object.
01252        *
01253        *  Removes every element in the list for which the predicate
01254        *  returns true.  Remaining elements stay in list order.  Note
01255        *  that this function only erases the elements, and that if the
01256        *  elements themselves are pointers, the pointed-to memory is
01257        *  not touched in any way.  Managing the pointer is the user's
01258        *  responsibility.
01259        */
01260       template<typename _Predicate>
01261         void
01262         remove_if(_Predicate);
01263 
01264       /**
01265        *  @brief  Remove consecutive duplicate elements.
01266        *
01267        *  For each consecutive set of elements with the same value,
01268        *  remove all but the first one.  Remaining elements stay in
01269        *  list order.  Note that this function only erases the
01270        *  elements, and that if the elements themselves are pointers,
01271        *  the pointed-to memory is not touched in any way.  Managing
01272        *  the pointer is the user's responsibility.
01273        */
01274       void
01275       unique();
01276 
01277       /**
01278        *  @brief  Remove consecutive elements satisfying a predicate.
01279        *  @param  BinaryPredicate  Binary predicate function or object.
01280        *
01281        *  For each consecutive set of elements [first,last) that
01282        *  satisfy predicate(first,i) where i is an iterator in
01283        *  [first,last), remove all but the first one.  Remaining
01284        *  elements stay in list order.  Note that this function only
01285        *  erases the elements, and that if the elements themselves are
01286        *  pointers, the pointed-to memory is not touched in any way.
01287        *  Managing the pointer is the user's responsibility.
01288        */
01289       template<typename _BinaryPredicate>
01290         void
01291         unique(_BinaryPredicate);
01292 
01293       /**
01294        *  @brief  Merge sorted lists.
01295        *  @param  x  Sorted list to merge.
01296        *
01297        *  Assumes that both @a x and this list are sorted according to
01298        *  operator<().  Merges elements of @a x into this list in
01299        *  sorted order, leaving @a x empty when complete.  Elements in
01300        *  this list precede elements in @a x that are equal.
01301        */
01302 #ifdef __GXX_EXPERIMENTAL_CXX0X__
01303       void
01304       merge(list&& __x);
01305 
01306       void
01307       merge(list& __x)
01308       { merge(std::move(__x)); }
01309 #else
01310       void
01311       merge(list& __x);
01312 #endif
01313 
01314       /**
01315        *  @brief  Merge sorted lists according to comparison function.
01316        *  @param  x  Sorted list to merge.
01317        *  @param StrictWeakOrdering Comparison function defining
01318        *  sort order.
01319        *
01320        *  Assumes that both @a x and this list are sorted according to
01321        *  StrictWeakOrdering.  Merges elements of @a x into this list
01322        *  in sorted order, leaving @a x empty when complete.  Elements
01323        *  in this list precede elements in @a x that are equivalent
01324        *  according to StrictWeakOrdering().
01325        */
01326 #ifdef __GXX_EXPERIMENTAL_CXX0X__
01327       template<typename _StrictWeakOrdering>
01328         void
01329         merge(list&&, _StrictWeakOrdering);
01330 
01331       template<typename _StrictWeakOrdering>
01332         void
01333         merge(list& __x, _StrictWeakOrdering __comp)
01334         { merge(std::move(__x), __comp); }
01335 #else
01336       template<typename _StrictWeakOrdering>
01337         void
01338         merge(list&, _StrictWeakOrdering);
01339 #endif
01340 
01341       /**
01342        *  @brief  Reverse the elements in list.
01343        *
01344        *  Reverse the order of elements in the list in linear time.
01345        */
01346       void
01347       reverse()
01348       { this->_M_impl._M_node._M_reverse(); }
01349 
01350       /**
01351        *  @brief  Sort the elements.
01352        *
01353        *  Sorts the elements of this list in NlogN time.  Equivalent
01354        *  elements remain in list order.
01355        */
01356       void
01357       sort();
01358 
01359       /**
01360        *  @brief  Sort the elements according to comparison function.
01361        *
01362        *  Sorts the elements of this list in NlogN time.  Equivalent
01363        *  elements remain in list order.
01364        */
01365       template<typename _StrictWeakOrdering>
01366         void
01367         sort(_StrictWeakOrdering);
01368 
01369     protected:
01370       // Internal constructor functions follow.
01371 
01372       // Called by the range constructor to implement [23.1.1]/9
01373 
01374       // _GLIBCXX_RESOLVE_LIB_DEFECTS
01375       // 438. Ambiguity in the "do the right thing" clause
01376       template<typename _Integer>
01377         void
01378         _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type)
01379         { _M_fill_initialize(static_cast<size_type>(__n), __x); }
01380 
01381       // Called by the range constructor to implement [23.1.1]/9
01382       template<typename _InputIterator>
01383         void
01384         _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
01385                    __false_type)
01386         {
01387       for (; __first != __last; ++__first)
01388         push_back(*__first);
01389     }
01390 
01391       // Called by list(n,v,a), and the range constructor when it turns out
01392       // to be the same thing.
01393       void
01394       _M_fill_initialize(size_type __n, const value_type& __x)
01395       {
01396     for (; __n > 0; --__n)
01397       push_back(__x);
01398       }
01399 
01400 
01401       // Internal assign functions follow.
01402 
01403       // Called by the range assign to implement [23.1.1]/9
01404 
01405       // _GLIBCXX_RESOLVE_LIB_DEFECTS
01406       // 438. Ambiguity in the "do the right thing" clause
01407       template<typename _Integer>
01408         void
01409         _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
01410         { _M_fill_assign(__n, __val); }
01411 
01412       // Called by the range assign to implement [23.1.1]/9
01413       template<typename _InputIterator>
01414         void
01415         _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
01416                __false_type);
01417 
01418       // Called by assign(n,t), and the range assign when it turns out
01419       // to be the same thing.
01420       void
01421       _M_fill_assign(size_type __n, const value_type& __val);
01422 
01423 
01424       // Moves the elements from [first,last) before position.
01425       void
01426       _M_transfer(iterator __position, iterator __first, iterator __last)
01427       { __position._M_node->_M_transfer(__first._M_node, __last._M_node); }
01428 
01429       // Inserts new element at position given and with value given.
01430 #ifndef __GXX_EXPERIMENTAL_CXX0X__
01431       void
01432       _M_insert(iterator __position, const value_type& __x)
01433       {
01434         _Node* __tmp = _M_create_node(__x);
01435         __tmp->_M_hook(__position._M_node);
01436       }
01437 #else
01438      template<typename... _Args>
01439        void
01440        _M_insert(iterator __position, _Args&&... __args)
01441        {
01442      _Node* __tmp = _M_create_node(std::forward<_Args>(__args)...);
01443      __tmp->_M_hook(__position._M_node);
01444        }
01445 #endif
01446 
01447       // Erases element at position given.
01448       void
01449       _M_erase(iterator __position)
01450       {
01451         __position._M_node->_M_unhook();
01452         _Node* __n = static_cast<_Node*>(__position._M_node);
01453 #ifdef __GXX_EXPERIMENTAL_CXX0X__
01454         _M_get_Node_allocator().destroy(__n);
01455 #else
01456     _M_get_Tp_allocator().destroy(&__n->_M_data);
01457 #endif
01458         _M_put_node(__n);
01459       }
01460 
01461       // To implement the splice (and merge) bits of N1599.
01462       void
01463       _M_check_equal_allocators(list& __x)
01464       {
01465     if (std::__alloc_neq<typename _Base::_Node_alloc_type>::
01466         _S_do_it(_M_get_Node_allocator(), __x._M_get_Node_allocator()))
01467       __throw_runtime_error(__N("list::_M_check_equal_allocators"));
01468       }
01469     };
01470 
01471   /**
01472    *  @brief  List equality comparison.
01473    *  @param  x  A %list.
01474    *  @param  y  A %list of the same type as @a x.
01475    *  @return  True iff the size and elements of the lists are equal.
01476    *
01477    *  This is an equivalence relation.  It is linear in the size of
01478    *  the lists.  Lists are considered equivalent if their sizes are
01479    *  equal, and if corresponding elements compare equal.
01480   */
01481   template<typename _Tp, typename _Alloc>
01482     inline bool
01483     operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
01484     {
01485       typedef typename list<_Tp, _Alloc>::const_iterator const_iterator;
01486       const_iterator __end1 = __x.end();
01487       const_iterator __end2 = __y.end();
01488 
01489       const_iterator __i1 = __x.begin();
01490       const_iterator __i2 = __y.begin();
01491       while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
01492     {
01493       ++__i1;
01494       ++__i2;
01495     }
01496       return __i1 == __end1 && __i2 == __end2;
01497     }
01498 
01499   /**
01500    *  @brief  List ordering relation.
01501    *  @param  x  A %list.
01502    *  @param  y  A %list of the same type as @a x.
01503    *  @return  True iff @a x is lexicographically less than @a y.
01504    *
01505    *  This is a total ordering relation.  It is linear in the size of the
01506    *  lists.  The elements must be comparable with @c <.
01507    *
01508    *  See std::lexicographical_compare() for how the determination is made.
01509   */
01510   template<typename _Tp, typename _Alloc>
01511     inline bool
01512     operator<(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
01513     { return std::lexicographical_compare(__x.begin(), __x.end(),
01514                       __y.begin(), __y.end()); }
01515 
01516   /// Based on operator==
01517   template<typename _Tp, typename _Alloc>
01518     inline bool
01519     operator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
01520     { return !(__x == __y); }
01521 
01522   /// Based on operator<
01523   template<typename _Tp, typename _Alloc>
01524     inline bool
01525     operator>(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
01526     { return __y < __x; }
01527 
01528   /// Based on operator<
01529   template<typename _Tp, typename _Alloc>
01530     inline bool
01531     operator<=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
01532     { return !(__y < __x); }
01533 
01534   /// Based on operator<
01535   template<typename _Tp, typename _Alloc>
01536     inline bool
01537     operator>=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
01538     { return !(__x < __y); }
01539 
01540   /// See std::list::swap().
01541   template<typename _Tp, typename _Alloc>
01542     inline void
01543     swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y)
01544     { __x.swap(__y); }
01545 
01546 _GLIBCXX_END_NESTED_NAMESPACE
01547 
01548 #endif /* _STL_LIST_H */