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