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 std::__addressof(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 std::__addressof(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
00465           (std::__addressof(__p->_M_data), __x);
00466       }
00467     __catch(...)
00468       {
00469         _M_put_node(__p);
00470         __throw_exception_again;
00471       }
00472     return __p;
00473       }
00474 #else
00475       template<typename... _Args>
00476         _Node*
00477         _M_create_node(_Args&&... __args)
00478     {
00479       _Node* __p = this->_M_get_node();
00480       __try
00481         {
00482           _M_get_Node_allocator().construct(__p,
00483                         std::forward<_Args>(__args)...);
00484         }
00485       __catch(...)
00486         {
00487           _M_put_node(__p);
00488           __throw_exception_again;
00489         }
00490       return __p;
00491     }
00492 #endif
00493 
00494     public:
00495       // [23.2.2.1] construct/copy/destroy
00496       // (assign() and get_allocator() are also listed in this section)
00497       /**
00498        *  @brief  Default constructor creates no elements.
00499        */
00500       list()
00501       : _Base() { }
00502 
00503       /**
00504        *  @brief  Creates a %list with no elements.
00505        *  @param  a  An allocator object.
00506        */
00507       explicit
00508       list(const allocator_type& __a)
00509       : _Base(__a) { }
00510 
00511 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00512       /**
00513        *  @brief  Creates a %list with default constructed elements.
00514        *  @param  n  The number of elements to initially create.
00515        *
00516        *  This constructor fills the %list with @a n default
00517        *  constructed elements.
00518        */
00519       explicit
00520       list(size_type __n)
00521       : _Base()
00522       { _M_default_initialize(__n); }
00523 
00524       /**
00525        *  @brief  Creates a %list with copies of an exemplar element.
00526        *  @param  n  The number of elements to initially create.
00527        *  @param  value  An element to copy.
00528        *  @param  a  An allocator object.
00529        *
00530        *  This constructor fills the %list with @a n copies of @a value.
00531        */
00532       list(size_type __n, const value_type& __value,
00533        const allocator_type& __a = allocator_type())
00534       : _Base(__a)
00535       { _M_fill_initialize(__n, __value); }
00536 #else
00537       /**
00538        *  @brief  Creates a %list with copies of an exemplar element.
00539        *  @param  n  The number of elements to initially create.
00540        *  @param  value  An element to copy.
00541        *  @param  a  An allocator object.
00542        *
00543        *  This constructor fills the %list with @a n copies of @a value.
00544        */
00545       explicit
00546       list(size_type __n, const value_type& __value = value_type(),
00547        const allocator_type& __a = allocator_type())
00548       : _Base(__a)
00549       { _M_fill_initialize(__n, __value); }
00550 #endif
00551 
00552       /**
00553        *  @brief  %List copy constructor.
00554        *  @param  x  A %list of identical element and allocator types.
00555        *
00556        *  The newly-created %list uses a copy of the allocation object used
00557        *  by @a x.
00558        */
00559       list(const list& __x)
00560       : _Base(__x._M_get_Node_allocator())
00561       { _M_initialize_dispatch(__x.begin(), __x.end(), __false_type()); }
00562 
00563 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00564       /**
00565        *  @brief  %List move constructor.
00566        *  @param  x  A %list of identical element and allocator types.
00567        *
00568        *  The newly-created %list contains the exact contents of @a x.
00569        *  The contents of @a x are a valid, but unspecified %list.
00570        */
00571       list(list&& __x)
00572       : _Base(std::move(__x)) { }
00573 
00574       /**
00575        *  @brief  Builds a %list from an initializer_list
00576        *  @param  l  An initializer_list of value_type.
00577        *  @param  a  An allocator object.
00578        *
00579        *  Create a %list consisting of copies of the elements in the
00580        *  initializer_list @a l.  This is linear in l.size().
00581        */
00582       list(initializer_list<value_type> __l,
00583            const allocator_type& __a = allocator_type())
00584       : _Base(__a)
00585       { _M_initialize_dispatch(__l.begin(), __l.end(), __false_type()); }
00586 #endif
00587 
00588       /**
00589        *  @brief  Builds a %list from a range.
00590        *  @param  first  An input iterator.
00591        *  @param  last  An input iterator.
00592        *  @param  a  An allocator object.
00593        *
00594        *  Create a %list consisting of copies of the elements from
00595        *  [@a first,@a last).  This is linear in N (where N is
00596        *  distance(@a first,@a last)).
00597        */
00598       template<typename _InputIterator>
00599         list(_InputIterator __first, _InputIterator __last,
00600          const allocator_type& __a = allocator_type())
00601         : _Base(__a)
00602         { 
00603       // Check whether it's an integral type.  If so, it's not an iterator.
00604       typedef typename std::__is_integer<_InputIterator>::__type _Integral;
00605       _M_initialize_dispatch(__first, __last, _Integral());
00606     }
00607 
00608       /**
00609        *  No explicit dtor needed as the _Base dtor takes care of
00610        *  things.  The _Base dtor only erases the elements, and note
00611        *  that if the elements themselves are pointers, the pointed-to
00612        *  memory is not touched in any way.  Managing the pointer is
00613        *  the user's responsibility.
00614        */
00615 
00616       /**
00617        *  @brief  %List assignment operator.
00618        *  @param  x  A %list of identical element and allocator types.
00619        *
00620        *  All the elements of @a x are copied, but unlike the copy
00621        *  constructor, the allocator object is not copied.
00622        */
00623       list&
00624       operator=(const list& __x);
00625 
00626 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00627       /**
00628        *  @brief  %List move assignment operator.
00629        *  @param  x  A %list of identical element and allocator types.
00630        *
00631        *  The contents of @a x are moved into this %list (without copying).
00632        *  @a x is a valid, but unspecified %list
00633        */
00634       list&
00635       operator=(list&& __x)
00636       {
00637     // NB: DR 1204.
00638     // NB: DR 675.
00639     this->clear();
00640     this->swap(__x);
00641     return *this;
00642       }
00643 
00644       /**
00645        *  @brief  %List initializer list assignment operator.
00646        *  @param  l  An initializer_list of value_type.
00647        *
00648        *  Replace the contents of the %list with copies of the elements
00649        *  in the initializer_list @a l.  This is linear in l.size().
00650        */
00651       list&
00652       operator=(initializer_list<value_type> __l)
00653       {
00654     this->assign(__l.begin(), __l.end());
00655     return *this;
00656       }
00657 #endif
00658 
00659       /**
00660        *  @brief  Assigns a given value to a %list.
00661        *  @param  n  Number of elements to be assigned.
00662        *  @param  val  Value to be assigned.
00663        *
00664        *  This function fills a %list with @a n copies of the given
00665        *  value.  Note that the assignment completely changes the %list
00666        *  and that the resulting %list's size is the same as the number
00667        *  of elements assigned.  Old data may be lost.
00668        */
00669       void
00670       assign(size_type __n, const value_type& __val)
00671       { _M_fill_assign(__n, __val); }
00672 
00673       /**
00674        *  @brief  Assigns a range to a %list.
00675        *  @param  first  An input iterator.
00676        *  @param  last   An input iterator.
00677        *
00678        *  This function fills a %list with copies of the elements in the
00679        *  range [@a first,@a last).
00680        *
00681        *  Note that the assignment completely changes the %list and
00682        *  that the resulting %list's size is the same as the number of
00683        *  elements assigned.  Old data may be lost.
00684        */
00685       template<typename _InputIterator>
00686         void
00687         assign(_InputIterator __first, _InputIterator __last)
00688         {
00689       // Check whether it's an integral type.  If so, it's not an iterator.
00690       typedef typename std::__is_integer<_InputIterator>::__type _Integral;
00691       _M_assign_dispatch(__first, __last, _Integral());
00692     }
00693 
00694 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00695       /**
00696        *  @brief  Assigns an initializer_list to a %list.
00697        *  @param  l  An initializer_list of value_type.
00698        *
00699        *  Replace the contents of the %list with copies of the elements
00700        *  in the initializer_list @a l.  This is linear in l.size().
00701        */
00702       void
00703       assign(initializer_list<value_type> __l)
00704       { this->assign(__l.begin(), __l.end()); }
00705 #endif
00706 
00707       /// Get a copy of the memory allocation object.
00708       allocator_type
00709       get_allocator() const
00710       { return _Base::get_allocator(); }
00711 
00712       // iterators
00713       /**
00714        *  Returns a read/write iterator that points to the first element in the
00715        *  %list.  Iteration is done in ordinary element order.
00716        */
00717       iterator
00718       begin()
00719       { return iterator(this->_M_impl._M_node._M_next); }
00720 
00721       /**
00722        *  Returns a read-only (constant) iterator that points to the
00723        *  first element in the %list.  Iteration is done in ordinary
00724        *  element order.
00725        */
00726       const_iterator
00727       begin() const
00728       { return const_iterator(this->_M_impl._M_node._M_next); }
00729 
00730       /**
00731        *  Returns a read/write iterator that points one past the last
00732        *  element in the %list.  Iteration is done in ordinary element
00733        *  order.
00734        */
00735       iterator
00736       end()
00737       { return iterator(&this->_M_impl._M_node); }
00738 
00739       /**
00740        *  Returns a read-only (constant) iterator that points one past
00741        *  the last element in the %list.  Iteration is done in ordinary
00742        *  element order.
00743        */
00744       const_iterator
00745       end() const
00746       { return const_iterator(&this->_M_impl._M_node); }
00747 
00748       /**
00749        *  Returns a read/write reverse iterator that points to the last
00750        *  element in the %list.  Iteration is done in reverse element
00751        *  order.
00752        */
00753       reverse_iterator
00754       rbegin()
00755       { return reverse_iterator(end()); }
00756 
00757       /**
00758        *  Returns a read-only (constant) reverse iterator that points to
00759        *  the last element in the %list.  Iteration is done in reverse
00760        *  element order.
00761        */
00762       const_reverse_iterator
00763       rbegin() const
00764       { return const_reverse_iterator(end()); }
00765 
00766       /**
00767        *  Returns a read/write reverse iterator that points to one
00768        *  before the first element in the %list.  Iteration is done in
00769        *  reverse element order.
00770        */
00771       reverse_iterator
00772       rend()
00773       { return reverse_iterator(begin()); }
00774 
00775       /**
00776        *  Returns a read-only (constant) reverse iterator that points to one
00777        *  before the first element in the %list.  Iteration is done in reverse
00778        *  element order.
00779        */
00780       const_reverse_iterator
00781       rend() const
00782       { return const_reverse_iterator(begin()); }
00783 
00784 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00785       /**
00786        *  Returns a read-only (constant) iterator that points to the
00787        *  first element in the %list.  Iteration is done in ordinary
00788        *  element order.
00789        */
00790       const_iterator
00791       cbegin() const
00792       { return const_iterator(this->_M_impl._M_node._M_next); }
00793 
00794       /**
00795        *  Returns a read-only (constant) iterator that points one past
00796        *  the last element in the %list.  Iteration is done in ordinary
00797        *  element order.
00798        */
00799       const_iterator
00800       cend() const
00801       { return const_iterator(&this->_M_impl._M_node); }
00802 
00803       /**
00804        *  Returns a read-only (constant) reverse iterator that points to
00805        *  the last element in the %list.  Iteration is done in reverse
00806        *  element order.
00807        */
00808       const_reverse_iterator
00809       crbegin() const
00810       { return const_reverse_iterator(end()); }
00811 
00812       /**
00813        *  Returns a read-only (constant) reverse iterator that points to one
00814        *  before the first element in the %list.  Iteration is done in reverse
00815        *  element order.
00816        */
00817       const_reverse_iterator
00818       crend() const
00819       { return const_reverse_iterator(begin()); }
00820 #endif
00821 
00822       // [23.2.2.2] capacity
00823       /**
00824        *  Returns true if the %list is empty.  (Thus begin() would equal
00825        *  end().)
00826        */
00827       bool
00828       empty() const
00829       { return this->_M_impl._M_node._M_next == &this->_M_impl._M_node; }
00830 
00831       /**  Returns the number of elements in the %list.  */
00832       size_type
00833       size() const
00834       { return std::distance(begin(), end()); }
00835 
00836       /**  Returns the size() of the largest possible %list.  */
00837       size_type
00838       max_size() const
00839       { return _M_get_Node_allocator().max_size(); }
00840 
00841 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00842       /**
00843        *  @brief Resizes the %list to the specified number of elements.
00844        *  @param new_size Number of elements the %list should contain.
00845        *
00846        *  This function will %resize the %list to the specified number
00847        *  of elements.  If the number is smaller than the %list's
00848        *  current size the %list is truncated, otherwise default
00849        *  constructed elements are appended.
00850        */
00851       void
00852       resize(size_type __new_size);
00853 
00854       /**
00855        *  @brief Resizes the %list to the specified number of elements.
00856        *  @param new_size Number of elements the %list should contain.
00857        *  @param x Data with which new elements should be populated.
00858        *
00859        *  This function will %resize the %list to the specified number
00860        *  of elements.  If the number is smaller than the %list's
00861        *  current size the %list is truncated, otherwise the %list is
00862        *  extended and new elements are populated with given data.
00863        */
00864       void
00865       resize(size_type __new_size, const value_type& __x);
00866 #else
00867       /**
00868        *  @brief Resizes the %list to the specified number of elements.
00869        *  @param new_size Number of elements the %list should contain.
00870        *  @param x Data with which new elements should be populated.
00871        *
00872        *  This function will %resize the %list to the specified number
00873        *  of elements.  If the number is smaller than the %list's
00874        *  current size the %list is truncated, otherwise the %list is
00875        *  extended and new elements are populated with given data.
00876        */
00877       void
00878       resize(size_type __new_size, value_type __x = value_type());
00879 #endif
00880 
00881       // element access
00882       /**
00883        *  Returns a read/write reference to the data at the first
00884        *  element of the %list.
00885        */
00886       reference
00887       front()
00888       { return *begin(); }
00889 
00890       /**
00891        *  Returns a read-only (constant) reference to the data at the first
00892        *  element of the %list.
00893        */
00894       const_reference
00895       front() const
00896       { return *begin(); }
00897 
00898       /**
00899        *  Returns a read/write reference to the data at the last element
00900        *  of the %list.
00901        */
00902       reference
00903       back()
00904       { 
00905     iterator __tmp = end();
00906     --__tmp;
00907     return *__tmp;
00908       }
00909 
00910       /**
00911        *  Returns a read-only (constant) reference to the data at the last
00912        *  element of the %list.
00913        */
00914       const_reference
00915       back() const
00916       { 
00917     const_iterator __tmp = end();
00918     --__tmp;
00919     return *__tmp;
00920       }
00921 
00922       // [23.2.2.3] modifiers
00923       /**
00924        *  @brief  Add data to the front of the %list.
00925        *  @param  x  Data to be added.
00926        *
00927        *  This is a typical stack operation.  The function creates an
00928        *  element at the front of the %list and assigns the given data
00929        *  to it.  Due to the nature of a %list this operation can be
00930        *  done in constant time, and does not invalidate iterators and
00931        *  references.
00932        */
00933       void
00934       push_front(const value_type& __x)
00935       { this->_M_insert(begin(), __x); }
00936 
00937 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00938       void
00939       push_front(value_type&& __x)
00940       { this->_M_insert(begin(), std::move(__x)); }
00941 
00942       template<typename... _Args>
00943         void
00944         emplace_front(_Args&&... __args)
00945         { this->_M_insert(begin(), std::forward<_Args>(__args)...); }
00946 #endif
00947 
00948       /**
00949        *  @brief  Removes first element.
00950        *
00951        *  This is a typical stack operation.  It shrinks the %list by
00952        *  one.  Due to the nature of a %list this operation can be done
00953        *  in constant time, and only invalidates iterators/references to
00954        *  the element being removed.
00955        *
00956        *  Note that no data is returned, and if the first element's data
00957        *  is needed, it should be retrieved before pop_front() is
00958        *  called.
00959        */
00960       void
00961       pop_front()
00962       { this->_M_erase(begin()); }
00963 
00964       /**
00965        *  @brief  Add data to the end of the %list.
00966        *  @param  x  Data to be added.
00967        *
00968        *  This is a typical stack operation.  The function creates an
00969        *  element at the end of the %list and assigns the given data to
00970        *  it.  Due to the nature of a %list this operation can be done
00971        *  in constant time, and does not invalidate iterators and
00972        *  references.
00973        */
00974       void
00975       push_back(const value_type& __x)
00976       { this->_M_insert(end(), __x); }
00977 
00978 #ifdef __GXX_EXPERIMENTAL_CXX0X__
00979       void
00980       push_back(value_type&& __x)
00981       { this->_M_insert(end(), std::move(__x)); }
00982 
00983       template<typename... _Args>
00984         void
00985         emplace_back(_Args&&... __args)
00986         { this->_M_insert(end(), std::forward<_Args>(__args)...); }
00987 #endif
00988 
00989       /**
00990        *  @brief  Removes last element.
00991        *
00992        *  This is a typical stack operation.  It shrinks the %list by
00993        *  one.  Due to the nature of a %list this operation can be done
00994        *  in constant time, and only invalidates iterators/references to
00995        *  the element being removed.
00996        *
00997        *  Note that no data is returned, and if the last element's data
00998        *  is needed, it should be retrieved before pop_back() is called.
00999        */
01000       void
01001       pop_back()
01002       { this->_M_erase(iterator(this->_M_impl._M_node._M_prev)); }
01003 
01004 #ifdef __GXX_EXPERIMENTAL_CXX0X__
01005       /**
01006        *  @brief  Constructs object in %list before specified iterator.
01007        *  @param  position  A const_iterator into the %list.
01008        *  @param  args  Arguments.
01009        *  @return  An iterator that points to the inserted data.
01010        *
01011        *  This function will insert an object of type T constructed
01012        *  with T(std::forward<Args>(args)...) before the specified
01013        *  location.  Due to the nature of a %list this operation can
01014        *  be done in constant time, and does not invalidate iterators
01015        *  and references.
01016        */
01017       template<typename... _Args>
01018         iterator
01019         emplace(iterator __position, _Args&&... __args);
01020 #endif
01021 
01022       /**
01023        *  @brief  Inserts given value into %list before specified iterator.
01024        *  @param  position  An iterator into the %list.
01025        *  @param  x  Data to be inserted.
01026        *  @return  An iterator that points to the inserted data.
01027        *
01028        *  This function will insert a copy of the given value before
01029        *  the specified location.  Due to the nature of a %list this
01030        *  operation can be done in constant time, and does not
01031        *  invalidate iterators and references.
01032        */
01033       iterator
01034       insert(iterator __position, const value_type& __x);
01035 
01036 #ifdef __GXX_EXPERIMENTAL_CXX0X__
01037       /**
01038        *  @brief  Inserts given rvalue into %list before specified iterator.
01039        *  @param  position  An iterator into the %list.
01040        *  @param  x  Data to be inserted.
01041        *  @return  An iterator that points to the inserted data.
01042        *
01043        *  This function will insert a copy of the given rvalue before
01044        *  the specified location.  Due to the nature of a %list this
01045        *  operation can be done in constant time, and does not
01046        *  invalidate iterators and references.
01047         */
01048       iterator
01049       insert(iterator __position, value_type&& __x)
01050       { return emplace(__position, std::move(__x)); }
01051 
01052       /**
01053        *  @brief  Inserts the contents of an initializer_list into %list
01054        *          before specified iterator.
01055        *  @param  p  An iterator into the %list.
01056        *  @param  l  An initializer_list of value_type.
01057        *
01058        *  This function will insert copies of the data in the
01059        *  initializer_list @a l into the %list before the location
01060        *  specified by @a p.
01061        *
01062        *  This operation is linear in the number of elements inserted and
01063        *  does not invalidate iterators and references.
01064        */
01065       void
01066       insert(iterator __p, initializer_list<value_type> __l)
01067       { this->insert(__p, __l.begin(), __l.end()); }
01068 #endif
01069 
01070       /**
01071        *  @brief  Inserts a number of copies of given data into the %list.
01072        *  @param  position  An iterator into the %list.
01073        *  @param  n  Number of elements to be inserted.
01074        *  @param  x  Data to be inserted.
01075        *
01076        *  This function will insert a specified number of copies of the
01077        *  given data before the location specified by @a position.
01078        *
01079        *  This operation is linear in the number of elements inserted and
01080        *  does not invalidate iterators and references.
01081        */
01082       void
01083       insert(iterator __position, size_type __n, const value_type& __x)
01084       {  
01085     list __tmp(__n, __x, _M_get_Node_allocator());
01086     splice(__position, __tmp);
01087       }
01088 
01089       /**
01090        *  @brief  Inserts a range into the %list.
01091        *  @param  position  An iterator into the %list.
01092        *  @param  first  An input iterator.
01093        *  @param  last   An input iterator.
01094        *
01095        *  This function will insert copies of the data in the range [@a
01096        *  first,@a last) into the %list before the location specified by
01097        *  @a position.
01098        *
01099        *  This operation is linear in the number of elements inserted and
01100        *  does not invalidate iterators and references.
01101        */
01102       template<typename _InputIterator>
01103         void
01104         insert(iterator __position, _InputIterator __first,
01105            _InputIterator __last)
01106         {
01107       list __tmp(__first, __last, _M_get_Node_allocator());
01108       splice(__position, __tmp);
01109     }
01110 
01111       /**
01112        *  @brief  Remove element at given position.
01113        *  @param  position  Iterator pointing to element to be erased.
01114        *  @return  An iterator pointing to the next element (or end()).
01115        *
01116        *  This function will erase the element at the given position and thus
01117        *  shorten the %list by one.
01118        *
01119        *  Due to the nature of a %list this operation can be done in
01120        *  constant time, and only invalidates iterators/references to
01121        *  the element being removed.  The user is also cautioned that
01122        *  this function only erases the element, and that if the element
01123        *  is itself a pointer, the pointed-to memory is not touched in
01124        *  any way.  Managing the pointer is the user's responsibility.
01125        */
01126       iterator
01127       erase(iterator __position);
01128 
01129       /**
01130        *  @brief  Remove a range of elements.
01131        *  @param  first  Iterator pointing to the first element to be erased.
01132        *  @param  last  Iterator pointing to one past the last element to be
01133        *                erased.
01134        *  @return  An iterator pointing to the element pointed to by @a last
01135        *           prior to erasing (or end()).
01136        *
01137        *  This function will erase the elements in the range @a
01138        *  [first,last) and shorten the %list accordingly.
01139        *
01140        *  This operation is linear time in the size of the range and only
01141        *  invalidates iterators/references to the element being removed.
01142        *  The user is also cautioned that this function only erases the
01143        *  elements, and that if the elements themselves are pointers, the
01144        *  pointed-to memory is not touched in any way.  Managing the pointer
01145        *  is the user's responsibility.
01146        */
01147       iterator
01148       erase(iterator __first, iterator __last)
01149       {
01150     while (__first != __last)
01151       __first = erase(__first);
01152     return __last;
01153       }
01154 
01155       /**
01156        *  @brief  Swaps data with another %list.
01157        *  @param  x  A %list of the same element and allocator types.
01158        *
01159        *  This exchanges the elements between two lists in constant
01160        *  time.  Note that the global std::swap() function is
01161        *  specialized such that std::swap(l1,l2) will feed to this
01162        *  function.
01163        */
01164       void
01165       swap(list& __x)
01166       {
01167     _List_node_base::swap(this->_M_impl._M_node, __x._M_impl._M_node);
01168 
01169     // _GLIBCXX_RESOLVE_LIB_DEFECTS
01170     // 431. Swapping containers with unequal allocators.
01171     std::__alloc_swap<typename _Base::_Node_alloc_type>::
01172       _S_do_it(_M_get_Node_allocator(), __x._M_get_Node_allocator());
01173       }
01174 
01175       /**
01176        *  Erases all the elements.  Note that this function only erases
01177        *  the elements, and that if the elements themselves are
01178        *  pointers, the pointed-to memory is not touched in any way.
01179        *  Managing the pointer is the user's responsibility.
01180        */
01181       void
01182       clear()
01183       {
01184         _Base::_M_clear();
01185         _Base::_M_init();
01186       }
01187 
01188       // [23.2.2.4] list operations
01189       /**
01190        *  @brief  Insert contents of another %list.
01191        *  @param  position  Iterator referencing the element to insert before.
01192        *  @param  x  Source list.
01193        *
01194        *  The elements of @a x are inserted in constant time in front of
01195        *  the element referenced by @a position.  @a x becomes an empty
01196        *  list.
01197        *
01198        *  Requires this != @a x.
01199        */
01200       void
01201 #ifdef __GXX_EXPERIMENTAL_CXX0X__
01202       splice(iterator __position, list&& __x)
01203 #else
01204       splice(iterator __position, list& __x)
01205 #endif
01206       {
01207     if (!__x.empty())
01208       {
01209         _M_check_equal_allocators(__x);
01210 
01211         this->_M_transfer(__position, __x.begin(), __x.end());
01212       }
01213       }
01214 
01215 #ifdef __GXX_EXPERIMENTAL_CXX0X__
01216       void
01217       splice(iterator __position, list& __x)
01218       { splice(__position, std::move(__x)); }
01219 #endif
01220 
01221       /**
01222        *  @brief  Insert element from another %list.
01223        *  @param  position  Iterator referencing the element to insert before.
01224        *  @param  x  Source list.
01225        *  @param  i  Iterator referencing the element to move.
01226        *
01227        *  Removes the element in list @a x referenced by @a i and
01228        *  inserts it into the current list before @a position.
01229        */
01230       void
01231 #ifdef __GXX_EXPERIMENTAL_CXX0X__
01232       splice(iterator __position, list&& __x, iterator __i)
01233 #else
01234       splice(iterator __position, list& __x, iterator __i)
01235 #endif
01236       {
01237     iterator __j = __i;
01238     ++__j;
01239     if (__position == __i || __position == __j)
01240       return;
01241 
01242     if (this != &__x)
01243       _M_check_equal_allocators(__x);
01244 
01245     this->_M_transfer(__position, __i, __j);
01246       }
01247 
01248 #ifdef __GXX_EXPERIMENTAL_CXX0X__
01249       void
01250       splice(iterator __position, list& __x, iterator __i)
01251       { splice(__position, std::move(__x), __i); }
01252 #endif
01253 
01254       /**
01255        *  @brief  Insert range from another %list.
01256        *  @param  position  Iterator referencing the element to insert before.
01257        *  @param  x  Source list.
01258        *  @param  first  Iterator referencing the start of range in x.
01259        *  @param  last  Iterator referencing the end of range in x.
01260        *
01261        *  Removes elements in the range [first,last) and inserts them
01262        *  before @a position in constant time.
01263        *
01264        *  Undefined if @a position is in [first,last).
01265        */
01266       void
01267 #ifdef __GXX_EXPERIMENTAL_CXX0X__
01268       splice(iterator __position, list&& __x, iterator __first,
01269          iterator __last)
01270 #else
01271       splice(iterator __position, list& __x, iterator __first,
01272          iterator __last)
01273 #endif
01274       {
01275     if (__first != __last)
01276       {
01277         if (this != &__x)
01278           _M_check_equal_allocators(__x);
01279 
01280         this->_M_transfer(__position, __first, __last);
01281       }
01282       }
01283 
01284 #ifdef __GXX_EXPERIMENTAL_CXX0X__
01285       void
01286       splice(iterator __position, list& __x, iterator __first, iterator __last)
01287       { splice(__position, std::move(__x), __first, __last); }
01288 #endif
01289 
01290       /**
01291        *  @brief  Remove all elements equal to value.
01292        *  @param  value  The value to remove.
01293        *
01294        *  Removes every element in the list equal to @a value.
01295        *  Remaining elements stay in list order.  Note that this
01296        *  function only erases the elements, and that if the elements
01297        *  themselves are pointers, the pointed-to memory is not
01298        *  touched in any way.  Managing the pointer is the user's
01299        *  responsibility.
01300        */
01301       void
01302       remove(const _Tp& __value);
01303 
01304       /**
01305        *  @brief  Remove all elements satisfying a predicate.
01306        *  @param  Predicate  Unary predicate function or object.
01307        *
01308        *  Removes every element in the list for which the predicate
01309        *  returns true.  Remaining elements stay in list order.  Note
01310        *  that this function only erases the elements, and that if the
01311        *  elements themselves are pointers, the pointed-to memory is
01312        *  not touched in any way.  Managing the pointer is the user's
01313        *  responsibility.
01314        */
01315       template<typename _Predicate>
01316         void
01317         remove_if(_Predicate);
01318 
01319       /**
01320        *  @brief  Remove consecutive duplicate elements.
01321        *
01322        *  For each consecutive set of elements with the same value,
01323        *  remove all but the first one.  Remaining elements stay in
01324        *  list order.  Note that this function only erases the
01325        *  elements, and that if the elements themselves are pointers,
01326        *  the pointed-to memory is not touched in any way.  Managing
01327        *  the pointer is the user's responsibility.
01328        */
01329       void
01330       unique();
01331 
01332       /**
01333        *  @brief  Remove consecutive elements satisfying a predicate.
01334        *  @param  BinaryPredicate  Binary predicate function or object.
01335        *
01336        *  For each consecutive set of elements [first,last) that
01337        *  satisfy predicate(first,i) where i is an iterator in
01338        *  [first,last), remove all but the first one.  Remaining
01339        *  elements stay in list order.  Note that this function only
01340        *  erases the elements, and that if the elements themselves are
01341        *  pointers, the pointed-to memory is not touched in any way.
01342        *  Managing the pointer is the user's responsibility.
01343        */
01344       template<typename _BinaryPredicate>
01345         void
01346         unique(_BinaryPredicate);
01347 
01348       /**
01349        *  @brief  Merge sorted lists.
01350        *  @param  x  Sorted list to merge.
01351        *
01352        *  Assumes that both @a x and this list are sorted according to
01353        *  operator<().  Merges elements of @a x into this list in
01354        *  sorted order, leaving @a x empty when complete.  Elements in
01355        *  this list precede elements in @a x that are equal.
01356        */
01357 #ifdef __GXX_EXPERIMENTAL_CXX0X__
01358       void
01359       merge(list&& __x);
01360 
01361       void
01362       merge(list& __x)
01363       { merge(std::move(__x)); }
01364 #else
01365       void
01366       merge(list& __x);
01367 #endif
01368 
01369       /**
01370        *  @brief  Merge sorted lists according to comparison function.
01371        *  @param  x  Sorted list to merge.
01372        *  @param StrictWeakOrdering Comparison function defining
01373        *  sort order.
01374        *
01375        *  Assumes that both @a x and this list are sorted according to
01376        *  StrictWeakOrdering.  Merges elements of @a x into this list
01377        *  in sorted order, leaving @a x empty when complete.  Elements
01378        *  in this list precede elements in @a x that are equivalent
01379        *  according to StrictWeakOrdering().
01380        */
01381 #ifdef __GXX_EXPERIMENTAL_CXX0X__
01382       template<typename _StrictWeakOrdering>
01383         void
01384         merge(list&&, _StrictWeakOrdering);
01385 
01386       template<typename _StrictWeakOrdering>
01387         void
01388         merge(list& __x, _StrictWeakOrdering __comp)
01389         { merge(std::move(__x), __comp); }
01390 #else
01391       template<typename _StrictWeakOrdering>
01392         void
01393         merge(list&, _StrictWeakOrdering);
01394 #endif
01395 
01396       /**
01397        *  @brief  Reverse the elements in list.
01398        *
01399        *  Reverse the order of elements in the list in linear time.
01400        */
01401       void
01402       reverse()
01403       { this->_M_impl._M_node._M_reverse(); }
01404 
01405       /**
01406        *  @brief  Sort the elements.
01407        *
01408        *  Sorts the elements of this list in NlogN time.  Equivalent
01409        *  elements remain in list order.
01410        */
01411       void
01412       sort();
01413 
01414       /**
01415        *  @brief  Sort the elements according to comparison function.
01416        *
01417        *  Sorts the elements of this list in NlogN time.  Equivalent
01418        *  elements remain in list order.
01419        */
01420       template<typename _StrictWeakOrdering>
01421         void
01422         sort(_StrictWeakOrdering);
01423 
01424     protected:
01425       // Internal constructor functions follow.
01426 
01427       // Called by the range constructor to implement [23.1.1]/9
01428 
01429       // _GLIBCXX_RESOLVE_LIB_DEFECTS
01430       // 438. Ambiguity in the "do the right thing" clause
01431       template<typename _Integer>
01432         void
01433         _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type)
01434         { _M_fill_initialize(static_cast<size_type>(__n), __x); }
01435 
01436       // Called by the range constructor to implement [23.1.1]/9
01437       template<typename _InputIterator>
01438         void
01439         _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
01440                    __false_type)
01441         {
01442       for (; __first != __last; ++__first)
01443         push_back(*__first);
01444     }
01445 
01446       // Called by list(n,v,a), and the range constructor when it turns out
01447       // to be the same thing.
01448       void
01449       _M_fill_initialize(size_type __n, const value_type& __x)
01450       {
01451     for (; __n; --__n)
01452       push_back(__x);
01453       }
01454 
01455 #ifdef __GXX_EXPERIMENTAL_CXX0X__
01456       // Called by list(n).
01457       void
01458       _M_default_initialize(size_type __n)
01459       {
01460     for (; __n; --__n)
01461       emplace_back();
01462       }
01463 
01464       // Called by resize(sz).
01465       void
01466       _M_default_append(size_type __n);
01467 #endif
01468 
01469       // Internal assign functions follow.
01470 
01471       // Called by the range assign to implement [23.1.1]/9
01472 
01473       // _GLIBCXX_RESOLVE_LIB_DEFECTS
01474       // 438. Ambiguity in the "do the right thing" clause
01475       template<typename _Integer>
01476         void
01477         _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
01478         { _M_fill_assign(__n, __val); }
01479 
01480       // Called by the range assign to implement [23.1.1]/9
01481       template<typename _InputIterator>
01482         void
01483         _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
01484                __false_type);
01485 
01486       // Called by assign(n,t), and the range assign when it turns out
01487       // to be the same thing.
01488       void
01489       _M_fill_assign(size_type __n, const value_type& __val);
01490 
01491 
01492       // Moves the elements from [first,last) before position.
01493       void
01494       _M_transfer(iterator __position, iterator __first, iterator __last)
01495       { __position._M_node->_M_transfer(__first._M_node, __last._M_node); }
01496 
01497       // Inserts new element at position given and with value given.
01498 #ifndef __GXX_EXPERIMENTAL_CXX0X__
01499       void
01500       _M_insert(iterator __position, const value_type& __x)
01501       {
01502         _Node* __tmp = _M_create_node(__x);
01503         __tmp->_M_hook(__position._M_node);
01504       }
01505 #else
01506      template<typename... _Args>
01507        void
01508        _M_insert(iterator __position, _Args&&... __args)
01509        {
01510      _Node* __tmp = _M_create_node(std::forward<_Args>(__args)...);
01511      __tmp->_M_hook(__position._M_node);
01512        }
01513 #endif
01514 
01515       // Erases element at position given.
01516       void
01517       _M_erase(iterator __position)
01518       {
01519         __position._M_node->_M_unhook();
01520         _Node* __n = static_cast<_Node*>(__position._M_node);
01521 #ifdef __GXX_EXPERIMENTAL_CXX0X__
01522         _M_get_Node_allocator().destroy(__n);
01523 #else
01524     _M_get_Tp_allocator().destroy(std::__addressof(__n->_M_data));
01525 #endif
01526         _M_put_node(__n);
01527       }
01528 
01529       // To implement the splice (and merge) bits of N1599.
01530       void
01531       _M_check_equal_allocators(list& __x)
01532       {
01533     if (std::__alloc_neq<typename _Base::_Node_alloc_type>::
01534         _S_do_it(_M_get_Node_allocator(), __x._M_get_Node_allocator()))
01535       __throw_runtime_error(__N("list::_M_check_equal_allocators"));
01536       }
01537     };
01538 
01539   /**
01540    *  @brief  List equality comparison.
01541    *  @param  x  A %list.
01542    *  @param  y  A %list of the same type as @a x.
01543    *  @return  True iff the size and elements of the lists are equal.
01544    *
01545    *  This is an equivalence relation.  It is linear in the size of
01546    *  the lists.  Lists are considered equivalent if their sizes are
01547    *  equal, and if corresponding elements compare equal.
01548   */
01549   template<typename _Tp, typename _Alloc>
01550     inline bool
01551     operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
01552     {
01553       typedef typename list<_Tp, _Alloc>::const_iterator const_iterator;
01554       const_iterator __end1 = __x.end();
01555       const_iterator __end2 = __y.end();
01556 
01557       const_iterator __i1 = __x.begin();
01558       const_iterator __i2 = __y.begin();
01559       while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2)
01560     {
01561       ++__i1;
01562       ++__i2;
01563     }
01564       return __i1 == __end1 && __i2 == __end2;
01565     }
01566 
01567   /**
01568    *  @brief  List ordering relation.
01569    *  @param  x  A %list.
01570    *  @param  y  A %list of the same type as @a x.
01571    *  @return  True iff @a x is lexicographically less than @a y.
01572    *
01573    *  This is a total ordering relation.  It is linear in the size of the
01574    *  lists.  The elements must be comparable with @c <.
01575    *
01576    *  See std::lexicographical_compare() for how the determination is made.
01577   */
01578   template<typename _Tp, typename _Alloc>
01579     inline bool
01580     operator<(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
01581     { return std::lexicographical_compare(__x.begin(), __x.end(),
01582                       __y.begin(), __y.end()); }
01583 
01584   /// Based on operator==
01585   template<typename _Tp, typename _Alloc>
01586     inline bool
01587     operator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
01588     { return !(__x == __y); }
01589 
01590   /// Based on operator<
01591   template<typename _Tp, typename _Alloc>
01592     inline bool
01593     operator>(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
01594     { return __y < __x; }
01595 
01596   /// Based on operator<
01597   template<typename _Tp, typename _Alloc>
01598     inline bool
01599     operator<=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
01600     { return !(__y < __x); }
01601 
01602   /// Based on operator<
01603   template<typename _Tp, typename _Alloc>
01604     inline bool
01605     operator>=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
01606     { return !(__x < __y); }
01607 
01608   /// See std::list::swap().
01609   template<typename _Tp, typename _Alloc>
01610     inline void
01611     swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y)
01612     { __x.swap(__y); }
01613 
01614 _GLIBCXX_END_NESTED_NAMESPACE
01615 
01616 #endif /* _STL_LIST_H */