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