libstdc++
forward_list.h
Go to the documentation of this file.
00001 // <forward_list.h> -*- C++ -*-
00002 
00003 // Copyright (C) 2008-2017 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 this->_M_impl; }
00309 
00310       const _Node_alloc_type&
00311       _M_get_Node_allocator() const noexcept
00312       { return this->_M_impl; }
00313 
00314       _Fwd_list_base()
00315       : _M_impl() { }
00316 
00317       _Fwd_list_base(_Node_alloc_type&& __a)
00318       : _M_impl(std::move(__a)) { }
00319 
00320       _Fwd_list_base(_Fwd_list_base&& __lst, _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        */
00439       forward_list()
00440       noexcept(is_nothrow_default_constructible<_Node_alloc_type>::value)
00441       : _Base()
00442       { }
00443 
00444       /**
00445        *  @brief  Creates a %forward_list with no elements.
00446        *  @param  __al  An allocator object.
00447        */
00448       explicit
00449       forward_list(const _Alloc& __al) noexcept
00450       : _Base(_Node_alloc_type(__al))
00451       { }
00452 
00453 
00454       /**
00455        *  @brief  Copy constructor with allocator argument.
00456        *  @param  __list  Input list to copy.
00457        *  @param  __al    An allocator object.
00458        */
00459       forward_list(const forward_list& __list, const _Alloc& __al)
00460       : _Base(_Node_alloc_type(__al))
00461       { _M_range_initialize(__list.begin(), __list.end()); }
00462 
00463       /**
00464        *  @brief  Move constructor with allocator argument.
00465        *  @param  __list  Input list to move.
00466        *  @param  __al    An allocator object.
00467        */
00468       forward_list(forward_list&& __list, const _Alloc& __al)
00469       noexcept(_Node_alloc_traits::_S_always_equal())
00470       : _Base(std::move(__list), _Node_alloc_type(__al))
00471       {
00472         // If __list is not empty it means its allocator is not equal to __a,
00473         // so we need to move from each element individually.
00474         insert_after(cbefore_begin(),
00475                      std::__make_move_if_noexcept_iterator(__list.begin()),
00476                      std::__make_move_if_noexcept_iterator(__list.end()));
00477       }
00478 
00479       /**
00480        *  @brief  Creates a %forward_list with default constructed elements.
00481        *  @param  __n   The number of elements to initially create.
00482        *  @param  __al  An allocator object.
00483        *
00484        *  This constructor creates the %forward_list with @a __n default
00485        *  constructed elements.
00486        */
00487       explicit
00488       forward_list(size_type __n, const _Alloc& __al = _Alloc())
00489       : _Base(_Node_alloc_type(__al))
00490       { _M_default_initialize(__n); }
00491 
00492       /**
00493        *  @brief  Creates a %forward_list with copies of an exemplar element.
00494        *  @param  __n      The number of elements to initially create.
00495        *  @param  __value  An element to copy.
00496        *  @param  __al     An allocator object.
00497        *
00498        *  This constructor fills the %forward_list with @a __n copies of
00499        *  @a __value.
00500        */
00501       forward_list(size_type __n, const _Tp& __value,
00502                    const _Alloc& __al = _Alloc())
00503       : _Base(_Node_alloc_type(__al))
00504       { _M_fill_initialize(__n, __value); }
00505 
00506       /**
00507        *  @brief  Builds a %forward_list from a range.
00508        *  @param  __first  An input iterator.
00509        *  @param  __last   An input iterator.
00510        *  @param  __al     An allocator object.
00511        *
00512        *  Create a %forward_list consisting of copies of the elements from
00513        *  [@a __first,@a __last).  This is linear in N (where N is
00514        *  distance(@a __first,@a __last)).
00515        */
00516       template<typename _InputIterator,
00517                typename = std::_RequireInputIter<_InputIterator>>
00518         forward_list(_InputIterator __first, _InputIterator __last,
00519                      const _Alloc& __al = _Alloc())
00520         : _Base(_Node_alloc_type(__al))
00521         { _M_range_initialize(__first, __last); }
00522 
00523       /**
00524        *  @brief  The %forward_list copy constructor.
00525        *  @param  __list  A %forward_list of identical element and allocator
00526        *                  types.
00527        */
00528       forward_list(const forward_list& __list)
00529       : _Base(_Node_alloc_traits::_S_select_on_copy(
00530                 __list._M_get_Node_allocator()))
00531       { _M_range_initialize(__list.begin(), __list.end()); }
00532 
00533       /**
00534        *  @brief  The %forward_list move constructor.
00535        *  @param  __list  A %forward_list of identical element and allocator
00536        *                  types.
00537        *
00538        *  The newly-created %forward_list contains the exact contents of @a
00539        *  __list. The contents of @a __list are a valid, but unspecified
00540        *  %forward_list.
00541        */
00542       forward_list(forward_list&& __list) noexcept
00543       : _Base(std::move(__list)) { }
00544 
00545       /**
00546        *  @brief  Builds a %forward_list from an initializer_list
00547        *  @param  __il  An initializer_list of value_type.
00548        *  @param  __al  An allocator object.
00549        *
00550        *  Create a %forward_list consisting of copies of the elements
00551        *  in the initializer_list @a __il.  This is linear in __il.size().
00552        */
00553       forward_list(std::initializer_list<_Tp> __il,
00554                    const _Alloc& __al = _Alloc())
00555       : _Base(_Node_alloc_type(__al))
00556       { _M_range_initialize(__il.begin(), __il.end()); }
00557 
00558       /**
00559        *  @brief  The forward_list dtor.
00560        */
00561       ~forward_list() noexcept
00562       { }
00563 
00564       /**
00565        *  @brief  The %forward_list assignment operator.
00566        *  @param  __list  A %forward_list of identical element and allocator
00567        *                types.
00568        *
00569        *  All the elements of @a __list are copied.
00570        *
00571        *  Whether the allocator is copied depends on the allocator traits.
00572        */
00573       forward_list&
00574       operator=(const forward_list& __list);
00575 
00576       /**
00577        *  @brief  The %forward_list move assignment operator.
00578        *  @param  __list  A %forward_list of identical element and allocator
00579        *                types.
00580        *
00581        *  The contents of @a __list are moved into this %forward_list
00582        *  (without copying, if the allocators permit it).
00583        *
00584        *  Afterwards @a __list is a valid, but unspecified %forward_list
00585        *
00586        *  Whether the allocator is moved depends on the allocator traits.
00587        */
00588       forward_list&
00589       operator=(forward_list&& __list)
00590       noexcept(_Node_alloc_traits::_S_nothrow_move())
00591       {
00592         constexpr bool __move_storage =
00593           _Node_alloc_traits::_S_propagate_on_move_assign()
00594           || _Node_alloc_traits::_S_always_equal();
00595         _M_move_assign(std::move(__list), __bool_constant<__move_storage>());
00596         return *this;
00597       }
00598 
00599       /**
00600        *  @brief  The %forward_list initializer list assignment operator.
00601        *  @param  __il  An initializer_list of value_type.
00602        *
00603        *  Replace the contents of the %forward_list with copies of the
00604        *  elements in the initializer_list @a __il.  This is linear in
00605        *  __il.size().
00606        */
00607       forward_list&
00608       operator=(std::initializer_list<_Tp> __il)
00609       {
00610         assign(__il);
00611         return *this;
00612       }
00613 
00614       /**
00615        *  @brief  Assigns a range to a %forward_list.
00616        *  @param  __first  An input iterator.
00617        *  @param  __last   An input iterator.
00618        *
00619        *  This function fills a %forward_list with copies of the elements
00620        *  in the range [@a __first,@a __last).
00621        *
00622        *  Note that the assignment completely changes the %forward_list and
00623        *  that the number of elements of the resulting %forward_list is the
00624        *  same as the number of elements assigned.
00625        */
00626       template<typename _InputIterator,
00627                typename = std::_RequireInputIter<_InputIterator>>
00628         void
00629         assign(_InputIterator __first, _InputIterator __last)
00630         {
00631           typedef is_assignable<_Tp, decltype(*__first)> __assignable;
00632           _M_assign(__first, __last, __assignable());
00633         }
00634 
00635       /**
00636        *  @brief  Assigns a given value to a %forward_list.
00637        *  @param  __n  Number of elements to be assigned.
00638        *  @param  __val  Value to be assigned.
00639        *
00640        *  This function fills a %forward_list with @a __n copies of the
00641        *  given value.  Note that the assignment completely changes the
00642        *  %forward_list, and that the resulting %forward_list has __n
00643        *  elements.
00644        */
00645       void
00646       assign(size_type __n, const _Tp& __val)
00647       { _M_assign_n(__n, __val, is_copy_assignable<_Tp>()); }
00648 
00649       /**
00650        *  @brief  Assigns an initializer_list to a %forward_list.
00651        *  @param  __il  An initializer_list of value_type.
00652        *
00653        *  Replace the contents of the %forward_list with copies of the
00654        *  elements in the initializer_list @a __il.  This is linear in
00655        *  il.size().
00656        */
00657       void
00658       assign(std::initializer_list<_Tp> __il)
00659       { assign(__il.begin(), __il.end()); }
00660 
00661       /// Get a copy of the memory allocation object.
00662       allocator_type
00663       get_allocator() const noexcept
00664       { return allocator_type(this->_M_get_Node_allocator()); }
00665 
00666       // 23.3.4.3 iterators:
00667 
00668       /**
00669        *  Returns a read/write iterator that points before the first element
00670        *  in the %forward_list.  Iteration is done in ordinary element order.
00671        */
00672       iterator
00673       before_begin() noexcept
00674       { return iterator(&this->_M_impl._M_head); }
00675 
00676       /**
00677        *  Returns a read-only (constant) iterator that points before the
00678        *  first element in the %forward_list.  Iteration is done in ordinary
00679        *  element order.
00680        */
00681       const_iterator
00682       before_begin() const noexcept
00683       { return const_iterator(&this->_M_impl._M_head); }
00684 
00685       /**
00686        *  Returns a read/write iterator that points to the first element
00687        *  in the %forward_list.  Iteration is done in ordinary element order.
00688        */
00689       iterator
00690       begin() noexcept
00691       { return iterator(this->_M_impl._M_head._M_next); }
00692 
00693       /**
00694        *  Returns a read-only (constant) iterator that points to the first
00695        *  element in the %forward_list.  Iteration is done in ordinary
00696        *  element order.
00697        */
00698       const_iterator
00699       begin() const noexcept
00700       { return const_iterator(this->_M_impl._M_head._M_next); }
00701 
00702       /**
00703        *  Returns a read/write iterator that points one past the last
00704        *  element in the %forward_list.  Iteration is done in ordinary
00705        *  element order.
00706        */
00707       iterator
00708       end() noexcept
00709       { return iterator(0); }
00710 
00711       /**
00712        *  Returns a read-only iterator that points one past the last
00713        *  element in the %forward_list.  Iteration is done in ordinary
00714        *  element order.
00715        */
00716       const_iterator
00717       end() const noexcept
00718       { return const_iterator(0); }
00719 
00720       /**
00721        *  Returns a read-only (constant) iterator that points to the
00722        *  first element in the %forward_list.  Iteration is done in ordinary
00723        *  element order.
00724        */
00725       const_iterator
00726       cbegin() const noexcept
00727       { return const_iterator(this->_M_impl._M_head._M_next); }
00728 
00729       /**
00730        *  Returns a read-only (constant) iterator that points before the
00731        *  first element in the %forward_list.  Iteration is done in ordinary
00732        *  element order.
00733        */
00734       const_iterator
00735       cbefore_begin() const noexcept
00736       { return const_iterator(&this->_M_impl._M_head); }
00737 
00738       /**
00739        *  Returns a read-only (constant) iterator that points one past
00740        *  the last element in the %forward_list.  Iteration is done in
00741        *  ordinary element order.
00742        */
00743       const_iterator
00744       cend() const noexcept
00745       { return const_iterator(0); }
00746 
00747       /**
00748        *  Returns true if the %forward_list is empty.  (Thus begin() would
00749        *  equal end().)
00750        */
00751       bool
00752       empty() const noexcept
00753       { return this->_M_impl._M_head._M_next == 0; }
00754 
00755       /**
00756        *  Returns the largest possible number of elements of %forward_list.
00757        */
00758       size_type
00759       max_size() const noexcept
00760       { return _Node_alloc_traits::max_size(this->_M_get_Node_allocator()); }
00761 
00762       // 23.3.4.4 element access:
00763 
00764       /**
00765        *  Returns a read/write reference to the data at the first
00766        *  element of the %forward_list.
00767        */
00768       reference
00769       front()
00770       {
00771         _Node* __front = static_cast<_Node*>(this->_M_impl._M_head._M_next);
00772         return *__front->_M_valptr();
00773       }
00774 
00775       /**
00776        *  Returns a read-only (constant) reference to the data at the first
00777        *  element of the %forward_list.
00778        */
00779       const_reference
00780       front() const
00781       {
00782         _Node* __front = static_cast<_Node*>(this->_M_impl._M_head._M_next);
00783         return *__front->_M_valptr();
00784       }
00785 
00786       // 23.3.4.5 modifiers:
00787 
00788       /**
00789        *  @brief  Constructs object in %forward_list at the front of the
00790        *          list.
00791        *  @param  __args  Arguments.
00792        *
00793        *  This function will insert an object of type Tp constructed
00794        *  with Tp(std::forward<Args>(args)...) at the front of the list
00795        *  Due to the nature of a %forward_list this operation can
00796        *  be done in constant time, and does not invalidate iterators
00797        *  and references.
00798        */
00799       template<typename... _Args>
00800 #if __cplusplus > 201402L
00801         reference
00802 #else
00803         void
00804 #endif
00805         emplace_front(_Args&&... __args)
00806         {
00807           this->_M_insert_after(cbefore_begin(),
00808                                 std::forward<_Args>(__args)...);
00809 #if __cplusplus > 201402L
00810           return front();
00811 #endif
00812         }
00813 
00814       /**
00815        *  @brief  Add data to the front of the %forward_list.
00816        *  @param  __val  Data to be added.
00817        *
00818        *  This is a typical stack operation.  The function creates an
00819        *  element at the front of the %forward_list and assigns the given
00820        *  data to it.  Due to the nature of a %forward_list this operation
00821        *  can be done in constant time, and does not invalidate iterators
00822        *  and references.
00823        */
00824       void
00825       push_front(const _Tp& __val)
00826       { this->_M_insert_after(cbefore_begin(), __val); }
00827 
00828       /**
00829        *
00830        */
00831       void
00832       push_front(_Tp&& __val)
00833       { this->_M_insert_after(cbefore_begin(), std::move(__val)); }
00834 
00835       /**
00836        *  @brief  Removes first element.
00837        *
00838        *  This is a typical stack operation.  It shrinks the %forward_list
00839        *  by one.  Due to the nature of a %forward_list this operation can
00840        *  be done in constant time, and only invalidates iterators/references
00841        *  to the element being removed.
00842        *
00843        *  Note that no data is returned, and if the first element's data
00844        *  is needed, it should be retrieved before pop_front() is
00845        *  called.
00846        */
00847       void
00848       pop_front()
00849       { this->_M_erase_after(&this->_M_impl._M_head); }
00850 
00851       /**
00852        *  @brief  Constructs object in %forward_list after the specified
00853        *          iterator.
00854        *  @param  __pos  A const_iterator into the %forward_list.
00855        *  @param  __args  Arguments.
00856        *  @return  An iterator that points to the inserted data.
00857        *
00858        *  This function will insert an object of type T constructed
00859        *  with T(std::forward<Args>(args)...) after the specified
00860        *  location.  Due to the nature of a %forward_list this operation can
00861        *  be done in constant time, and does not invalidate iterators
00862        *  and references.
00863        */
00864       template<typename... _Args>
00865         iterator
00866         emplace_after(const_iterator __pos, _Args&&... __args)
00867         { return iterator(this->_M_insert_after(__pos,
00868                                           std::forward<_Args>(__args)...)); }
00869 
00870       /**
00871        *  @brief  Inserts given value into %forward_list after specified
00872        *          iterator.
00873        *  @param  __pos  An iterator into the %forward_list.
00874        *  @param  __val  Data to be inserted.
00875        *  @return  An iterator that points to the inserted data.
00876        *
00877        *  This function will insert a copy of the given value after
00878        *  the specified location.  Due to the nature of a %forward_list this
00879        *  operation can be done in constant time, and does not
00880        *  invalidate iterators and references.
00881        */
00882       iterator
00883       insert_after(const_iterator __pos, const _Tp& __val)
00884       { return iterator(this->_M_insert_after(__pos, __val)); }
00885 
00886       /**
00887        *
00888        */
00889       iterator
00890       insert_after(const_iterator __pos, _Tp&& __val)
00891       { return iterator(this->_M_insert_after(__pos, std::move(__val))); }
00892 
00893       /**
00894        *  @brief  Inserts a number of copies of given data into the
00895        *          %forward_list.
00896        *  @param  __pos  An iterator into the %forward_list.
00897        *  @param  __n  Number of elements to be inserted.
00898        *  @param  __val  Data to be inserted.
00899        *  @return  An iterator pointing to the last inserted copy of
00900        *           @a val or @a pos if @a n == 0.
00901        *
00902        *  This function will insert a specified number of copies of the
00903        *  given data after the location specified by @a pos.
00904        *
00905        *  This operation is linear in the number of elements inserted and
00906        *  does not invalidate iterators and references.
00907        */
00908       iterator
00909       insert_after(const_iterator __pos, size_type __n, const _Tp& __val);
00910 
00911       /**
00912        *  @brief  Inserts a range into the %forward_list.
00913        *  @param  __pos  An iterator into the %forward_list.
00914        *  @param  __first  An input iterator.
00915        *  @param  __last   An input iterator.
00916        *  @return  An iterator pointing to the last inserted element or
00917        *           @a __pos if @a __first == @a __last.
00918        *
00919        *  This function will insert copies of the data in the range
00920        *  [@a __first,@a __last) into the %forward_list after the
00921        *  location specified by @a __pos.
00922        *
00923        *  This operation is linear in the number of elements inserted and
00924        *  does not invalidate iterators and references.
00925        */
00926       template<typename _InputIterator,
00927                typename = std::_RequireInputIter<_InputIterator>>
00928         iterator
00929         insert_after(const_iterator __pos,
00930                      _InputIterator __first, _InputIterator __last);
00931 
00932       /**
00933        *  @brief  Inserts the contents of an initializer_list into
00934        *          %forward_list after the specified iterator.
00935        *  @param  __pos  An iterator into the %forward_list.
00936        *  @param  __il  An initializer_list of value_type.
00937        *  @return  An iterator pointing to the last inserted element
00938        *           or @a __pos if @a __il is empty.
00939        *
00940        *  This function will insert copies of the data in the
00941        *  initializer_list @a __il into the %forward_list before the location
00942        *  specified by @a __pos.
00943        *
00944        *  This operation is linear in the number of elements inserted and
00945        *  does not invalidate iterators and references.
00946        */
00947       iterator
00948       insert_after(const_iterator __pos, std::initializer_list<_Tp> __il)
00949       { return insert_after(__pos, __il.begin(), __il.end()); }
00950 
00951       /**
00952        *  @brief  Removes the element pointed to by the iterator following
00953        *          @c pos.
00954        *  @param  __pos  Iterator pointing before element to be erased.
00955        *  @return  An iterator pointing to the element following the one
00956        *           that was erased, or end() if no such element exists.
00957        *
00958        *  This function will erase the element at the given position and
00959        *  thus shorten the %forward_list by one.
00960        *
00961        *  Due to the nature of a %forward_list this operation can be done
00962        *  in constant time, and only invalidates iterators/references to
00963        *  the element being removed.  The user is also cautioned that
00964        *  this function only erases the element, and that if the element
00965        *  is itself a pointer, the pointed-to memory is not touched in
00966        *  any way.  Managing the pointer is the user's responsibility.
00967        */
00968       iterator
00969       erase_after(const_iterator __pos)
00970       { return iterator(this->_M_erase_after(const_cast<_Node_base*>
00971                                              (__pos._M_node))); }
00972 
00973       /**
00974        *  @brief  Remove a range of elements.
00975        *  @param  __pos  Iterator pointing before the first element to be
00976        *                 erased.
00977        *  @param  __last  Iterator pointing to one past the last element to be
00978        *                  erased.
00979        *  @return  @ __last.
00980        *
00981        *  This function will erase the elements in the range
00982        *  @a (__pos,__last) and shorten the %forward_list accordingly.
00983        *
00984        *  This operation is linear time in the size of the range and only
00985        *  invalidates iterators/references to the element being removed.
00986        *  The user is also cautioned that this function only erases the
00987        *  elements, and that if the elements themselves are pointers, the
00988        *  pointed-to memory is not touched in any way.  Managing the pointer
00989        *  is the user's responsibility.
00990        */
00991       iterator
00992       erase_after(const_iterator __pos, const_iterator __last)
00993       { return iterator(this->_M_erase_after(const_cast<_Node_base*>
00994                                              (__pos._M_node),
00995                                              const_cast<_Node_base*>
00996                                              (__last._M_node))); }
00997 
00998       /**
00999        *  @brief  Swaps data with another %forward_list.
01000        *  @param  __list  A %forward_list of the same element and allocator
01001        *                  types.
01002        *
01003        *  This exchanges the elements between two lists in constant
01004        *  time.  Note that the global std::swap() function is
01005        *  specialized such that std::swap(l1,l2) will feed to this
01006        *  function.
01007        *
01008        *  Whether the allocators are swapped depends on the allocator traits.
01009        */
01010       void
01011       swap(forward_list& __list) noexcept
01012       {
01013         std::swap(this->_M_impl._M_head._M_next,
01014                   __list._M_impl._M_head._M_next);
01015         _Node_alloc_traits::_S_on_swap(this->_M_get_Node_allocator(),
01016                                        __list._M_get_Node_allocator());
01017       }
01018 
01019       /**
01020        *  @brief Resizes the %forward_list to the specified number of
01021        *         elements.
01022        *  @param __sz Number of elements the %forward_list should contain.
01023        *
01024        *  This function will %resize the %forward_list to the specified
01025        *  number of elements.  If the number is smaller than the
01026        *  %forward_list's current number of elements the %forward_list
01027        *  is truncated, otherwise the %forward_list is extended and the
01028        *  new elements are default constructed.
01029        */
01030       void
01031       resize(size_type __sz);
01032 
01033       /**
01034        *  @brief Resizes the %forward_list to the specified number of
01035        *         elements.
01036        *  @param __sz Number of elements the %forward_list should contain.
01037        *  @param __val Data with which new elements should be populated.
01038        *
01039        *  This function will %resize the %forward_list to the specified
01040        *  number of elements.  If the number is smaller than the
01041        *  %forward_list's current number of elements the %forward_list
01042        *  is truncated, otherwise the %forward_list is extended and new
01043        *  elements are populated with given data.
01044        */
01045       void
01046       resize(size_type __sz, const value_type& __val);
01047 
01048       /**
01049        *  @brief  Erases all the elements.
01050        *
01051        *  Note that this function only erases
01052        *  the elements, and that if the elements themselves are
01053        *  pointers, the pointed-to memory is not touched in any way.
01054        *  Managing the pointer is the user's responsibility.
01055        */
01056       void
01057       clear() noexcept
01058       { this->_M_erase_after(&this->_M_impl._M_head, 0); }
01059 
01060       // 23.3.4.6 forward_list operations:
01061 
01062       /**
01063        *  @brief  Insert contents of another %forward_list.
01064        *  @param  __pos  Iterator referencing the element to insert after.
01065        *  @param  __list  Source list.
01066        *
01067        *  The elements of @a list are inserted in constant time after
01068        *  the element referenced by @a pos.  @a list becomes an empty
01069        *  list.
01070        *
01071        *  Requires this != @a x.
01072        */
01073       void
01074       splice_after(const_iterator __pos, forward_list&& __list) noexcept
01075       {
01076         if (!__list.empty())
01077           _M_splice_after(__pos, __list.before_begin(), __list.end());
01078       }
01079 
01080       void
01081       splice_after(const_iterator __pos, forward_list& __list) noexcept
01082       { splice_after(__pos, std::move(__list)); }
01083 
01084       /**
01085        *  @brief  Insert element from another %forward_list.
01086        *  @param  __pos  Iterator referencing the element to insert after.
01087        *  @param  __list  Source list.
01088        *  @param  __i   Iterator referencing the element before the element
01089        *                to move.
01090        *
01091        *  Removes the element in list @a list referenced by @a i and
01092        *  inserts it into the current list after @a pos.
01093        */
01094       void
01095       splice_after(const_iterator __pos, forward_list&& __list,
01096                    const_iterator __i) noexcept;
01097 
01098       void
01099       splice_after(const_iterator __pos, forward_list& __list,
01100                    const_iterator __i) noexcept
01101       { splice_after(__pos, std::move(__list), __i); }
01102 
01103       /**
01104        *  @brief  Insert range from another %forward_list.
01105        *  @param  __pos  Iterator referencing the element to insert after.
01106        *  @param  __list  Source list.
01107        *  @param  __before  Iterator referencing before the start of range
01108        *                    in list.
01109        *  @param  __last  Iterator referencing the end of range in list.
01110        *
01111        *  Removes elements in the range (__before,__last) and inserts them
01112        *  after @a __pos in constant time.
01113        *
01114        *  Undefined if @a __pos is in (__before,__last).
01115        *  @{
01116        */
01117       void
01118       splice_after(const_iterator __pos, forward_list&&,
01119                    const_iterator __before, const_iterator __last) noexcept
01120       { _M_splice_after(__pos, __before, __last); }
01121 
01122       void
01123       splice_after(const_iterator __pos, forward_list&,
01124                    const_iterator __before, const_iterator __last) noexcept
01125       { _M_splice_after(__pos, __before, __last); }
01126       // @}
01127 
01128       /**
01129        *  @brief  Remove all elements equal to value.
01130        *  @param  __val  The value to remove.
01131        *
01132        *  Removes every element in the list equal to @a __val.
01133        *  Remaining elements stay in list order.  Note that this
01134        *  function only erases the elements, and that if the elements
01135        *  themselves are pointers, the pointed-to memory is not
01136        *  touched in any way.  Managing the pointer is the user's
01137        *  responsibility.
01138        */
01139       void
01140       remove(const _Tp& __val);
01141 
01142       /**
01143        *  @brief  Remove all elements satisfying a predicate.
01144        *  @param  __pred  Unary predicate function or object.
01145        *
01146        *  Removes every element in the list for which the predicate
01147        *  returns true.  Remaining elements stay in list order.  Note
01148        *  that this function only erases the elements, and that if the
01149        *  elements themselves are pointers, the pointed-to memory is
01150        *  not touched in any way.  Managing the pointer is the user's
01151        *  responsibility.
01152        */
01153       template<typename _Pred>
01154         void
01155         remove_if(_Pred __pred);
01156 
01157       /**
01158        *  @brief  Remove consecutive duplicate elements.
01159        *
01160        *  For each consecutive set of elements with the same value,
01161        *  remove all but the first one.  Remaining elements stay in
01162        *  list order.  Note that this function only erases the
01163        *  elements, and that if the elements themselves are pointers,
01164        *  the pointed-to memory is not touched in any way.  Managing
01165        *  the pointer is the user's responsibility.
01166        */
01167       void
01168       unique()
01169       { unique(std::equal_to<_Tp>()); }
01170 
01171       /**
01172        *  @brief  Remove consecutive elements satisfying a predicate.
01173        *  @param  __binary_pred  Binary predicate function or object.
01174        *
01175        *  For each consecutive set of elements [first,last) that
01176        *  satisfy predicate(first,i) where i is an iterator in
01177        *  [first,last), remove all but the first one.  Remaining
01178        *  elements stay in list order.  Note that this function only
01179        *  erases the elements, and that if the elements themselves are
01180        *  pointers, the pointed-to memory is not touched in any way.
01181        *  Managing the pointer is the user's responsibility.
01182        */
01183       template<typename _BinPred>
01184         void
01185         unique(_BinPred __binary_pred);
01186 
01187       /**
01188        *  @brief  Merge sorted lists.
01189        *  @param  __list  Sorted list to merge.
01190        *
01191        *  Assumes that both @a list and this list are sorted according to
01192        *  operator<().  Merges elements of @a __list into this list in
01193        *  sorted order, leaving @a __list empty when complete.  Elements in
01194        *  this list precede elements in @a __list that are equal.
01195        */
01196       void
01197       merge(forward_list&& __list)
01198       { merge(std::move(__list), std::less<_Tp>()); }
01199 
01200       void
01201       merge(forward_list& __list)
01202       { merge(std::move(__list)); }
01203 
01204       /**
01205        *  @brief  Merge sorted lists according to comparison function.
01206        *  @param  __list  Sorted list to merge.
01207        *  @param  __comp Comparison function defining sort order.
01208        *
01209        *  Assumes that both @a __list and this list are sorted according to
01210        *  comp.  Merges elements of @a __list into this list
01211        *  in sorted order, leaving @a __list empty when complete.  Elements
01212        *  in this list precede elements in @a __list that are equivalent
01213        *  according to comp().
01214        */
01215       template<typename _Comp>
01216         void
01217         merge(forward_list&& __list, _Comp __comp);
01218 
01219       template<typename _Comp>
01220         void
01221         merge(forward_list& __list, _Comp __comp)
01222         { merge(std::move(__list), __comp); }
01223 
01224       /**
01225        *  @brief  Sort the elements of the list.
01226        *
01227        *  Sorts the elements of this list in NlogN time.  Equivalent
01228        *  elements remain in list order.
01229        */
01230       void
01231       sort()
01232       { sort(std::less<_Tp>()); }
01233 
01234       /**
01235        *  @brief  Sort the forward_list using a comparison function.
01236        *
01237        *  Sorts the elements of this list in NlogN time.  Equivalent
01238        *  elements remain in list order.
01239        */
01240       template<typename _Comp>
01241         void
01242         sort(_Comp __comp);
01243 
01244       /**
01245        *  @brief  Reverse the elements in list.
01246        *
01247        *  Reverse the order of elements in the list in linear time.
01248        */
01249       void
01250       reverse() noexcept
01251       { this->_M_impl._M_head._M_reverse_after(); }
01252 
01253     private:
01254       // Called by the range constructor to implement [23.3.4.2]/9
01255       template<typename _InputIterator>
01256         void
01257         _M_range_initialize(_InputIterator __first, _InputIterator __last);
01258 
01259       // Called by forward_list(n,v,a), and the range constructor when it
01260       // turns out to be the same thing.
01261       void
01262       _M_fill_initialize(size_type __n, const value_type& __value);
01263 
01264       // Called by splice_after and insert_after.
01265       iterator
01266       _M_splice_after(const_iterator __pos, const_iterator __before,
01267                       const_iterator __last);
01268 
01269       // Called by forward_list(n).
01270       void
01271       _M_default_initialize(size_type __n);
01272 
01273       // Called by resize(sz).
01274       void
01275       _M_default_insert_after(const_iterator __pos, size_type __n);
01276 
01277       // Called by operator=(forward_list&&)
01278       void
01279       _M_move_assign(forward_list&& __list, std::true_type) noexcept
01280       {
01281         clear();
01282         this->_M_impl._M_head._M_next = __list._M_impl._M_head._M_next;
01283         __list._M_impl._M_head._M_next = nullptr;
01284         std::__alloc_on_move(this->_M_get_Node_allocator(),
01285                              __list._M_get_Node_allocator());
01286       }
01287 
01288       // Called by operator=(forward_list&&)
01289       void
01290       _M_move_assign(forward_list&& __list, std::false_type)
01291       {
01292         if (__list._M_get_Node_allocator() == this->_M_get_Node_allocator())
01293           _M_move_assign(std::move(__list), std::true_type());
01294         else
01295           // The rvalue's allocator cannot be moved, or is not equal,
01296           // so we need to individually move each element.
01297           this->assign(std::__make_move_if_noexcept_iterator(__list.begin()),
01298                        std::__make_move_if_noexcept_iterator(__list.end()));
01299       }
01300 
01301       // Called by assign(_InputIterator, _InputIterator) if _Tp is
01302       // CopyAssignable.
01303       template<typename _InputIterator>
01304         void
01305         _M_assign(_InputIterator __first, _InputIterator __last, true_type)
01306         {
01307           auto __prev = before_begin();
01308           auto __curr = begin();
01309           auto __end = end();
01310           while (__curr != __end && __first != __last)
01311             {
01312               *__curr = *__first;
01313               ++__prev;
01314               ++__curr;
01315               ++__first;
01316             }
01317           if (__first != __last)
01318             insert_after(__prev, __first, __last);
01319           else if (__curr != __end)
01320             erase_after(__prev, __end);
01321         }
01322 
01323       // Called by assign(_InputIterator, _InputIterator) if _Tp is not
01324       // CopyAssignable.
01325       template<typename _InputIterator>
01326         void
01327         _M_assign(_InputIterator __first, _InputIterator __last, false_type)
01328         {
01329           clear();
01330           insert_after(cbefore_begin(), __first, __last);
01331         }
01332 
01333       // Called by assign(size_type, const _Tp&) if Tp is CopyAssignable
01334       void
01335       _M_assign_n(size_type __n, const _Tp& __val, true_type)
01336       {
01337         auto __prev = before_begin();
01338         auto __curr = begin();
01339         auto __end = end();
01340         while (__curr != __end && __n > 0)
01341           {
01342             *__curr = __val;
01343             ++__prev;
01344             ++__curr;
01345             --__n;
01346           }
01347         if (__n > 0)
01348           insert_after(__prev, __n, __val);
01349         else if (__curr != __end)
01350           erase_after(__prev, __end);
01351       }
01352 
01353       // Called by assign(size_type, const _Tp&) if Tp is non-CopyAssignable
01354       void
01355       _M_assign_n(size_type __n, const _Tp& __val, false_type)
01356       {
01357         clear();
01358         insert_after(cbefore_begin(), __n, __val);
01359       }
01360     };
01361 
01362   /**
01363    *  @brief  Forward list equality comparison.
01364    *  @param  __lx  A %forward_list
01365    *  @param  __ly  A %forward_list of the same type as @a __lx.
01366    *  @return  True iff the elements of the forward lists are equal.
01367    *
01368    *  This is an equivalence relation.  It is linear in the number of 
01369    *  elements of the forward lists.  Deques are considered equivalent
01370    *  if corresponding elements compare equal.
01371    */
01372   template<typename _Tp, typename _Alloc>
01373     bool
01374     operator==(const forward_list<_Tp, _Alloc>& __lx,
01375                const forward_list<_Tp, _Alloc>& __ly);
01376 
01377   /**
01378    *  @brief  Forward list ordering relation.
01379    *  @param  __lx  A %forward_list.
01380    *  @param  __ly  A %forward_list of the same type as @a __lx.
01381    *  @return  True iff @a __lx is lexicographically less than @a __ly.
01382    *
01383    *  This is a total ordering relation.  It is linear in the number of 
01384    *  elements of the forward lists.  The elements must be comparable
01385    *  with @c <.
01386    *
01387    *  See std::lexicographical_compare() for how the determination is made.
01388    */
01389   template<typename _Tp, typename _Alloc>
01390     inline bool
01391     operator<(const forward_list<_Tp, _Alloc>& __lx,
01392               const forward_list<_Tp, _Alloc>& __ly)
01393     { return std::lexicographical_compare(__lx.cbegin(), __lx.cend(),
01394                                           __ly.cbegin(), __ly.cend()); }
01395 
01396   /// Based on operator==
01397   template<typename _Tp, typename _Alloc>
01398     inline bool
01399     operator!=(const forward_list<_Tp, _Alloc>& __lx,
01400                const forward_list<_Tp, _Alloc>& __ly)
01401     { return !(__lx == __ly); }
01402 
01403   /// Based on operator<
01404   template<typename _Tp, typename _Alloc>
01405     inline bool
01406     operator>(const forward_list<_Tp, _Alloc>& __lx,
01407               const forward_list<_Tp, _Alloc>& __ly)
01408     { return (__ly < __lx); }
01409 
01410   /// Based on operator<
01411   template<typename _Tp, typename _Alloc>
01412     inline bool
01413     operator>=(const forward_list<_Tp, _Alloc>& __lx,
01414                const forward_list<_Tp, _Alloc>& __ly)
01415     { return !(__lx < __ly); }
01416 
01417   /// Based on operator<
01418   template<typename _Tp, typename _Alloc>
01419     inline bool
01420     operator<=(const forward_list<_Tp, _Alloc>& __lx,
01421                const forward_list<_Tp, _Alloc>& __ly)
01422     { return !(__ly < __lx); }
01423 
01424   /// See std::forward_list::swap().
01425   template<typename _Tp, typename _Alloc>
01426     inline void
01427     swap(forward_list<_Tp, _Alloc>& __lx,
01428          forward_list<_Tp, _Alloc>& __ly)
01429     noexcept(noexcept(__lx.swap(__ly)))
01430     { __lx.swap(__ly); }
01431 
01432 _GLIBCXX_END_NAMESPACE_CONTAINER
01433 } // namespace std
01434 
01435 #endif // _FORWARD_LIST_H