libstdc++
forward_list.h
Go to the documentation of this file.
00001 // <forward_list.h> -*- C++ -*-
00002 
00003 // Copyright (C) 2008-2015 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the
00008 // Free Software Foundation; either version 3, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 
00016 // Under Section 7 of GPL version 3, you are granted additional
00017 // permissions described in the GCC Runtime Library Exception, version
00018 // 3.1, as published by the Free Software Foundation.
00019 
00020 // You should have received a copy of the GNU General Public License and
00021 // a copy of the GCC Runtime Library Exception along with this program;
00022 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00023 // <http://www.gnu.org/licenses/>.
00024 
00025 /** @file bits/forward_list.h
00026  *  This is an internal header file, included by other library headers.
00027  *  Do not attempt to use it directly. @headername{forward_list}
00028  */
00029 
00030 #ifndef _FORWARD_LIST_H
00031 #define _FORWARD_LIST_H 1
00032 
00033 #pragma GCC system_header
00034 
00035 #include <initializer_list>
00036 #include <bits/stl_iterator_base_types.h>
00037 #include <bits/stl_iterator.h>
00038 #include <bits/stl_algobase.h>
00039 #include <bits/stl_function.h>
00040 #include <bits/allocator.h>
00041 #include <ext/alloc_traits.h>
00042 #include <ext/aligned_buffer.h>
00043 
00044 namespace std _GLIBCXX_VISIBILITY(default)
00045 {
00046 _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
00047 
00048   /**
00049    *  @brief  A helper basic node class for %forward_list.
00050    *          This is just a linked list with nothing inside it.
00051    *          There are purely list shuffling utility methods here.
00052    */
00053   struct _Fwd_list_node_base
00054   {
00055     _Fwd_list_node_base() = default;
00056 
00057     _Fwd_list_node_base* _M_next = nullptr;
00058 
00059     _Fwd_list_node_base*
00060     _M_transfer_after(_Fwd_list_node_base* __begin,
00061                       _Fwd_list_node_base* __end) noexcept
00062     {
00063       _Fwd_list_node_base* __keep = __begin->_M_next;
00064       if (__end)
00065         {
00066           __begin->_M_next = __end->_M_next;
00067           __end->_M_next = _M_next;
00068         }
00069       else
00070         __begin->_M_next = 0;
00071       _M_next = __keep;
00072       return __end;
00073     }
00074 
00075     void
00076     _M_reverse_after() noexcept
00077     {
00078       _Fwd_list_node_base* __tail = _M_next;
00079       if (!__tail)
00080         return;
00081       while (_Fwd_list_node_base* __temp = __tail->_M_next)
00082         {
00083           _Fwd_list_node_base* __keep = _M_next;
00084           _M_next = __temp;
00085           __tail->_M_next = __temp->_M_next;
00086           _M_next->_M_next = __keep;
00087         }
00088     }
00089   };
00090 
00091   /**
00092    *  @brief  A helper node class for %forward_list.
00093    *          This is just a linked list with uninitialized storage for a
00094    *          data value in each node.
00095    *          There is a sorting utility method.
00096    */
00097   template<typename _Tp>
00098     struct _Fwd_list_node
00099     : public _Fwd_list_node_base
00100     {
00101       _Fwd_list_node() = default;
00102 
00103       __gnu_cxx::__aligned_buffer<_Tp> _M_storage;
00104 
00105       _Tp*
00106       _M_valptr() noexcept
00107       { return _M_storage._M_ptr(); }
00108 
00109       const _Tp*
00110       _M_valptr() const noexcept
00111       { return _M_storage._M_ptr(); }
00112     };
00113 
00114   /**
00115    *   @brief A forward_list::iterator.
00116    * 
00117    *   All the functions are op overloads.
00118    */
00119   template<typename _Tp>
00120     struct _Fwd_list_iterator
00121     {
00122       typedef _Fwd_list_iterator<_Tp>            _Self;
00123       typedef _Fwd_list_node<_Tp>                _Node;
00124 
00125       typedef _Tp                                value_type;
00126       typedef _Tp*                               pointer;
00127       typedef _Tp&                               reference;
00128       typedef ptrdiff_t                          difference_type;
00129       typedef std::forward_iterator_tag          iterator_category;
00130 
00131       _Fwd_list_iterator() noexcept
00132       : _M_node() { }
00133 
00134       explicit
00135       _Fwd_list_iterator(_Fwd_list_node_base* __n) noexcept
00136       : _M_node(__n) { }
00137 
00138       reference
00139       operator*() const noexcept
00140       { return *static_cast<_Node*>(this->_M_node)->_M_valptr(); }
00141 
00142       pointer
00143       operator->() const noexcept
00144       { return static_cast<_Node*>(this->_M_node)->_M_valptr(); }
00145 
00146       _Self&
00147       operator++() noexcept
00148       {
00149         _M_node = _M_node->_M_next;
00150         return *this;
00151       }
00152 
00153       _Self
00154       operator++(int) noexcept
00155       {
00156         _Self __tmp(*this);
00157         _M_node = _M_node->_M_next;
00158         return __tmp;
00159       }
00160 
00161       bool
00162       operator==(const _Self& __x) const noexcept
00163       { return _M_node == __x._M_node; }
00164 
00165       bool
00166       operator!=(const _Self& __x) const noexcept
00167       { return _M_node != __x._M_node; }
00168 
00169       _Self
00170       _M_next() const noexcept
00171       {
00172         if (_M_node)
00173           return _Fwd_list_iterator(_M_node->_M_next);
00174         else
00175           return _Fwd_list_iterator(0);
00176       }
00177 
00178       _Fwd_list_node_base* _M_node;
00179     };
00180 
00181   /**
00182    *   @brief A forward_list::const_iterator.
00183    * 
00184    *   All the functions are op overloads.
00185    */
00186   template<typename _Tp>
00187     struct _Fwd_list_const_iterator
00188     {
00189       typedef _Fwd_list_const_iterator<_Tp>      _Self;
00190       typedef const _Fwd_list_node<_Tp>          _Node;
00191       typedef _Fwd_list_iterator<_Tp>            iterator;
00192 
00193       typedef _Tp                                value_type;
00194       typedef const _Tp*                         pointer;
00195       typedef const _Tp&                         reference;
00196       typedef ptrdiff_t                          difference_type;
00197       typedef std::forward_iterator_tag          iterator_category;
00198 
00199       _Fwd_list_const_iterator() noexcept
00200       : _M_node() { }
00201 
00202       explicit
00203       _Fwd_list_const_iterator(const _Fwd_list_node_base* __n)  noexcept
00204       : _M_node(__n) { }
00205 
00206       _Fwd_list_const_iterator(const iterator& __iter) noexcept
00207       : _M_node(__iter._M_node) { }
00208 
00209       reference
00210       operator*() const noexcept
00211       { return *static_cast<_Node*>(this->_M_node)->_M_valptr(); }
00212 
00213       pointer
00214       operator->() const noexcept
00215       { return static_cast<_Node*>(this->_M_node)->_M_valptr(); }
00216 
00217       _Self&
00218       operator++() noexcept
00219       {
00220         _M_node = _M_node->_M_next;
00221         return *this;
00222       }
00223 
00224       _Self
00225       operator++(int) noexcept
00226       {
00227         _Self __tmp(*this);
00228         _M_node = _M_node->_M_next;
00229         return __tmp;
00230       }
00231 
00232       bool
00233       operator==(const _Self& __x) const noexcept
00234       { return _M_node == __x._M_node; }
00235 
00236       bool
00237       operator!=(const _Self& __x) const noexcept
00238       { return _M_node != __x._M_node; }
00239 
00240       _Self
00241       _M_next() const noexcept
00242       {
00243         if (this->_M_node)
00244           return _Fwd_list_const_iterator(_M_node->_M_next);
00245         else
00246           return _Fwd_list_const_iterator(0);
00247       }
00248 
00249       const _Fwd_list_node_base* _M_node;
00250     };
00251 
00252   /**
00253    *  @brief  Forward list iterator equality comparison.
00254    */
00255   template<typename _Tp>
00256     inline bool
00257     operator==(const _Fwd_list_iterator<_Tp>& __x,
00258                const _Fwd_list_const_iterator<_Tp>& __y) noexcept
00259     { return __x._M_node == __y._M_node; }
00260 
00261   /**
00262    *  @brief  Forward list iterator inequality comparison.
00263    */
00264   template<typename _Tp>
00265     inline bool
00266     operator!=(const _Fwd_list_iterator<_Tp>& __x,
00267                const _Fwd_list_const_iterator<_Tp>& __y) noexcept
00268     { return __x._M_node != __y._M_node; }
00269 
00270   /**
00271    *  @brief  Base class for %forward_list.
00272    */
00273   template<typename _Tp, typename _Alloc>
00274     struct _Fwd_list_base
00275     {
00276     protected:
00277       typedef __alloc_rebind<_Alloc, _Tp>                 _Tp_alloc_type;
00278       typedef __alloc_rebind<_Alloc, _Fwd_list_node<_Tp>> _Node_alloc_type;
00279       typedef __gnu_cxx::__alloc_traits<_Node_alloc_type> _Node_alloc_traits;
00280 
00281       struct _Fwd_list_impl 
00282       : public _Node_alloc_type
00283       {
00284         _Fwd_list_node_base _M_head;
00285 
00286         _Fwd_list_impl()
00287         : _Node_alloc_type(), _M_head()
00288         { }
00289 
00290         _Fwd_list_impl(const _Node_alloc_type& __a)
00291         : _Node_alloc_type(__a), _M_head()
00292         { }
00293 
00294         _Fwd_list_impl(_Node_alloc_type&& __a)
00295         : _Node_alloc_type(std::move(__a)), _M_head()
00296         { }
00297       };
00298 
00299       _Fwd_list_impl _M_impl;
00300 
00301     public:
00302       typedef _Fwd_list_iterator<_Tp>                 iterator;
00303       typedef _Fwd_list_const_iterator<_Tp>           const_iterator;
00304       typedef _Fwd_list_node<_Tp>                     _Node;
00305 
00306       _Node_alloc_type&
00307       _M_get_Node_allocator() noexcept
00308       { return *static_cast<_Node_alloc_type*>(&this->_M_impl); }
00309 
00310       const _Node_alloc_type&
00311       _M_get_Node_allocator() const noexcept
00312       { return *static_cast<const _Node_alloc_type*>(&this->_M_impl); }
00313 
00314       _Fwd_list_base()
00315       : _M_impl() { }
00316 
00317       _Fwd_list_base(const _Node_alloc_type& __a)
00318       : _M_impl(__a) { }
00319 
00320       _Fwd_list_base(_Fwd_list_base&& __lst, const _Node_alloc_type& __a);
00321 
00322       _Fwd_list_base(_Fwd_list_base&& __lst)
00323       : _M_impl(std::move(__lst._M_get_Node_allocator()))
00324       {
00325         this->_M_impl._M_head._M_next = __lst._M_impl._M_head._M_next;
00326         __lst._M_impl._M_head._M_next = 0;
00327       }
00328 
00329       ~_Fwd_list_base()
00330       { _M_erase_after(&_M_impl._M_head, 0); }
00331 
00332     protected:
00333 
00334       _Node*
00335       _M_get_node()
00336       {
00337         auto __ptr = _Node_alloc_traits::allocate(_M_get_Node_allocator(), 1);
00338         return std::__addressof(*__ptr);
00339       }
00340 
00341       template<typename... _Args>
00342         _Node*
00343         _M_create_node(_Args&&... __args)
00344         {
00345           _Node* __node = this->_M_get_node();
00346           __try
00347             {
00348               _Tp_alloc_type __a(_M_get_Node_allocator());
00349               typedef allocator_traits<_Tp_alloc_type> _Alloc_traits;
00350               ::new ((void*)__node) _Node;
00351               _Alloc_traits::construct(__a, __node->_M_valptr(),
00352                                        std::forward<_Args>(__args)...);
00353             }
00354           __catch(...)
00355             {
00356               this->_M_put_node(__node);
00357               __throw_exception_again;
00358             }
00359           return __node;
00360         }
00361 
00362       template<typename... _Args>
00363         _Fwd_list_node_base*
00364         _M_insert_after(const_iterator __pos, _Args&&... __args);
00365 
00366       void
00367       _M_put_node(_Node* __p)
00368       {
00369         typedef typename _Node_alloc_traits::pointer _Ptr;
00370         auto __ptr = std::pointer_traits<_Ptr>::pointer_to(*__p);
00371         _Node_alloc_traits::deallocate(_M_get_Node_allocator(), __ptr, 1);
00372       }
00373 
00374       _Fwd_list_node_base*
00375       _M_erase_after(_Fwd_list_node_base* __pos);
00376 
00377       _Fwd_list_node_base*
00378       _M_erase_after(_Fwd_list_node_base* __pos, 
00379                      _Fwd_list_node_base* __last);
00380     };
00381 
00382   /**
00383    *  @brief A standard container with linear time access to elements,
00384    *  and fixed time insertion/deletion at any point in the sequence.
00385    *
00386    *  @ingroup sequences
00387    *
00388    *  @tparam _Tp  Type of element.
00389    *  @tparam _Alloc  Allocator type, defaults to allocator<_Tp>.
00390    *
00391    *  Meets the requirements of a <a href="tables.html#65">container</a>, a
00392    *  <a href="tables.html#67">sequence</a>, including the
00393    *  <a href="tables.html#68">optional sequence requirements</a> with the
00394    *  %exception of @c at and @c operator[].
00395    *
00396    *  This is a @e singly @e linked %list.  Traversal up the
00397    *  %list requires linear time, but adding and removing elements (or
00398    *  @e nodes) is done in constant time, regardless of where the
00399    *  change takes place.  Unlike std::vector and std::deque,
00400    *  random-access iterators are not provided, so subscripting ( @c
00401    *  [] ) access is not allowed.  For algorithms which only need
00402    *  sequential access, this lack makes no difference.
00403    *
00404    *  Also unlike the other standard containers, std::forward_list provides
00405    *  specialized algorithms %unique to linked lists, such as
00406    *  splicing, sorting, and in-place reversal.
00407    */
00408   template<typename _Tp, typename _Alloc = allocator<_Tp> >
00409     class forward_list : private _Fwd_list_base<_Tp, _Alloc>
00410     {
00411     private:
00412       typedef _Fwd_list_base<_Tp, _Alloc>                  _Base;
00413       typedef _Fwd_list_node<_Tp>                          _Node;
00414       typedef _Fwd_list_node_base                          _Node_base;
00415       typedef typename _Base::_Tp_alloc_type               _Tp_alloc_type;
00416       typedef typename _Base::_Node_alloc_type             _Node_alloc_type;
00417       typedef typename _Base::_Node_alloc_traits           _Node_alloc_traits;
00418       typedef __gnu_cxx::__alloc_traits<_Tp_alloc_type>    _Alloc_traits;
00419 
00420     public:
00421       // types:
00422       typedef _Tp                                          value_type;
00423       typedef typename _Alloc_traits::pointer              pointer;
00424       typedef typename _Alloc_traits::const_pointer        const_pointer;
00425       typedef value_type&                                  reference;
00426       typedef const value_type&                            const_reference;
00427  
00428       typedef _Fwd_list_iterator<_Tp>                      iterator;
00429       typedef _Fwd_list_const_iterator<_Tp>                const_iterator;
00430       typedef std::size_t                                  size_type;
00431       typedef std::ptrdiff_t                               difference_type;
00432       typedef _Alloc                                       allocator_type;
00433 
00434       // 23.3.4.2 construct/copy/destroy:
00435 
00436       /**
00437        *  @brief  Creates a %forward_list with no elements.
00438        *  @param  __al  An allocator object.
00439        */
00440       explicit
00441       forward_list(const _Alloc& __al = _Alloc())
00442       : _Base(_Node_alloc_type(__al))
00443       { }
00444 
00445       /**
00446        *  @brief  Copy constructor with allocator argument.
00447        *  @param  __list  Input list to copy.
00448        *  @param  __al    An allocator object.
00449        */
00450       forward_list(const forward_list& __list, const _Alloc& __al)
00451       : _Base(_Node_alloc_type(__al))
00452       { _M_range_initialize(__list.begin(), __list.end()); }
00453 
00454       /**
00455        *  @brief  Move constructor with allocator argument.
00456        *  @param  __list  Input list to move.
00457        *  @param  __al    An allocator object.
00458        */
00459       forward_list(forward_list&& __list, const _Alloc& __al)
00460       noexcept(_Node_alloc_traits::_S_always_equal())
00461       : _Base(std::move(__list), _Node_alloc_type(__al))
00462       { }
00463 
00464       /**
00465        *  @brief  Creates a %forward_list with default constructed elements.
00466        *  @param  __n   The number of elements to initially create.
00467        *  @param  __al  An allocator object.
00468        *
00469        *  This constructor creates the %forward_list with @a __n default
00470        *  constructed elements.
00471        */
00472       explicit
00473       forward_list(size_type __n, const _Alloc& __al = _Alloc())
00474       : _Base(_Node_alloc_type(__al))
00475       { _M_default_initialize(__n); }
00476 
00477       /**
00478        *  @brief  Creates a %forward_list with copies of an exemplar element.
00479        *  @param  __n      The number of elements to initially create.
00480        *  @param  __value  An element to copy.
00481        *  @param  __al     An allocator object.
00482        *
00483        *  This constructor fills the %forward_list with @a __n copies of
00484        *  @a __value.
00485        */
00486       forward_list(size_type __n, const _Tp& __value,
00487                    const _Alloc& __al = _Alloc())
00488       : _Base(_Node_alloc_type(__al))
00489       { _M_fill_initialize(__n, __value); }
00490 
00491       /**
00492        *  @brief  Builds a %forward_list from a range.
00493        *  @param  __first  An input iterator.
00494        *  @param  __last   An input iterator.
00495        *  @param  __al     An allocator object.
00496        *
00497        *  Create a %forward_list consisting of copies of the elements from
00498        *  [@a __first,@a __last).  This is linear in N (where N is
00499        *  distance(@a __first,@a __last)).
00500        */
00501       template<typename _InputIterator,
00502                typename = std::_RequireInputIter<_InputIterator>>
00503         forward_list(_InputIterator __first, _InputIterator __last,
00504                      const _Alloc& __al = _Alloc())
00505         : _Base(_Node_alloc_type(__al))
00506         { _M_range_initialize(__first, __last); }
00507 
00508       /**
00509        *  @brief  The %forward_list copy constructor.
00510        *  @param  __list  A %forward_list of identical element and allocator
00511        *                  types.
00512        */
00513       forward_list(const forward_list& __list)
00514       : _Base(_Node_alloc_traits::_S_select_on_copy(
00515                 __list._M_get_Node_allocator()))
00516       { _M_range_initialize(__list.begin(), __list.end()); }
00517 
00518       /**
00519        *  @brief  The %forward_list move constructor.
00520        *  @param  __list  A %forward_list of identical element and allocator
00521        *                  types.
00522        *
00523        *  The newly-created %forward_list contains the exact contents of @a
00524        *  __list. The contents of @a __list are a valid, but unspecified
00525        *  %forward_list.
00526        */
00527       forward_list(forward_list&& __list) noexcept
00528       : _Base(std::move(__list)) { }
00529 
00530       /**
00531        *  @brief  Builds a %forward_list from an initializer_list
00532        *  @param  __il  An initializer_list of value_type.
00533        *  @param  __al  An allocator object.
00534        *
00535        *  Create a %forward_list consisting of copies of the elements
00536        *  in the initializer_list @a __il.  This is linear in __il.size().
00537        */
00538       forward_list(std::initializer_list<_Tp> __il,
00539                    const _Alloc& __al = _Alloc())
00540       : _Base(_Node_alloc_type(__al))
00541       { _M_range_initialize(__il.begin(), __il.end()); }
00542 
00543       /**
00544        *  @brief  The forward_list dtor.
00545        */
00546       ~forward_list() noexcept
00547       { }
00548 
00549       /**
00550        *  @brief  The %forward_list assignment operator.
00551        *  @param  __list  A %forward_list of identical element and allocator
00552        *                types.
00553        *
00554        *  All the elements of @a __list are copied, but unlike the copy
00555        *  constructor, the allocator object is not copied.
00556        */
00557       forward_list&
00558       operator=(const forward_list& __list);
00559 
00560       /**
00561        *  @brief  The %forward_list move assignment operator.
00562        *  @param  __list  A %forward_list of identical element and allocator
00563        *                types.
00564        *
00565        *  The contents of @a __list are moved into this %forward_list
00566        *  (without copying, if the allocators permit it).
00567        *  @a __list is a valid, but unspecified %forward_list
00568        */
00569       forward_list&
00570       operator=(forward_list&& __list)
00571       noexcept(_Node_alloc_traits::_S_nothrow_move())
00572       {
00573         constexpr bool __move_storage =
00574           _Node_alloc_traits::_S_propagate_on_move_assign()
00575           || _Node_alloc_traits::_S_always_equal();
00576         _M_move_assign(std::move(__list),
00577                        integral_constant<bool, __move_storage>());
00578         return *this;
00579       }
00580 
00581       /**
00582        *  @brief  The %forward_list initializer list assignment operator.
00583        *  @param  __il  An initializer_list of value_type.
00584        *
00585        *  Replace the contents of the %forward_list with copies of the
00586        *  elements in the initializer_list @a __il.  This is linear in
00587        *  __il.size().
00588        */
00589       forward_list&
00590       operator=(std::initializer_list<_Tp> __il)
00591       {
00592         assign(__il);
00593         return *this;
00594       }
00595 
00596       /**
00597        *  @brief  Assigns a range to a %forward_list.
00598        *  @param  __first  An input iterator.
00599        *  @param  __last   An input iterator.
00600        *
00601        *  This function fills a %forward_list with copies of the elements
00602        *  in the range [@a __first,@a __last).
00603        *
00604        *  Note that the assignment completely changes the %forward_list and
00605        *  that the number of elements of the resulting %forward_list is the
00606        *  same as the number of elements assigned.  Old data is lost.
00607        */
00608       template<typename _InputIterator,
00609                typename = std::_RequireInputIter<_InputIterator>>
00610         void
00611         assign(_InputIterator __first, _InputIterator __last)
00612         {
00613           typedef is_assignable<_Tp, decltype(*__first)> __assignable;
00614           _M_assign(__first, __last, __assignable());
00615         }
00616 
00617       /**
00618        *  @brief  Assigns a given value to a %forward_list.
00619        *  @param  __n  Number of elements to be assigned.
00620        *  @param  __val  Value to be assigned.
00621        *
00622        *  This function fills a %forward_list with @a __n copies of the
00623        *  given value.  Note that the assignment completely changes the
00624        *  %forward_list, and that the resulting %forward_list has __n
00625        *  elements.  Old data is lost.
00626        */
00627       void
00628       assign(size_type __n, const _Tp& __val)
00629       { _M_assign_n(__n, __val, is_copy_assignable<_Tp>()); }
00630 
00631       /**
00632        *  @brief  Assigns an initializer_list to a %forward_list.
00633        *  @param  __il  An initializer_list of value_type.
00634        *
00635        *  Replace the contents of the %forward_list with copies of the
00636        *  elements in the initializer_list @a __il.  This is linear in
00637        *  il.size().
00638        */
00639       void
00640       assign(std::initializer_list<_Tp> __il)
00641       { assign(__il.begin(), __il.end()); }
00642 
00643       /// Get a copy of the memory allocation object.
00644       allocator_type
00645       get_allocator() const noexcept
00646       { return allocator_type(this->_M_get_Node_allocator()); }
00647 
00648       // 23.3.4.3 iterators:
00649 
00650       /**
00651        *  Returns a read/write iterator that points before the first element
00652        *  in the %forward_list.  Iteration is done in ordinary element order.
00653        */
00654       iterator
00655       before_begin() noexcept
00656       { return iterator(&this->_M_impl._M_head); }
00657 
00658       /**
00659        *  Returns a read-only (constant) iterator that points before the
00660        *  first element in the %forward_list.  Iteration is done in ordinary
00661        *  element order.
00662        */
00663       const_iterator
00664       before_begin() const noexcept
00665       { return const_iterator(&this->_M_impl._M_head); }
00666 
00667       /**
00668        *  Returns a read/write iterator that points to the first element
00669        *  in the %forward_list.  Iteration is done in ordinary element order.
00670        */
00671       iterator
00672       begin() noexcept
00673       { return iterator(this->_M_impl._M_head._M_next); }
00674 
00675       /**
00676        *  Returns a read-only (constant) iterator that points to the first
00677        *  element in the %forward_list.  Iteration is done in ordinary
00678        *  element order.
00679        */
00680       const_iterator
00681       begin() const noexcept
00682       { return const_iterator(this->_M_impl._M_head._M_next); }
00683 
00684       /**
00685        *  Returns a read/write iterator that points one past the last
00686        *  element in the %forward_list.  Iteration is done in ordinary
00687        *  element order.
00688        */
00689       iterator
00690       end() noexcept
00691       { return iterator(0); }
00692 
00693       /**
00694        *  Returns a read-only iterator that points one past the last
00695        *  element in the %forward_list.  Iteration is done in ordinary
00696        *  element order.
00697        */
00698       const_iterator
00699       end() const noexcept
00700       { return const_iterator(0); }
00701 
00702       /**
00703        *  Returns a read-only (constant) iterator that points to the
00704        *  first element in the %forward_list.  Iteration is done in ordinary
00705        *  element order.
00706        */
00707       const_iterator
00708       cbegin() const noexcept
00709       { return const_iterator(this->_M_impl._M_head._M_next); }
00710 
00711       /**
00712        *  Returns a read-only (constant) iterator that points before the
00713        *  first element in the %forward_list.  Iteration is done in ordinary
00714        *  element order.
00715        */
00716       const_iterator
00717       cbefore_begin() const noexcept
00718       { return const_iterator(&this->_M_impl._M_head); }
00719 
00720       /**
00721        *  Returns a read-only (constant) iterator that points one past
00722        *  the last element in the %forward_list.  Iteration is done in
00723        *  ordinary element order.
00724        */
00725       const_iterator
00726       cend() const noexcept
00727       { return const_iterator(0); }
00728 
00729       /**
00730        *  Returns true if the %forward_list is empty.  (Thus begin() would
00731        *  equal end().)
00732        */
00733       bool
00734       empty() const noexcept
00735       { return this->_M_impl._M_head._M_next == 0; }
00736 
00737       /**
00738        *  Returns the largest possible number of elements of %forward_list.
00739        */
00740       size_type
00741       max_size() const noexcept
00742       { return _Node_alloc_traits::max_size(this->_M_get_Node_allocator()); }
00743 
00744       // 23.3.4.4 element access:
00745 
00746       /**
00747        *  Returns a read/write reference to the data at the first
00748        *  element of the %forward_list.
00749        */
00750       reference
00751       front()
00752       {
00753         _Node* __front = static_cast<_Node*>(this->_M_impl._M_head._M_next);
00754         return *__front->_M_valptr();
00755       }
00756 
00757       /**
00758        *  Returns a read-only (constant) reference to the data at the first
00759        *  element of the %forward_list.
00760        */
00761       const_reference
00762       front() const
00763       {
00764         _Node* __front = static_cast<_Node*>(this->_M_impl._M_head._M_next);
00765         return *__front->_M_valptr();
00766       }
00767 
00768       // 23.3.4.5 modifiers:
00769 
00770       /**
00771        *  @brief  Constructs object in %forward_list at the front of the
00772        *          list.
00773        *  @param  __args  Arguments.
00774        *
00775        *  This function will insert an object of type Tp constructed
00776        *  with Tp(std::forward<Args>(args)...) at the front of the list
00777        *  Due to the nature of a %forward_list this operation can
00778        *  be done in constant time, and does not invalidate iterators
00779        *  and references.
00780        */
00781       template<typename... _Args>
00782         void
00783         emplace_front(_Args&&... __args)
00784         { this->_M_insert_after(cbefore_begin(),
00785                                 std::forward<_Args>(__args)...); }
00786 
00787       /**
00788        *  @brief  Add data to the front of the %forward_list.
00789        *  @param  __val  Data to be added.
00790        *
00791        *  This is a typical stack operation.  The function creates an
00792        *  element at the front of the %forward_list and assigns the given
00793        *  data to it.  Due to the nature of a %forward_list this operation
00794        *  can be done in constant time, and does not invalidate iterators
00795        *  and references.
00796        */
00797       void
00798       push_front(const _Tp& __val)
00799       { this->_M_insert_after(cbefore_begin(), __val); }
00800 
00801       /**
00802        *
00803        */
00804       void
00805       push_front(_Tp&& __val)
00806       { this->_M_insert_after(cbefore_begin(), std::move(__val)); }
00807 
00808       /**
00809        *  @brief  Removes first element.
00810        *
00811        *  This is a typical stack operation.  It shrinks the %forward_list
00812        *  by one.  Due to the nature of a %forward_list this operation can
00813        *  be done in constant time, and only invalidates iterators/references
00814        *  to the element being removed.
00815        *
00816        *  Note that no data is returned, and if the first element's data
00817        *  is needed, it should be retrieved before pop_front() is
00818        *  called.
00819        */
00820       void
00821       pop_front()
00822       { this->_M_erase_after(&this->_M_impl._M_head); }
00823 
00824       /**
00825        *  @brief  Constructs object in %forward_list after the specified
00826        *          iterator.
00827        *  @param  __pos  A const_iterator into the %forward_list.
00828        *  @param  __args  Arguments.
00829        *  @return  An iterator that points to the inserted data.
00830        *
00831        *  This function will insert an object of type T constructed
00832        *  with T(std::forward<Args>(args)...) after the specified
00833        *  location.  Due to the nature of a %forward_list this operation can
00834        *  be done in constant time, and does not invalidate iterators
00835        *  and references.
00836        */
00837       template<typename... _Args>
00838         iterator
00839         emplace_after(const_iterator __pos, _Args&&... __args)
00840         { return iterator(this->_M_insert_after(__pos,
00841                                           std::forward<_Args>(__args)...)); }
00842 
00843       /**
00844        *  @brief  Inserts given value into %forward_list after specified
00845        *          iterator.
00846        *  @param  __pos  An iterator into the %forward_list.
00847        *  @param  __val  Data to be inserted.
00848        *  @return  An iterator that points to the inserted data.
00849        *
00850        *  This function will insert a copy of the given value after
00851        *  the specified location.  Due to the nature of a %forward_list this
00852        *  operation can be done in constant time, and does not
00853        *  invalidate iterators and references.
00854        */
00855       iterator
00856       insert_after(const_iterator __pos, const _Tp& __val)
00857       { return iterator(this->_M_insert_after(__pos, __val)); }
00858 
00859       /**
00860        *
00861        */
00862       iterator
00863       insert_after(const_iterator __pos, _Tp&& __val)
00864       { return iterator(this->_M_insert_after(__pos, std::move(__val))); }
00865 
00866       /**
00867        *  @brief  Inserts a number of copies of given data into the
00868        *          %forward_list.
00869        *  @param  __pos  An iterator into the %forward_list.
00870        *  @param  __n  Number of elements to be inserted.
00871        *  @param  __val  Data to be inserted.
00872        *  @return  An iterator pointing to the last inserted copy of
00873        *           @a val or @a pos if @a n == 0.
00874        *
00875        *  This function will insert a specified number of copies of the
00876        *  given data after the location specified by @a pos.
00877        *
00878        *  This operation is linear in the number of elements inserted and
00879        *  does not invalidate iterators and references.
00880        */
00881       iterator
00882       insert_after(const_iterator __pos, size_type __n, const _Tp& __val);
00883 
00884       /**
00885        *  @brief  Inserts a range into the %forward_list.
00886        *  @param  __pos  An iterator into the %forward_list.
00887        *  @param  __first  An input iterator.
00888        *  @param  __last   An input iterator.
00889        *  @return  An iterator pointing to the last inserted element or
00890        *           @a __pos if @a __first == @a __last.
00891        *
00892        *  This function will insert copies of the data in the range
00893        *  [@a __first,@a __last) into the %forward_list after the
00894        *  location specified by @a __pos.
00895        *
00896        *  This operation is linear in the number of elements inserted and
00897        *  does not invalidate iterators and references.
00898        */
00899       template<typename _InputIterator,
00900                typename = std::_RequireInputIter<_InputIterator>>
00901         iterator
00902         insert_after(const_iterator __pos,
00903                      _InputIterator __first, _InputIterator __last);
00904 
00905       /**
00906        *  @brief  Inserts the contents of an initializer_list into
00907        *          %forward_list after the specified iterator.
00908        *  @param  __pos  An iterator into the %forward_list.
00909        *  @param  __il  An initializer_list of value_type.
00910        *  @return  An iterator pointing to the last inserted element
00911        *           or @a __pos if @a __il is empty.
00912        *
00913        *  This function will insert copies of the data in the
00914        *  initializer_list @a __il into the %forward_list before the location
00915        *  specified by @a __pos.
00916        *
00917        *  This operation is linear in the number of elements inserted and
00918        *  does not invalidate iterators and references.
00919        */
00920       iterator
00921       insert_after(const_iterator __pos, std::initializer_list<_Tp> __il)
00922       { return insert_after(__pos, __il.begin(), __il.end()); }
00923 
00924       /**
00925        *  @brief  Removes the element pointed to by the iterator following
00926        *          @c pos.
00927        *  @param  __pos  Iterator pointing before element to be erased.
00928        *  @return  An iterator pointing to the element following the one
00929        *           that was erased, or end() if no such element exists.
00930        *
00931        *  This function will erase the element at the given position and
00932        *  thus shorten the %forward_list by one.
00933        *
00934        *  Due to the nature of a %forward_list this operation can be done
00935        *  in constant time, and only invalidates iterators/references to
00936        *  the element being removed.  The user is also cautioned that
00937        *  this function only erases the element, and that if the element
00938        *  is itself a pointer, the pointed-to memory is not touched in
00939        *  any way.  Managing the pointer is the user's responsibility.
00940        */
00941       iterator
00942       erase_after(const_iterator __pos)
00943       { return iterator(this->_M_erase_after(const_cast<_Node_base*>
00944                                              (__pos._M_node))); }
00945 
00946       /**
00947        *  @brief  Remove a range of elements.
00948        *  @param  __pos  Iterator pointing before the first element to be
00949        *                 erased.
00950        *  @param  __last  Iterator pointing to one past the last element to be
00951        *                  erased.
00952        *  @return  @ __last.
00953        *
00954        *  This function will erase the elements in the range
00955        *  @a (__pos,__last) and shorten the %forward_list accordingly.
00956        *
00957        *  This operation is linear time in the size of the range and only
00958        *  invalidates iterators/references to the element being removed.
00959        *  The user is also cautioned that this function only erases the
00960        *  elements, and that if the elements themselves are pointers, the
00961        *  pointed-to memory is not touched in any way.  Managing the pointer
00962        *  is the user's responsibility.
00963        */
00964       iterator
00965       erase_after(const_iterator __pos, const_iterator __last)
00966       { return iterator(this->_M_erase_after(const_cast<_Node_base*>
00967                                              (__pos._M_node),
00968                                              const_cast<_Node_base*>
00969                                              (__last._M_node))); }
00970 
00971       /**
00972        *  @brief  Swaps data with another %forward_list.
00973        *  @param  __list  A %forward_list of the same element and allocator
00974        *                  types.
00975        *
00976        *  This exchanges the elements between two lists in constant
00977        *  time.  Note that the global std::swap() function is
00978        *  specialized such that std::swap(l1,l2) will feed to this
00979        *  function.
00980        */
00981       void
00982       swap(forward_list& __list)
00983       noexcept(_Node_alloc_traits::_S_nothrow_swap())
00984       {
00985         std::swap(this->_M_impl._M_head._M_next,
00986                   __list._M_impl._M_head._M_next);
00987         _Node_alloc_traits::_S_on_swap(this->_M_get_Node_allocator(),
00988                                        __list._M_get_Node_allocator());
00989       }
00990 
00991       /**
00992        *  @brief Resizes the %forward_list to the specified number of
00993        *         elements.
00994        *  @param __sz Number of elements the %forward_list should contain.
00995        *
00996        *  This function will %resize the %forward_list to the specified
00997        *  number of elements.  If the number is smaller than the
00998        *  %forward_list's current number of elements the %forward_list
00999        *  is truncated, otherwise the %forward_list is extended and the
01000        *  new elements are default constructed.
01001        */
01002       void
01003       resize(size_type __sz);
01004 
01005       /**
01006        *  @brief Resizes the %forward_list to the specified number of
01007        *         elements.
01008        *  @param __sz Number of elements the %forward_list should contain.
01009        *  @param __val Data with which new elements should be populated.
01010        *
01011        *  This function will %resize the %forward_list to the specified
01012        *  number of elements.  If the number is smaller than the
01013        *  %forward_list's current number of elements the %forward_list
01014        *  is truncated, otherwise the %forward_list is extended and new
01015        *  elements are populated with given data.
01016        */
01017       void
01018       resize(size_type __sz, const value_type& __val);
01019 
01020       /**
01021        *  @brief  Erases all the elements.
01022        *
01023        *  Note that this function only erases
01024        *  the elements, and that if the elements themselves are
01025        *  pointers, the pointed-to memory is not touched in any way.
01026        *  Managing the pointer is the user's responsibility.
01027        */
01028       void
01029       clear() noexcept
01030       { this->_M_erase_after(&this->_M_impl._M_head, 0); }
01031 
01032       // 23.3.4.6 forward_list operations:
01033 
01034       /**
01035        *  @brief  Insert contents of another %forward_list.
01036        *  @param  __pos  Iterator referencing the element to insert after.
01037        *  @param  __list  Source list.
01038        *
01039        *  The elements of @a list are inserted in constant time after
01040        *  the element referenced by @a pos.  @a list becomes an empty
01041        *  list.
01042        *
01043        *  Requires this != @a x.
01044        */
01045       void
01046       splice_after(const_iterator __pos, forward_list&& __list)
01047       {
01048         if (!__list.empty())
01049           _M_splice_after(__pos, __list.before_begin(), __list.end());
01050       }
01051 
01052       void
01053       splice_after(const_iterator __pos, forward_list& __list)
01054       { splice_after(__pos, std::move(__list)); }
01055 
01056       /**
01057        *  @brief  Insert element from another %forward_list.
01058        *  @param  __pos  Iterator referencing the element to insert after.
01059        *  @param  __list  Source list.
01060        *  @param  __i   Iterator referencing the element before the element
01061        *                to move.
01062        *
01063        *  Removes the element in list @a list referenced by @a i and
01064        *  inserts it into the current list after @a pos.
01065        */
01066       void
01067       splice_after(const_iterator __pos, forward_list&& __list,
01068                    const_iterator __i);
01069 
01070       void
01071       splice_after(const_iterator __pos, forward_list& __list,
01072                    const_iterator __i)
01073       { splice_after(__pos, std::move(__list), __i); }
01074 
01075       /**
01076        *  @brief  Insert range from another %forward_list.
01077        *  @param  __pos  Iterator referencing the element to insert after.
01078        *  @param  __list  Source list.
01079        *  @param  __before  Iterator referencing before the start of range
01080        *                    in list.
01081        *  @param  __last  Iterator referencing the end of range in list.
01082        *
01083        *  Removes elements in the range (__before,__last) and inserts them
01084        *  after @a __pos in constant time.
01085        *
01086        *  Undefined if @a __pos is in (__before,__last).
01087        *  @{
01088        */
01089       void
01090       splice_after(const_iterator __pos, forward_list&&,
01091                    const_iterator __before, const_iterator __last)
01092       { _M_splice_after(__pos, __before, __last); }
01093 
01094       void
01095       splice_after(const_iterator __pos, forward_list&,
01096                    const_iterator __before, const_iterator __last)
01097       { _M_splice_after(__pos, __before, __last); }
01098       // @}
01099 
01100       /**
01101        *  @brief  Remove all elements equal to value.
01102        *  @param  __val  The value to remove.
01103        *
01104        *  Removes every element in the list equal to @a __val.
01105        *  Remaining elements stay in list order.  Note that this
01106        *  function only erases the elements, and that if the elements
01107        *  themselves are pointers, the pointed-to memory is not
01108        *  touched in any way.  Managing the pointer is the user's
01109        *  responsibility.
01110        */
01111       void
01112       remove(const _Tp& __val);
01113 
01114       /**
01115        *  @brief  Remove all elements satisfying a predicate.
01116        *  @param  __pred  Unary predicate function or object.
01117        *
01118        *  Removes every element in the list for which the predicate
01119        *  returns true.  Remaining elements stay in list order.  Note
01120        *  that this function only erases the elements, and that if the
01121        *  elements themselves are pointers, the pointed-to memory is
01122        *  not touched in any way.  Managing the pointer is the user's
01123        *  responsibility.
01124        */
01125       template<typename _Pred>
01126         void
01127         remove_if(_Pred __pred);
01128 
01129       /**
01130        *  @brief  Remove consecutive duplicate elements.
01131        *
01132        *  For each consecutive set of elements with the same value,
01133        *  remove all but the first one.  Remaining elements stay in
01134        *  list order.  Note that this function only erases the
01135        *  elements, and that if the elements themselves are pointers,
01136        *  the pointed-to memory is not touched in any way.  Managing
01137        *  the pointer is the user's responsibility.
01138        */
01139       void
01140       unique()
01141       { unique(std::equal_to<_Tp>()); }
01142 
01143       /**
01144        *  @brief  Remove consecutive elements satisfying a predicate.
01145        *  @param  __binary_pred  Binary predicate function or object.
01146        *
01147        *  For each consecutive set of elements [first,last) that
01148        *  satisfy predicate(first,i) where i is an iterator in
01149        *  [first,last), remove all but the first one.  Remaining
01150        *  elements stay in list order.  Note that this function only
01151        *  erases the elements, and that if the elements themselves are
01152        *  pointers, the pointed-to memory is not touched in any way.
01153        *  Managing the pointer is the user's responsibility.
01154        */
01155       template<typename _BinPred>
01156         void
01157         unique(_BinPred __binary_pred);
01158 
01159       /**
01160        *  @brief  Merge sorted lists.
01161        *  @param  __list  Sorted list to merge.
01162        *
01163        *  Assumes that both @a list and this list are sorted according to
01164        *  operator<().  Merges elements of @a __list into this list in
01165        *  sorted order, leaving @a __list empty when complete.  Elements in
01166        *  this list precede elements in @a __list that are equal.
01167        */
01168       void
01169       merge(forward_list&& __list)
01170       { merge(std::move(__list), std::less<_Tp>()); }
01171 
01172       void
01173       merge(forward_list& __list)
01174       { merge(std::move(__list)); }
01175 
01176       /**
01177        *  @brief  Merge sorted lists according to comparison function.
01178        *  @param  __list  Sorted list to merge.
01179        *  @param  __comp Comparison function defining sort order.
01180        *
01181        *  Assumes that both @a __list and this list are sorted according to
01182        *  comp.  Merges elements of @a __list into this list
01183        *  in sorted order, leaving @a __list empty when complete.  Elements
01184        *  in this list precede elements in @a __list that are equivalent
01185        *  according to comp().
01186        */
01187       template<typename _Comp>
01188         void
01189         merge(forward_list&& __list, _Comp __comp);
01190 
01191       template<typename _Comp>
01192         void
01193         merge(forward_list& __list, _Comp __comp)
01194         { merge(std::move(__list), __comp); }
01195 
01196       /**
01197        *  @brief  Sort the elements of the list.
01198        *
01199        *  Sorts the elements of this list in NlogN time.  Equivalent
01200        *  elements remain in list order.
01201        */
01202       void
01203       sort()
01204       { sort(std::less<_Tp>()); }
01205 
01206       /**
01207        *  @brief  Sort the forward_list using a comparison function.
01208        *
01209        *  Sorts the elements of this list in NlogN time.  Equivalent
01210        *  elements remain in list order.
01211        */
01212       template<typename _Comp>
01213         void
01214         sort(_Comp __comp);
01215 
01216       /**
01217        *  @brief  Reverse the elements in list.
01218        *
01219        *  Reverse the order of elements in the list in linear time.
01220        */
01221       void
01222       reverse() noexcept
01223       { this->_M_impl._M_head._M_reverse_after(); }
01224 
01225     private:
01226       // Called by the range constructor to implement [23.3.4.2]/9
01227       template<typename _InputIterator>
01228         void
01229         _M_range_initialize(_InputIterator __first, _InputIterator __last);
01230 
01231       // Called by forward_list(n,v,a), and the range constructor when it
01232       // turns out to be the same thing.
01233       void
01234       _M_fill_initialize(size_type __n, const value_type& __value);
01235 
01236       // Called by splice_after and insert_after.
01237       iterator
01238       _M_splice_after(const_iterator __pos, const_iterator __before,
01239                       const_iterator __last);
01240 
01241       // Called by forward_list(n).
01242       void
01243       _M_default_initialize(size_type __n);
01244 
01245       // Called by resize(sz).
01246       void
01247       _M_default_insert_after(const_iterator __pos, size_type __n);
01248 
01249       // Called by operator=(forward_list&&)
01250       void
01251       _M_move_assign(forward_list&& __list, std::true_type) noexcept
01252       {
01253         clear();
01254         std::swap(this->_M_impl._M_head._M_next,
01255                   __list._M_impl._M_head._M_next);
01256         std::__alloc_on_move(this->_M_get_Node_allocator(),
01257                              __list._M_get_Node_allocator());
01258       }
01259 
01260       // Called by operator=(forward_list&&)
01261       void
01262       _M_move_assign(forward_list&& __list, std::false_type)
01263       {
01264         if (__list._M_get_Node_allocator() == this->_M_get_Node_allocator())
01265           _M_move_assign(std::move(__list), std::true_type());
01266         else
01267           // The rvalue's allocator cannot be moved, or is not equal,
01268           // so we need to individually move each element.
01269           this->assign(std::__make_move_if_noexcept_iterator(__list.begin()),
01270                        std::__make_move_if_noexcept_iterator(__list.end()));
01271       }
01272 
01273       // Called by assign(_InputIterator, _InputIterator) if _Tp is
01274       // CopyAssignable.
01275       template<typename _InputIterator>
01276         void
01277         _M_assign(_InputIterator __first, _InputIterator __last, true_type)
01278         {
01279           auto __prev = before_begin();
01280           auto __curr = begin();
01281           auto __end = end();
01282           while (__curr != __end && __first != __last)
01283             {
01284               *__curr = *__first;
01285               ++__prev;
01286               ++__curr;
01287               ++__first;
01288             }
01289           if (__first != __last)
01290             insert_after(__prev, __first, __last);
01291           else if (__curr != __end)
01292             erase_after(__prev, __end);
01293         }
01294 
01295       // Called by assign(_InputIterator, _InputIterator) if _Tp is not
01296       // CopyAssignable.
01297       template<typename _InputIterator>
01298         void
01299         _M_assign(_InputIterator __first, _InputIterator __last, false_type)
01300         {
01301           clear();
01302           insert_after(cbefore_begin(), __first, __last);
01303         }
01304 
01305       // Called by assign(size_type, const _Tp&) if Tp is CopyAssignable
01306       void
01307       _M_assign_n(size_type __n, const _Tp& __val, true_type)
01308       {
01309         auto __prev = before_begin();
01310         auto __curr = begin();
01311         auto __end = end();
01312         while (__curr != __end && __n > 0)
01313           {
01314             *__curr = __val;
01315             ++__prev;
01316             ++__curr;
01317             --__n;
01318           }
01319         if (__n > 0)
01320           insert_after(__prev, __n, __val);
01321         else if (__curr != __end)
01322           erase_after(__prev, __end);
01323       }
01324 
01325       // Called by assign(size_type, const _Tp&) if Tp is non-CopyAssignable
01326       void
01327       _M_assign_n(size_type __n, const _Tp& __val, false_type)
01328       {
01329         clear();
01330         insert_after(cbefore_begin(), __n, __val);
01331       }
01332     };
01333 
01334   /**
01335    *  @brief  Forward list equality comparison.
01336    *  @param  __lx  A %forward_list
01337    *  @param  __ly  A %forward_list of the same type as @a __lx.
01338    *  @return  True iff the elements of the forward lists are equal.
01339    *
01340    *  This is an equivalence relation.  It is linear in the number of 
01341    *  elements of the forward lists.  Deques are considered equivalent
01342    *  if corresponding elements compare equal.
01343    */
01344   template<typename _Tp, typename _Alloc>
01345     bool
01346     operator==(const forward_list<_Tp, _Alloc>& __lx,
01347                const forward_list<_Tp, _Alloc>& __ly);
01348 
01349   /**
01350    *  @brief  Forward list ordering relation.
01351    *  @param  __lx  A %forward_list.
01352    *  @param  __ly  A %forward_list of the same type as @a __lx.
01353    *  @return  True iff @a __lx is lexicographically less than @a __ly.
01354    *
01355    *  This is a total ordering relation.  It is linear in the number of 
01356    *  elements of the forward lists.  The elements must be comparable
01357    *  with @c <.
01358    *
01359    *  See std::lexicographical_compare() for how the determination is made.
01360    */
01361   template<typename _Tp, typename _Alloc>
01362     inline bool
01363     operator<(const forward_list<_Tp, _Alloc>& __lx,
01364               const forward_list<_Tp, _Alloc>& __ly)
01365     { return std::lexicographical_compare(__lx.cbegin(), __lx.cend(),
01366                                           __ly.cbegin(), __ly.cend()); }
01367 
01368   /// Based on operator==
01369   template<typename _Tp, typename _Alloc>
01370     inline bool
01371     operator!=(const forward_list<_Tp, _Alloc>& __lx,
01372                const forward_list<_Tp, _Alloc>& __ly)
01373     { return !(__lx == __ly); }
01374 
01375   /// Based on operator<
01376   template<typename _Tp, typename _Alloc>
01377     inline bool
01378     operator>(const forward_list<_Tp, _Alloc>& __lx,
01379               const forward_list<_Tp, _Alloc>& __ly)
01380     { return (__ly < __lx); }
01381 
01382   /// Based on operator<
01383   template<typename _Tp, typename _Alloc>
01384     inline bool
01385     operator>=(const forward_list<_Tp, _Alloc>& __lx,
01386                const forward_list<_Tp, _Alloc>& __ly)
01387     { return !(__lx < __ly); }
01388 
01389   /// Based on operator<
01390   template<typename _Tp, typename _Alloc>
01391     inline bool
01392     operator<=(const forward_list<_Tp, _Alloc>& __lx,
01393                const forward_list<_Tp, _Alloc>& __ly)
01394     { return !(__ly < __lx); }
01395 
01396   /// See std::forward_list::swap().
01397   template<typename _Tp, typename _Alloc>
01398     inline void
01399     swap(forward_list<_Tp, _Alloc>& __lx,
01400          forward_list<_Tp, _Alloc>& __ly)
01401     { __lx.swap(__ly); }
01402 
01403 _GLIBCXX_END_NAMESPACE_CONTAINER
01404 } // namespace std
01405 
01406 #endif // _FORWARD_LIST_H