xref: /dflybsd-src/contrib/gcc-4.7/libstdc++-v3/include/bits/forward_list.h (revision 04febcfb30580676d3e95f58a16c5137ee478b32)
1*e4b17023SJohn Marino // <forward_list.h> -*- C++ -*-
2*e4b17023SJohn Marino 
3*e4b17023SJohn Marino // Copyright (C) 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
4*e4b17023SJohn Marino //
5*e4b17023SJohn Marino // This file is part of the GNU ISO C++ Library.  This library is free
6*e4b17023SJohn Marino // software; you can redistribute it and/or modify it under the
7*e4b17023SJohn Marino // terms of the GNU General Public License as published by the
8*e4b17023SJohn Marino // Free Software Foundation; either version 3, or (at your option)
9*e4b17023SJohn Marino // any later version.
10*e4b17023SJohn Marino 
11*e4b17023SJohn Marino // This library is distributed in the hope that it will be useful,
12*e4b17023SJohn Marino // but WITHOUT ANY WARRANTY; without even the implied warranty of
13*e4b17023SJohn Marino // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*e4b17023SJohn Marino // GNU General Public License for more details.
15*e4b17023SJohn Marino 
16*e4b17023SJohn Marino // Under Section 7 of GPL version 3, you are granted additional
17*e4b17023SJohn Marino // permissions described in the GCC Runtime Library Exception, version
18*e4b17023SJohn Marino // 3.1, as published by the Free Software Foundation.
19*e4b17023SJohn Marino 
20*e4b17023SJohn Marino // You should have received a copy of the GNU General Public License and
21*e4b17023SJohn Marino // a copy of the GCC Runtime Library Exception along with this program;
22*e4b17023SJohn Marino // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
23*e4b17023SJohn Marino // <http://www.gnu.org/licenses/>.
24*e4b17023SJohn Marino 
25*e4b17023SJohn Marino /** @file bits/forward_list.h
26*e4b17023SJohn Marino  *  This is an internal header file, included by other library headers.
27*e4b17023SJohn Marino  *  Do not attempt to use it directly. @headername{forward_list}
28*e4b17023SJohn Marino  */
29*e4b17023SJohn Marino 
30*e4b17023SJohn Marino #ifndef _FORWARD_LIST_H
31*e4b17023SJohn Marino #define _FORWARD_LIST_H 1
32*e4b17023SJohn Marino 
33*e4b17023SJohn Marino #pragma GCC system_header
34*e4b17023SJohn Marino 
35*e4b17023SJohn Marino #include <memory>
36*e4b17023SJohn Marino #ifdef __GXX_EXPERIMENTAL_CXX0X__
37*e4b17023SJohn Marino #include <initializer_list>
38*e4b17023SJohn Marino #endif
39*e4b17023SJohn Marino 
_GLIBCXX_VISIBILITY(default)40*e4b17023SJohn Marino namespace std _GLIBCXX_VISIBILITY(default)
41*e4b17023SJohn Marino {
42*e4b17023SJohn Marino _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
43*e4b17023SJohn Marino 
44*e4b17023SJohn Marino   /**
45*e4b17023SJohn Marino    *  @brief  A helper basic node class for %forward_list.
46*e4b17023SJohn Marino    *          This is just a linked list with nothing inside it.
47*e4b17023SJohn Marino    *          There are purely list shuffling utility methods here.
48*e4b17023SJohn Marino    */
49*e4b17023SJohn Marino   struct _Fwd_list_node_base
50*e4b17023SJohn Marino   {
51*e4b17023SJohn Marino     _Fwd_list_node_base() : _M_next(0) { }
52*e4b17023SJohn Marino 
53*e4b17023SJohn Marino     _Fwd_list_node_base* _M_next;
54*e4b17023SJohn Marino 
55*e4b17023SJohn Marino     _Fwd_list_node_base*
56*e4b17023SJohn Marino     _M_transfer_after(_Fwd_list_node_base* __begin,
57*e4b17023SJohn Marino 		      _Fwd_list_node_base* __end)
58*e4b17023SJohn Marino     {
59*e4b17023SJohn Marino       _Fwd_list_node_base* __keep = __begin->_M_next;
60*e4b17023SJohn Marino       if (__end)
61*e4b17023SJohn Marino 	{
62*e4b17023SJohn Marino 	  __begin->_M_next = __end->_M_next;
63*e4b17023SJohn Marino 	  __end->_M_next = _M_next;
64*e4b17023SJohn Marino 	}
65*e4b17023SJohn Marino       else
66*e4b17023SJohn Marino 	__begin->_M_next = 0;
67*e4b17023SJohn Marino       _M_next = __keep;
68*e4b17023SJohn Marino       return __end;
69*e4b17023SJohn Marino     }
70*e4b17023SJohn Marino 
71*e4b17023SJohn Marino     void
72*e4b17023SJohn Marino     _M_reverse_after() noexcept
73*e4b17023SJohn Marino     {
74*e4b17023SJohn Marino       _Fwd_list_node_base* __tail = _M_next;
75*e4b17023SJohn Marino       if (!__tail)
76*e4b17023SJohn Marino 	return;
77*e4b17023SJohn Marino       while (_Fwd_list_node_base* __temp = __tail->_M_next)
78*e4b17023SJohn Marino 	{
79*e4b17023SJohn Marino 	  _Fwd_list_node_base* __keep = _M_next;
80*e4b17023SJohn Marino 	  _M_next = __temp;
81*e4b17023SJohn Marino 	  __tail->_M_next = __temp->_M_next;
82*e4b17023SJohn Marino 	  _M_next->_M_next = __keep;
83*e4b17023SJohn Marino 	}
84*e4b17023SJohn Marino     }
85*e4b17023SJohn Marino   };
86*e4b17023SJohn Marino 
87*e4b17023SJohn Marino   /**
88*e4b17023SJohn Marino    *  @brief  A helper node class for %forward_list.
89*e4b17023SJohn Marino    *          This is just a linked list with a data value in each node.
90*e4b17023SJohn Marino    *          There is a sorting utility method.
91*e4b17023SJohn Marino    */
92*e4b17023SJohn Marino   template<typename _Tp>
93*e4b17023SJohn Marino     struct _Fwd_list_node
94*e4b17023SJohn Marino     : public _Fwd_list_node_base
95*e4b17023SJohn Marino     {
96*e4b17023SJohn Marino       template<typename... _Args>
97*e4b17023SJohn Marino         _Fwd_list_node(_Args&&... __args)
98*e4b17023SJohn Marino         : _Fwd_list_node_base(),
99*e4b17023SJohn Marino           _M_value(std::forward<_Args>(__args)...) { }
100*e4b17023SJohn Marino 
101*e4b17023SJohn Marino       _Tp _M_value;
102*e4b17023SJohn Marino     };
103*e4b17023SJohn Marino 
104*e4b17023SJohn Marino   /**
105*e4b17023SJohn Marino    *   @brief A forward_list::iterator.
106*e4b17023SJohn Marino    *
107*e4b17023SJohn Marino    *   All the functions are op overloads.
108*e4b17023SJohn Marino    */
109*e4b17023SJohn Marino   template<typename _Tp>
110*e4b17023SJohn Marino     struct _Fwd_list_iterator
111*e4b17023SJohn Marino     {
112*e4b17023SJohn Marino       typedef _Fwd_list_iterator<_Tp>            _Self;
113*e4b17023SJohn Marino       typedef _Fwd_list_node<_Tp>                _Node;
114*e4b17023SJohn Marino 
115*e4b17023SJohn Marino       typedef _Tp                                value_type;
116*e4b17023SJohn Marino       typedef _Tp*                               pointer;
117*e4b17023SJohn Marino       typedef _Tp&                               reference;
118*e4b17023SJohn Marino       typedef ptrdiff_t                          difference_type;
119*e4b17023SJohn Marino       typedef std::forward_iterator_tag          iterator_category;
120*e4b17023SJohn Marino 
121*e4b17023SJohn Marino       _Fwd_list_iterator()
122*e4b17023SJohn Marino       : _M_node() { }
123*e4b17023SJohn Marino 
124*e4b17023SJohn Marino       explicit
125*e4b17023SJohn Marino       _Fwd_list_iterator(_Fwd_list_node_base* __n)
126*e4b17023SJohn Marino       : _M_node(__n) { }
127*e4b17023SJohn Marino 
128*e4b17023SJohn Marino       reference
129*e4b17023SJohn Marino       operator*() const
130*e4b17023SJohn Marino       { return static_cast<_Node*>(this->_M_node)->_M_value; }
131*e4b17023SJohn Marino 
132*e4b17023SJohn Marino       pointer
133*e4b17023SJohn Marino       operator->() const
134*e4b17023SJohn Marino       { return std::__addressof(static_cast<_Node*>
135*e4b17023SJohn Marino 				(this->_M_node)->_M_value); }
136*e4b17023SJohn Marino 
137*e4b17023SJohn Marino       _Self&
138*e4b17023SJohn Marino       operator++()
139*e4b17023SJohn Marino       {
140*e4b17023SJohn Marino         _M_node = _M_node->_M_next;
141*e4b17023SJohn Marino         return *this;
142*e4b17023SJohn Marino       }
143*e4b17023SJohn Marino 
144*e4b17023SJohn Marino       _Self
145*e4b17023SJohn Marino       operator++(int)
146*e4b17023SJohn Marino       {
147*e4b17023SJohn Marino         _Self __tmp(*this);
148*e4b17023SJohn Marino         _M_node = _M_node->_M_next;
149*e4b17023SJohn Marino         return __tmp;
150*e4b17023SJohn Marino       }
151*e4b17023SJohn Marino 
152*e4b17023SJohn Marino       bool
153*e4b17023SJohn Marino       operator==(const _Self& __x) const
154*e4b17023SJohn Marino       { return _M_node == __x._M_node; }
155*e4b17023SJohn Marino 
156*e4b17023SJohn Marino       bool
157*e4b17023SJohn Marino       operator!=(const _Self& __x) const
158*e4b17023SJohn Marino       { return _M_node != __x._M_node; }
159*e4b17023SJohn Marino 
160*e4b17023SJohn Marino       _Self
161*e4b17023SJohn Marino       _M_next() const
162*e4b17023SJohn Marino       {
163*e4b17023SJohn Marino         if (_M_node)
164*e4b17023SJohn Marino           return _Fwd_list_iterator(_M_node->_M_next);
165*e4b17023SJohn Marino         else
166*e4b17023SJohn Marino           return _Fwd_list_iterator(0);
167*e4b17023SJohn Marino       }
168*e4b17023SJohn Marino 
169*e4b17023SJohn Marino       _Fwd_list_node_base* _M_node;
170*e4b17023SJohn Marino     };
171*e4b17023SJohn Marino 
172*e4b17023SJohn Marino   /**
173*e4b17023SJohn Marino    *   @brief A forward_list::const_iterator.
174*e4b17023SJohn Marino    *
175*e4b17023SJohn Marino    *   All the functions are op overloads.
176*e4b17023SJohn Marino    */
177*e4b17023SJohn Marino   template<typename _Tp>
178*e4b17023SJohn Marino     struct _Fwd_list_const_iterator
179*e4b17023SJohn Marino     {
180*e4b17023SJohn Marino       typedef _Fwd_list_const_iterator<_Tp>      _Self;
181*e4b17023SJohn Marino       typedef const _Fwd_list_node<_Tp>          _Node;
182*e4b17023SJohn Marino       typedef _Fwd_list_iterator<_Tp>            iterator;
183*e4b17023SJohn Marino 
184*e4b17023SJohn Marino       typedef _Tp                                value_type;
185*e4b17023SJohn Marino       typedef const _Tp*                         pointer;
186*e4b17023SJohn Marino       typedef const _Tp&                         reference;
187*e4b17023SJohn Marino       typedef ptrdiff_t                          difference_type;
188*e4b17023SJohn Marino       typedef std::forward_iterator_tag          iterator_category;
189*e4b17023SJohn Marino 
190*e4b17023SJohn Marino       _Fwd_list_const_iterator()
191*e4b17023SJohn Marino       : _M_node() { }
192*e4b17023SJohn Marino 
193*e4b17023SJohn Marino       explicit
194*e4b17023SJohn Marino       _Fwd_list_const_iterator(const _Fwd_list_node_base* __n)
195*e4b17023SJohn Marino       : _M_node(__n) { }
196*e4b17023SJohn Marino 
197*e4b17023SJohn Marino       _Fwd_list_const_iterator(const iterator& __iter)
198*e4b17023SJohn Marino       : _M_node(__iter._M_node) { }
199*e4b17023SJohn Marino 
200*e4b17023SJohn Marino       reference
201*e4b17023SJohn Marino       operator*() const
202*e4b17023SJohn Marino       { return static_cast<_Node*>(this->_M_node)->_M_value; }
203*e4b17023SJohn Marino 
204*e4b17023SJohn Marino       pointer
205*e4b17023SJohn Marino       operator->() const
206*e4b17023SJohn Marino       { return std::__addressof(static_cast<_Node*>
207*e4b17023SJohn Marino 				(this->_M_node)->_M_value); }
208*e4b17023SJohn Marino 
209*e4b17023SJohn Marino       _Self&
210*e4b17023SJohn Marino       operator++()
211*e4b17023SJohn Marino       {
212*e4b17023SJohn Marino         _M_node = _M_node->_M_next;
213*e4b17023SJohn Marino         return *this;
214*e4b17023SJohn Marino       }
215*e4b17023SJohn Marino 
216*e4b17023SJohn Marino       _Self
217*e4b17023SJohn Marino       operator++(int)
218*e4b17023SJohn Marino       {
219*e4b17023SJohn Marino         _Self __tmp(*this);
220*e4b17023SJohn Marino         _M_node = _M_node->_M_next;
221*e4b17023SJohn Marino         return __tmp;
222*e4b17023SJohn Marino       }
223*e4b17023SJohn Marino 
224*e4b17023SJohn Marino       bool
225*e4b17023SJohn Marino       operator==(const _Self& __x) const
226*e4b17023SJohn Marino       { return _M_node == __x._M_node; }
227*e4b17023SJohn Marino 
228*e4b17023SJohn Marino       bool
229*e4b17023SJohn Marino       operator!=(const _Self& __x) const
230*e4b17023SJohn Marino       { return _M_node != __x._M_node; }
231*e4b17023SJohn Marino 
232*e4b17023SJohn Marino       _Self
233*e4b17023SJohn Marino       _M_next() const
234*e4b17023SJohn Marino       {
235*e4b17023SJohn Marino         if (this->_M_node)
236*e4b17023SJohn Marino           return _Fwd_list_const_iterator(_M_node->_M_next);
237*e4b17023SJohn Marino         else
238*e4b17023SJohn Marino           return _Fwd_list_const_iterator(0);
239*e4b17023SJohn Marino       }
240*e4b17023SJohn Marino 
241*e4b17023SJohn Marino       const _Fwd_list_node_base* _M_node;
242*e4b17023SJohn Marino     };
243*e4b17023SJohn Marino 
244*e4b17023SJohn Marino   /**
245*e4b17023SJohn Marino    *  @brief  Forward list iterator equality comparison.
246*e4b17023SJohn Marino    */
247*e4b17023SJohn Marino   template<typename _Tp>
248*e4b17023SJohn Marino     inline bool
249*e4b17023SJohn Marino     operator==(const _Fwd_list_iterator<_Tp>& __x,
250*e4b17023SJohn Marino                const _Fwd_list_const_iterator<_Tp>& __y)
251*e4b17023SJohn Marino     { return __x._M_node == __y._M_node; }
252*e4b17023SJohn Marino 
253*e4b17023SJohn Marino   /**
254*e4b17023SJohn Marino    *  @brief  Forward list iterator inequality comparison.
255*e4b17023SJohn Marino    */
256*e4b17023SJohn Marino   template<typename _Tp>
257*e4b17023SJohn Marino     inline bool
258*e4b17023SJohn Marino     operator!=(const _Fwd_list_iterator<_Tp>& __x,
259*e4b17023SJohn Marino                const _Fwd_list_const_iterator<_Tp>& __y)
260*e4b17023SJohn Marino     { return __x._M_node != __y._M_node; }
261*e4b17023SJohn Marino 
262*e4b17023SJohn Marino   /**
263*e4b17023SJohn Marino    *  @brief  Base class for %forward_list.
264*e4b17023SJohn Marino    */
265*e4b17023SJohn Marino   template<typename _Tp, typename _Alloc>
266*e4b17023SJohn Marino     struct _Fwd_list_base
267*e4b17023SJohn Marino     {
268*e4b17023SJohn Marino     protected:
269*e4b17023SJohn Marino       typedef typename _Alloc::template rebind<_Tp>::other _Tp_alloc_type;
270*e4b17023SJohn Marino 
271*e4b17023SJohn Marino       typedef typename _Alloc::template
272*e4b17023SJohn Marino         rebind<_Fwd_list_node<_Tp>>::other _Node_alloc_type;
273*e4b17023SJohn Marino 
274*e4b17023SJohn Marino       struct _Fwd_list_impl
275*e4b17023SJohn Marino       : public _Node_alloc_type
276*e4b17023SJohn Marino       {
277*e4b17023SJohn Marino         _Fwd_list_node_base _M_head;
278*e4b17023SJohn Marino 
279*e4b17023SJohn Marino         _Fwd_list_impl()
280*e4b17023SJohn Marino         : _Node_alloc_type(), _M_head()
281*e4b17023SJohn Marino         { }
282*e4b17023SJohn Marino 
283*e4b17023SJohn Marino         _Fwd_list_impl(const _Node_alloc_type& __a)
284*e4b17023SJohn Marino         : _Node_alloc_type(__a), _M_head()
285*e4b17023SJohn Marino         { }
286*e4b17023SJohn Marino 
287*e4b17023SJohn Marino         _Fwd_list_impl(_Node_alloc_type&& __a)
288*e4b17023SJohn Marino 	: _Node_alloc_type(std::move(__a)), _M_head()
289*e4b17023SJohn Marino         { }
290*e4b17023SJohn Marino       };
291*e4b17023SJohn Marino 
292*e4b17023SJohn Marino       _Fwd_list_impl _M_impl;
293*e4b17023SJohn Marino 
294*e4b17023SJohn Marino     public:
295*e4b17023SJohn Marino       typedef _Fwd_list_iterator<_Tp>                 iterator;
296*e4b17023SJohn Marino       typedef _Fwd_list_const_iterator<_Tp>           const_iterator;
297*e4b17023SJohn Marino       typedef _Fwd_list_node<_Tp>                     _Node;
298*e4b17023SJohn Marino 
299*e4b17023SJohn Marino       _Node_alloc_type&
300*e4b17023SJohn Marino       _M_get_Node_allocator() noexcept
301*e4b17023SJohn Marino       { return *static_cast<_Node_alloc_type*>(&this->_M_impl); }
302*e4b17023SJohn Marino 
303*e4b17023SJohn Marino       const _Node_alloc_type&
304*e4b17023SJohn Marino       _M_get_Node_allocator() const noexcept
305*e4b17023SJohn Marino       { return *static_cast<const _Node_alloc_type*>(&this->_M_impl); }
306*e4b17023SJohn Marino 
307*e4b17023SJohn Marino       _Fwd_list_base()
308*e4b17023SJohn Marino       : _M_impl() { }
309*e4b17023SJohn Marino 
310*e4b17023SJohn Marino       _Fwd_list_base(const _Node_alloc_type& __a)
311*e4b17023SJohn Marino       : _M_impl(__a) { }
312*e4b17023SJohn Marino 
313*e4b17023SJohn Marino       _Fwd_list_base(const _Fwd_list_base& __lst, const _Node_alloc_type& __a);
314*e4b17023SJohn Marino 
315*e4b17023SJohn Marino       _Fwd_list_base(_Fwd_list_base&& __lst, const _Node_alloc_type& __a)
316*e4b17023SJohn Marino       : _M_impl(__a)
317*e4b17023SJohn Marino       {
318*e4b17023SJohn Marino 	this->_M_impl._M_head._M_next = __lst._M_impl._M_head._M_next;
319*e4b17023SJohn Marino 	__lst._M_impl._M_head._M_next = 0;
320*e4b17023SJohn Marino       }
321*e4b17023SJohn Marino 
322*e4b17023SJohn Marino       _Fwd_list_base(_Fwd_list_base&& __lst)
323*e4b17023SJohn Marino       : _M_impl(std::move(__lst._M_get_Node_allocator()))
324*e4b17023SJohn Marino       {
325*e4b17023SJohn Marino 	this->_M_impl._M_head._M_next = __lst._M_impl._M_head._M_next;
326*e4b17023SJohn Marino 	__lst._M_impl._M_head._M_next = 0;
327*e4b17023SJohn Marino       }
328*e4b17023SJohn Marino 
329*e4b17023SJohn Marino       ~_Fwd_list_base()
330*e4b17023SJohn Marino       { _M_erase_after(&_M_impl._M_head, 0); }
331*e4b17023SJohn Marino 
332*e4b17023SJohn Marino     protected:
333*e4b17023SJohn Marino 
334*e4b17023SJohn Marino       _Node*
335*e4b17023SJohn Marino       _M_get_node()
336*e4b17023SJohn Marino       { return _M_get_Node_allocator().allocate(1); }
337*e4b17023SJohn Marino 
338*e4b17023SJohn Marino       template<typename... _Args>
339*e4b17023SJohn Marino         _Node*
340*e4b17023SJohn Marino         _M_create_node(_Args&&... __args)
341*e4b17023SJohn Marino         {
342*e4b17023SJohn Marino           _Node* __node = this->_M_get_node();
343*e4b17023SJohn Marino           __try
344*e4b17023SJohn Marino             {
345*e4b17023SJohn Marino               _M_get_Node_allocator().construct(__node,
346*e4b17023SJohn Marino                                               std::forward<_Args>(__args)...);
347*e4b17023SJohn Marino               __node->_M_next = 0;
348*e4b17023SJohn Marino             }
349*e4b17023SJohn Marino           __catch(...)
350*e4b17023SJohn Marino             {
351*e4b17023SJohn Marino               this->_M_put_node(__node);
352*e4b17023SJohn Marino               __throw_exception_again;
353*e4b17023SJohn Marino             }
354*e4b17023SJohn Marino           return __node;
355*e4b17023SJohn Marino         }
356*e4b17023SJohn Marino 
357*e4b17023SJohn Marino       template<typename... _Args>
358*e4b17023SJohn Marino         _Fwd_list_node_base*
359*e4b17023SJohn Marino         _M_insert_after(const_iterator __pos, _Args&&... __args);
360*e4b17023SJohn Marino 
361*e4b17023SJohn Marino       void
362*e4b17023SJohn Marino       _M_put_node(_Node* __p)
363*e4b17023SJohn Marino       { _M_get_Node_allocator().deallocate(__p, 1); }
364*e4b17023SJohn Marino 
365*e4b17023SJohn Marino       _Fwd_list_node_base*
366*e4b17023SJohn Marino       _M_erase_after(_Fwd_list_node_base* __pos);
367*e4b17023SJohn Marino 
368*e4b17023SJohn Marino       _Fwd_list_node_base*
369*e4b17023SJohn Marino       _M_erase_after(_Fwd_list_node_base* __pos,
370*e4b17023SJohn Marino                      _Fwd_list_node_base* __last);
371*e4b17023SJohn Marino     };
372*e4b17023SJohn Marino 
373*e4b17023SJohn Marino   /**
374*e4b17023SJohn Marino    *  @brief A standard container with linear time access to elements,
375*e4b17023SJohn Marino    *  and fixed time insertion/deletion at any point in the sequence.
376*e4b17023SJohn Marino    *
377*e4b17023SJohn Marino    *  @ingroup sequences
378*e4b17023SJohn Marino    *
379*e4b17023SJohn Marino    *  Meets the requirements of a <a href="tables.html#65">container</a>, a
380*e4b17023SJohn Marino    *  <a href="tables.html#67">sequence</a>, including the
381*e4b17023SJohn Marino    *  <a href="tables.html#68">optional sequence requirements</a> with the
382*e4b17023SJohn Marino    *  %exception of @c at and @c operator[].
383*e4b17023SJohn Marino    *
384*e4b17023SJohn Marino    *  This is a @e singly @e linked %list.  Traversal up the
385*e4b17023SJohn Marino    *  %list requires linear time, but adding and removing elements (or
386*e4b17023SJohn Marino    *  @e nodes) is done in constant time, regardless of where the
387*e4b17023SJohn Marino    *  change takes place.  Unlike std::vector and std::deque,
388*e4b17023SJohn Marino    *  random-access iterators are not provided, so subscripting ( @c
389*e4b17023SJohn Marino    *  [] ) access is not allowed.  For algorithms which only need
390*e4b17023SJohn Marino    *  sequential access, this lack makes no difference.
391*e4b17023SJohn Marino    *
392*e4b17023SJohn Marino    *  Also unlike the other standard containers, std::forward_list provides
393*e4b17023SJohn Marino    *  specialized algorithms %unique to linked lists, such as
394*e4b17023SJohn Marino    *  splicing, sorting, and in-place reversal.
395*e4b17023SJohn Marino    *
396*e4b17023SJohn Marino    *  A couple points on memory allocation for forward_list<Tp>:
397*e4b17023SJohn Marino    *
398*e4b17023SJohn Marino    *  First, we never actually allocate a Tp, we allocate
399*e4b17023SJohn Marino    *  Fwd_list_node<Tp>'s and trust [20.1.5]/4 to DTRT.  This is to ensure
400*e4b17023SJohn Marino    *  that after elements from %forward_list<X,Alloc1> are spliced into
401*e4b17023SJohn Marino    *  %forward_list<X,Alloc2>, destroying the memory of the second %list is a
402*e4b17023SJohn Marino    *  valid operation, i.e., Alloc1 giveth and Alloc2 taketh away.
403*e4b17023SJohn Marino    */
404*e4b17023SJohn Marino   template<typename _Tp, typename _Alloc = allocator<_Tp> >
405*e4b17023SJohn Marino     class forward_list : private _Fwd_list_base<_Tp, _Alloc>
406*e4b17023SJohn Marino     {
407*e4b17023SJohn Marino     private:
408*e4b17023SJohn Marino       typedef _Fwd_list_base<_Tp, _Alloc>                  _Base;
409*e4b17023SJohn Marino       typedef _Fwd_list_node<_Tp>                          _Node;
410*e4b17023SJohn Marino       typedef _Fwd_list_node_base                          _Node_base;
411*e4b17023SJohn Marino       typedef typename _Base::_Tp_alloc_type               _Tp_alloc_type;
412*e4b17023SJohn Marino       typedef typename _Base::_Node_alloc_type             _Node_alloc_type;
413*e4b17023SJohn Marino 
414*e4b17023SJohn Marino     public:
415*e4b17023SJohn Marino       // types:
416*e4b17023SJohn Marino       typedef _Tp                                          value_type;
417*e4b17023SJohn Marino       typedef typename _Tp_alloc_type::pointer             pointer;
418*e4b17023SJohn Marino       typedef typename _Tp_alloc_type::const_pointer       const_pointer;
419*e4b17023SJohn Marino       typedef typename _Tp_alloc_type::reference           reference;
420*e4b17023SJohn Marino       typedef typename _Tp_alloc_type::const_reference     const_reference;
421*e4b17023SJohn Marino 
422*e4b17023SJohn Marino       typedef _Fwd_list_iterator<_Tp>                      iterator;
423*e4b17023SJohn Marino       typedef _Fwd_list_const_iterator<_Tp>                const_iterator;
424*e4b17023SJohn Marino       typedef std::size_t                                  size_type;
425*e4b17023SJohn Marino       typedef std::ptrdiff_t                               difference_type;
426*e4b17023SJohn Marino       typedef _Alloc                                       allocator_type;
427*e4b17023SJohn Marino 
428*e4b17023SJohn Marino       // 23.2.3.1 construct/copy/destroy:
429*e4b17023SJohn Marino 
430*e4b17023SJohn Marino       /**
431*e4b17023SJohn Marino        *  @brief  Creates a %forward_list with no elements.
432*e4b17023SJohn Marino        *  @param  __al  An allocator object.
433*e4b17023SJohn Marino        */
434*e4b17023SJohn Marino       explicit
435*e4b17023SJohn Marino       forward_list(const _Alloc& __al = _Alloc())
436*e4b17023SJohn Marino       : _Base(_Node_alloc_type(__al))
437*e4b17023SJohn Marino       { }
438*e4b17023SJohn Marino 
439*e4b17023SJohn Marino       /**
440*e4b17023SJohn Marino        *  @brief  Copy constructor with allocator argument.
441*e4b17023SJohn Marino        *  @param  __list  Input list to copy.
442*e4b17023SJohn Marino        *  @param  __al    An allocator object.
443*e4b17023SJohn Marino        */
444*e4b17023SJohn Marino       forward_list(const forward_list& __list, const _Alloc& __al)
445*e4b17023SJohn Marino       : _Base(__list, _Node_alloc_type(__al))
446*e4b17023SJohn Marino       { }
447*e4b17023SJohn Marino 
448*e4b17023SJohn Marino       /**
449*e4b17023SJohn Marino        *  @brief  Move constructor with allocator argument.
450*e4b17023SJohn Marino        *  @param  __list  Input list to move.
451*e4b17023SJohn Marino        *  @param  __al    An allocator object.
452*e4b17023SJohn Marino        */
453*e4b17023SJohn Marino       forward_list(forward_list&& __list, const _Alloc& __al)
454*e4b17023SJohn Marino       : _Base(std::move(__list), _Node_alloc_type(__al))
455*e4b17023SJohn Marino       { }
456*e4b17023SJohn Marino 
457*e4b17023SJohn Marino       /**
458*e4b17023SJohn Marino        *  @brief  Creates a %forward_list with default constructed elements.
459*e4b17023SJohn Marino        *  @param  __n  The number of elements to initially create.
460*e4b17023SJohn Marino        *
461*e4b17023SJohn Marino        *  This constructor creates the %forward_list with @a __n default
462*e4b17023SJohn Marino        *  constructed elements.
463*e4b17023SJohn Marino        */
464*e4b17023SJohn Marino       explicit
465*e4b17023SJohn Marino       forward_list(size_type __n)
466*e4b17023SJohn Marino       : _Base()
467*e4b17023SJohn Marino       { _M_default_initialize(__n); }
468*e4b17023SJohn Marino 
469*e4b17023SJohn Marino       /**
470*e4b17023SJohn Marino        *  @brief  Creates a %forward_list with copies of an exemplar element.
471*e4b17023SJohn Marino        *  @param  __n      The number of elements to initially create.
472*e4b17023SJohn Marino        *  @param  __value  An element to copy.
473*e4b17023SJohn Marino        *  @param  __al     An allocator object.
474*e4b17023SJohn Marino        *
475*e4b17023SJohn Marino        *  This constructor fills the %forward_list with @a __n copies of
476*e4b17023SJohn Marino        *  @a __value.
477*e4b17023SJohn Marino        */
478*e4b17023SJohn Marino       forward_list(size_type __n, const _Tp& __value,
479*e4b17023SJohn Marino                    const _Alloc& __al = _Alloc())
480*e4b17023SJohn Marino       : _Base(_Node_alloc_type(__al))
481*e4b17023SJohn Marino       { _M_fill_initialize(__n, __value); }
482*e4b17023SJohn Marino 
483*e4b17023SJohn Marino       /**
484*e4b17023SJohn Marino        *  @brief  Builds a %forward_list from a range.
485*e4b17023SJohn Marino        *  @param  __first  An input iterator.
486*e4b17023SJohn Marino        *  @param  __last   An input iterator.
487*e4b17023SJohn Marino        *  @param  __al     An allocator object.
488*e4b17023SJohn Marino        *
489*e4b17023SJohn Marino        *  Create a %forward_list consisting of copies of the elements from
490*e4b17023SJohn Marino        *  [@a __first,@a __last).  This is linear in N (where N is
491*e4b17023SJohn Marino        *  distance(@a __first,@a __last)).
492*e4b17023SJohn Marino        */
493*e4b17023SJohn Marino       template<typename _InputIterator>
494*e4b17023SJohn Marino         forward_list(_InputIterator __first, _InputIterator __last,
495*e4b17023SJohn Marino                      const _Alloc& __al = _Alloc())
496*e4b17023SJohn Marino 	: _Base(_Node_alloc_type(__al))
497*e4b17023SJohn Marino         {
498*e4b17023SJohn Marino           // Check whether it's an integral type.  If so, it's not an iterator.
499*e4b17023SJohn Marino           typedef typename std::__is_integer<_InputIterator>::__type _Integral;
500*e4b17023SJohn Marino           _M_initialize_dispatch(__first, __last, _Integral());
501*e4b17023SJohn Marino         }
502*e4b17023SJohn Marino 
503*e4b17023SJohn Marino       /**
504*e4b17023SJohn Marino        *  @brief  The %forward_list copy constructor.
505*e4b17023SJohn Marino        *  @param  __list  A %forward_list of identical element and allocator
506*e4b17023SJohn Marino        *                types.
507*e4b17023SJohn Marino        *
508*e4b17023SJohn Marino        *  The newly-created %forward_list uses a copy of the allocation
509*e4b17023SJohn Marino        *  object used by @a __list.
510*e4b17023SJohn Marino        */
511*e4b17023SJohn Marino       forward_list(const forward_list& __list)
512*e4b17023SJohn Marino       : _Base(__list._M_get_Node_allocator())
513*e4b17023SJohn Marino       { _M_initialize_dispatch(__list.begin(), __list.end(), __false_type()); }
514*e4b17023SJohn Marino 
515*e4b17023SJohn Marino       /**
516*e4b17023SJohn Marino        *  @brief  The %forward_list move constructor.
517*e4b17023SJohn Marino        *  @param  __list  A %forward_list of identical element and allocator
518*e4b17023SJohn Marino        *                types.
519*e4b17023SJohn Marino        *
520*e4b17023SJohn Marino        *  The newly-created %forward_list contains the exact contents of @a
521*e4b17023SJohn Marino        *  forward_list. The contents of @a __list are a valid, but unspecified
522*e4b17023SJohn Marino        *  %forward_list.
523*e4b17023SJohn Marino        */
524*e4b17023SJohn Marino       forward_list(forward_list&& __list) noexcept
525*e4b17023SJohn Marino       : _Base(std::move(__list)) { }
526*e4b17023SJohn Marino 
527*e4b17023SJohn Marino       /**
528*e4b17023SJohn Marino        *  @brief  Builds a %forward_list from an initializer_list
529*e4b17023SJohn Marino        *  @param  __il  An initializer_list of value_type.
530*e4b17023SJohn Marino        *  @param  __al  An allocator object.
531*e4b17023SJohn Marino        *
532*e4b17023SJohn Marino        *  Create a %forward_list consisting of copies of the elements
533*e4b17023SJohn Marino        *  in the initializer_list @a __il.  This is linear in __il.size().
534*e4b17023SJohn Marino        */
535*e4b17023SJohn Marino       forward_list(std::initializer_list<_Tp> __il,
536*e4b17023SJohn Marino                    const _Alloc& __al = _Alloc())
537*e4b17023SJohn Marino       : _Base(_Node_alloc_type(__al))
538*e4b17023SJohn Marino       { _M_initialize_dispatch(__il.begin(), __il.end(), __false_type()); }
539*e4b17023SJohn Marino 
540*e4b17023SJohn Marino       /**
541*e4b17023SJohn Marino        *  @brief  The forward_list dtor.
542*e4b17023SJohn Marino        */
543*e4b17023SJohn Marino       ~forward_list() noexcept
544*e4b17023SJohn Marino       { }
545*e4b17023SJohn Marino 
546*e4b17023SJohn Marino       /**
547*e4b17023SJohn Marino        *  @brief  The %forward_list assignment operator.
548*e4b17023SJohn Marino        *  @param  __list  A %forward_list of identical element and allocator
549*e4b17023SJohn Marino        *                types.
550*e4b17023SJohn Marino        *
551*e4b17023SJohn Marino        *  All the elements of @a __list are copied, but unlike the copy
552*e4b17023SJohn Marino        *  constructor, the allocator object is not copied.
553*e4b17023SJohn Marino        */
554*e4b17023SJohn Marino       forward_list&
555*e4b17023SJohn Marino       operator=(const forward_list& __list);
556*e4b17023SJohn Marino 
557*e4b17023SJohn Marino       /**
558*e4b17023SJohn Marino        *  @brief  The %forward_list move assignment operator.
559*e4b17023SJohn Marino        *  @param  __list  A %forward_list of identical element and allocator
560*e4b17023SJohn Marino        *                types.
561*e4b17023SJohn Marino        *
562*e4b17023SJohn Marino        *  The contents of @a __list are moved into this %forward_list
563*e4b17023SJohn Marino        *  (without copying). @a __list is a valid, but unspecified
564*e4b17023SJohn Marino        *  %forward_list
565*e4b17023SJohn Marino        */
566*e4b17023SJohn Marino       forward_list&
567*e4b17023SJohn Marino       operator=(forward_list&& __list)
568*e4b17023SJohn Marino       {
569*e4b17023SJohn Marino 	// NB: DR 1204.
570*e4b17023SJohn Marino 	// NB: DR 675.
571*e4b17023SJohn Marino 	this->clear();
572*e4b17023SJohn Marino 	this->swap(__list);
573*e4b17023SJohn Marino 	return *this;
574*e4b17023SJohn Marino       }
575*e4b17023SJohn Marino 
576*e4b17023SJohn Marino       /**
577*e4b17023SJohn Marino        *  @brief  The %forward_list initializer list assignment operator.
578*e4b17023SJohn Marino        *  @param  __il  An initializer_list of value_type.
579*e4b17023SJohn Marino        *
580*e4b17023SJohn Marino        *  Replace the contents of the %forward_list with copies of the
581*e4b17023SJohn Marino        *  elements in the initializer_list @a __il.  This is linear in
582*e4b17023SJohn Marino        *  __il.size().
583*e4b17023SJohn Marino        */
584*e4b17023SJohn Marino       forward_list&
585*e4b17023SJohn Marino       operator=(std::initializer_list<_Tp> __il)
586*e4b17023SJohn Marino       {
587*e4b17023SJohn Marino         assign(__il);
588*e4b17023SJohn Marino         return *this;
589*e4b17023SJohn Marino       }
590*e4b17023SJohn Marino 
591*e4b17023SJohn Marino       /**
592*e4b17023SJohn Marino        *  @brief  Assigns a range to a %forward_list.
593*e4b17023SJohn Marino        *  @param  __first  An input iterator.
594*e4b17023SJohn Marino        *  @param  __last   An input iterator.
595*e4b17023SJohn Marino        *
596*e4b17023SJohn Marino        *  This function fills a %forward_list with copies of the elements
597*e4b17023SJohn Marino        *  in the range [@a __first,@a __last).
598*e4b17023SJohn Marino        *
599*e4b17023SJohn Marino        *  Note that the assignment completely changes the %forward_list and
600*e4b17023SJohn Marino        *  that the number of elements of the resulting %forward_list's is the
601*e4b17023SJohn Marino        *  same as the number of elements assigned.  Old data is lost.
602*e4b17023SJohn Marino        */
603*e4b17023SJohn Marino       template<typename _InputIterator>
604*e4b17023SJohn Marino         void
605*e4b17023SJohn Marino         assign(_InputIterator __first, _InputIterator __last)
606*e4b17023SJohn Marino         {
607*e4b17023SJohn Marino           clear();
608*e4b17023SJohn Marino           insert_after(cbefore_begin(), __first, __last);
609*e4b17023SJohn Marino         }
610*e4b17023SJohn Marino 
611*e4b17023SJohn Marino       /**
612*e4b17023SJohn Marino        *  @brief  Assigns a given value to a %forward_list.
613*e4b17023SJohn Marino        *  @param  __n  Number of elements to be assigned.
614*e4b17023SJohn Marino        *  @param  __val  Value to be assigned.
615*e4b17023SJohn Marino        *
616*e4b17023SJohn Marino        *  This function fills a %forward_list with @a __n copies of the
617*e4b17023SJohn Marino        *  given value.  Note that the assignment completely changes the
618*e4b17023SJohn Marino        *  %forward_list, and that the resulting %forward_list has __n
619*e4b17023SJohn Marino        *  elements.  Old data is lost.
620*e4b17023SJohn Marino        */
621*e4b17023SJohn Marino       void
622*e4b17023SJohn Marino       assign(size_type __n, const _Tp& __val)
623*e4b17023SJohn Marino       {
624*e4b17023SJohn Marino         clear();
625*e4b17023SJohn Marino         insert_after(cbefore_begin(), __n, __val);
626*e4b17023SJohn Marino       }
627*e4b17023SJohn Marino 
628*e4b17023SJohn Marino       /**
629*e4b17023SJohn Marino        *  @brief  Assigns an initializer_list to a %forward_list.
630*e4b17023SJohn Marino        *  @param  __il  An initializer_list of value_type.
631*e4b17023SJohn Marino        *
632*e4b17023SJohn Marino        *  Replace the contents of the %forward_list with copies of the
633*e4b17023SJohn Marino        *  elements in the initializer_list @a __il.  This is linear in
634*e4b17023SJohn Marino        *  il.size().
635*e4b17023SJohn Marino        */
636*e4b17023SJohn Marino       void
637*e4b17023SJohn Marino       assign(std::initializer_list<_Tp> __il)
638*e4b17023SJohn Marino       {
639*e4b17023SJohn Marino         clear();
640*e4b17023SJohn Marino         insert_after(cbefore_begin(), __il);
641*e4b17023SJohn Marino       }
642*e4b17023SJohn Marino 
643*e4b17023SJohn Marino       /// Get a copy of the memory allocation object.
644*e4b17023SJohn Marino       allocator_type
645*e4b17023SJohn Marino       get_allocator() const noexcept
646*e4b17023SJohn Marino       { return allocator_type(this->_M_get_Node_allocator()); }
647*e4b17023SJohn Marino 
648*e4b17023SJohn Marino       // 23.2.3.2 iterators:
649*e4b17023SJohn Marino 
650*e4b17023SJohn Marino       /**
651*e4b17023SJohn Marino        *  Returns a read/write iterator that points before the first element
652*e4b17023SJohn Marino        *  in the %forward_list.  Iteration is done in ordinary element order.
653*e4b17023SJohn Marino        */
654*e4b17023SJohn Marino       iterator
655*e4b17023SJohn Marino       before_begin() noexcept
656*e4b17023SJohn Marino       { return iterator(&this->_M_impl._M_head); }
657*e4b17023SJohn Marino 
658*e4b17023SJohn Marino       /**
659*e4b17023SJohn Marino        *  Returns a read-only (constant) iterator that points before the
660*e4b17023SJohn Marino        *  first element in the %forward_list.  Iteration is done in ordinary
661*e4b17023SJohn Marino        *  element order.
662*e4b17023SJohn Marino        */
663*e4b17023SJohn Marino       const_iterator
664*e4b17023SJohn Marino       before_begin() const noexcept
665*e4b17023SJohn Marino       { return const_iterator(&this->_M_impl._M_head); }
666*e4b17023SJohn Marino 
667*e4b17023SJohn Marino       /**
668*e4b17023SJohn Marino        *  Returns a read/write iterator that points to the first element
669*e4b17023SJohn Marino        *  in the %forward_list.  Iteration is done in ordinary element order.
670*e4b17023SJohn Marino        */
671*e4b17023SJohn Marino       iterator
672*e4b17023SJohn Marino       begin() noexcept
673*e4b17023SJohn Marino       { return iterator(this->_M_impl._M_head._M_next); }
674*e4b17023SJohn Marino 
675*e4b17023SJohn Marino       /**
676*e4b17023SJohn Marino        *  Returns a read-only (constant) iterator that points to the first
677*e4b17023SJohn Marino        *  element in the %forward_list.  Iteration is done in ordinary
678*e4b17023SJohn Marino        *  element order.
679*e4b17023SJohn Marino        */
680*e4b17023SJohn Marino       const_iterator
681*e4b17023SJohn Marino       begin() const noexcept
682*e4b17023SJohn Marino       { return const_iterator(this->_M_impl._M_head._M_next); }
683*e4b17023SJohn Marino 
684*e4b17023SJohn Marino       /**
685*e4b17023SJohn Marino        *  Returns a read/write iterator that points one past the last
686*e4b17023SJohn Marino        *  element in the %forward_list.  Iteration is done in ordinary
687*e4b17023SJohn Marino        *  element order.
688*e4b17023SJohn Marino        */
689*e4b17023SJohn Marino       iterator
690*e4b17023SJohn Marino       end() noexcept
691*e4b17023SJohn Marino       { return iterator(0); }
692*e4b17023SJohn Marino 
693*e4b17023SJohn Marino       /**
694*e4b17023SJohn Marino        *  Returns a read-only iterator that points one past the last
695*e4b17023SJohn Marino        *  element in the %forward_list.  Iteration is done in ordinary
696*e4b17023SJohn Marino        *  element order.
697*e4b17023SJohn Marino        */
698*e4b17023SJohn Marino       const_iterator
699*e4b17023SJohn Marino       end() const noexcept
700*e4b17023SJohn Marino       { return const_iterator(0); }
701*e4b17023SJohn Marino 
702*e4b17023SJohn Marino       /**
703*e4b17023SJohn Marino        *  Returns a read-only (constant) iterator that points to the
704*e4b17023SJohn Marino        *  first element in the %forward_list.  Iteration is done in ordinary
705*e4b17023SJohn Marino        *  element order.
706*e4b17023SJohn Marino        */
707*e4b17023SJohn Marino       const_iterator
708*e4b17023SJohn Marino       cbegin() const noexcept
709*e4b17023SJohn Marino       { return const_iterator(this->_M_impl._M_head._M_next); }
710*e4b17023SJohn Marino 
711*e4b17023SJohn Marino       /**
712*e4b17023SJohn Marino        *  Returns a read-only (constant) iterator that points before the
713*e4b17023SJohn Marino        *  first element in the %forward_list.  Iteration is done in ordinary
714*e4b17023SJohn Marino        *  element order.
715*e4b17023SJohn Marino        */
716*e4b17023SJohn Marino       const_iterator
717*e4b17023SJohn Marino       cbefore_begin() const noexcept
718*e4b17023SJohn Marino       { return const_iterator(&this->_M_impl._M_head); }
719*e4b17023SJohn Marino 
720*e4b17023SJohn Marino       /**
721*e4b17023SJohn Marino        *  Returns a read-only (constant) iterator that points one past
722*e4b17023SJohn Marino        *  the last element in the %forward_list.  Iteration is done in
723*e4b17023SJohn Marino        *  ordinary element order.
724*e4b17023SJohn Marino        */
725*e4b17023SJohn Marino       const_iterator
726*e4b17023SJohn Marino       cend() const noexcept
727*e4b17023SJohn Marino       { return const_iterator(0); }
728*e4b17023SJohn Marino 
729*e4b17023SJohn Marino       /**
730*e4b17023SJohn Marino        *  Returns true if the %forward_list is empty.  (Thus begin() would
731*e4b17023SJohn Marino        *  equal end().)
732*e4b17023SJohn Marino        */
733*e4b17023SJohn Marino       bool
734*e4b17023SJohn Marino       empty() const noexcept
735*e4b17023SJohn Marino       { return this->_M_impl._M_head._M_next == 0; }
736*e4b17023SJohn Marino 
737*e4b17023SJohn Marino       /**
738*e4b17023SJohn Marino        *  Returns the largest possible number of elements of %forward_list.
739*e4b17023SJohn Marino        */
740*e4b17023SJohn Marino       size_type
741*e4b17023SJohn Marino       max_size() const noexcept
742*e4b17023SJohn Marino       { return this->_M_get_Node_allocator().max_size(); }
743*e4b17023SJohn Marino 
744*e4b17023SJohn Marino       // 23.2.3.3 element access:
745*e4b17023SJohn Marino 
746*e4b17023SJohn Marino       /**
747*e4b17023SJohn Marino        *  Returns a read/write reference to the data at the first
748*e4b17023SJohn Marino        *  element of the %forward_list.
749*e4b17023SJohn Marino        */
750*e4b17023SJohn Marino       reference
751*e4b17023SJohn Marino       front()
752*e4b17023SJohn Marino       {
753*e4b17023SJohn Marino         _Node* __front = static_cast<_Node*>(this->_M_impl._M_head._M_next);
754*e4b17023SJohn Marino         return __front->_M_value;
755*e4b17023SJohn Marino       }
756*e4b17023SJohn Marino 
757*e4b17023SJohn Marino       /**
758*e4b17023SJohn Marino        *  Returns a read-only (constant) reference to the data at the first
759*e4b17023SJohn Marino        *  element of the %forward_list.
760*e4b17023SJohn Marino        */
761*e4b17023SJohn Marino       const_reference
762*e4b17023SJohn Marino       front() const
763*e4b17023SJohn Marino       {
764*e4b17023SJohn Marino         _Node* __front = static_cast<_Node*>(this->_M_impl._M_head._M_next);
765*e4b17023SJohn Marino         return __front->_M_value;
766*e4b17023SJohn Marino       }
767*e4b17023SJohn Marino 
768*e4b17023SJohn Marino       // 23.2.3.4 modifiers:
769*e4b17023SJohn Marino 
770*e4b17023SJohn Marino       /**
771*e4b17023SJohn Marino        *  @brief  Constructs object in %forward_list at the front of the
772*e4b17023SJohn Marino        *          list.
773*e4b17023SJohn Marino        *  @param  __args  Arguments.
774*e4b17023SJohn Marino        *
775*e4b17023SJohn Marino        *  This function will insert an object of type Tp constructed
776*e4b17023SJohn Marino        *  with Tp(std::forward<Args>(args)...) at the front of the list
777*e4b17023SJohn Marino        *  Due to the nature of a %forward_list this operation can
778*e4b17023SJohn Marino        *  be done in constant time, and does not invalidate iterators
779*e4b17023SJohn Marino        *  and references.
780*e4b17023SJohn Marino        */
781*e4b17023SJohn Marino       template<typename... _Args>
782*e4b17023SJohn Marino         void
783*e4b17023SJohn Marino         emplace_front(_Args&&... __args)
784*e4b17023SJohn Marino         { this->_M_insert_after(cbefore_begin(),
785*e4b17023SJohn Marino                                 std::forward<_Args>(__args)...); }
786*e4b17023SJohn Marino 
787*e4b17023SJohn Marino       /**
788*e4b17023SJohn Marino        *  @brief  Add data to the front of the %forward_list.
789*e4b17023SJohn Marino        *  @param  __val  Data to be added.
790*e4b17023SJohn Marino        *
791*e4b17023SJohn Marino        *  This is a typical stack operation.  The function creates an
792*e4b17023SJohn Marino        *  element at the front of the %forward_list and assigns the given
793*e4b17023SJohn Marino        *  data to it.  Due to the nature of a %forward_list this operation
794*e4b17023SJohn Marino        *  can be done in constant time, and does not invalidate iterators
795*e4b17023SJohn Marino        *  and references.
796*e4b17023SJohn Marino        */
797*e4b17023SJohn Marino       void
798*e4b17023SJohn Marino       push_front(const _Tp& __val)
799*e4b17023SJohn Marino       { this->_M_insert_after(cbefore_begin(), __val); }
800*e4b17023SJohn Marino 
801*e4b17023SJohn Marino       /**
802*e4b17023SJohn Marino        *
803*e4b17023SJohn Marino        */
804*e4b17023SJohn Marino       void
805*e4b17023SJohn Marino       push_front(_Tp&& __val)
806*e4b17023SJohn Marino       { this->_M_insert_after(cbefore_begin(), std::move(__val)); }
807*e4b17023SJohn Marino 
808*e4b17023SJohn Marino       /**
809*e4b17023SJohn Marino        *  @brief  Removes first element.
810*e4b17023SJohn Marino        *
811*e4b17023SJohn Marino        *  This is a typical stack operation.  It shrinks the %forward_list
812*e4b17023SJohn Marino        *  by one.  Due to the nature of a %forward_list this operation can
813*e4b17023SJohn Marino        *  be done in constant time, and only invalidates iterators/references
814*e4b17023SJohn Marino        *  to the element being removed.
815*e4b17023SJohn Marino        *
816*e4b17023SJohn Marino        *  Note that no data is returned, and if the first element's data
817*e4b17023SJohn Marino        *  is needed, it should be retrieved before pop_front() is
818*e4b17023SJohn Marino        *  called.
819*e4b17023SJohn Marino        */
820*e4b17023SJohn Marino       void
821*e4b17023SJohn Marino       pop_front()
822*e4b17023SJohn Marino       { this->_M_erase_after(&this->_M_impl._M_head); }
823*e4b17023SJohn Marino 
824*e4b17023SJohn Marino       /**
825*e4b17023SJohn Marino        *  @brief  Constructs object in %forward_list after the specified
826*e4b17023SJohn Marino        *          iterator.
827*e4b17023SJohn Marino        *  @param  __pos  A const_iterator into the %forward_list.
828*e4b17023SJohn Marino        *  @param  __args  Arguments.
829*e4b17023SJohn Marino        *  @return  An iterator that points to the inserted data.
830*e4b17023SJohn Marino        *
831*e4b17023SJohn Marino        *  This function will insert an object of type T constructed
832*e4b17023SJohn Marino        *  with T(std::forward<Args>(args)...) after the specified
833*e4b17023SJohn Marino        *  location.  Due to the nature of a %forward_list this operation can
834*e4b17023SJohn Marino        *  be done in constant time, and does not invalidate iterators
835*e4b17023SJohn Marino        *  and references.
836*e4b17023SJohn Marino        */
837*e4b17023SJohn Marino       template<typename... _Args>
838*e4b17023SJohn Marino         iterator
839*e4b17023SJohn Marino         emplace_after(const_iterator __pos, _Args&&... __args)
840*e4b17023SJohn Marino         { return iterator(this->_M_insert_after(__pos,
841*e4b17023SJohn Marino                                           std::forward<_Args>(__args)...)); }
842*e4b17023SJohn Marino 
843*e4b17023SJohn Marino       /**
844*e4b17023SJohn Marino        *  @brief  Inserts given value into %forward_list after specified
845*e4b17023SJohn Marino        *          iterator.
846*e4b17023SJohn Marino        *  @param  __pos  An iterator into the %forward_list.
847*e4b17023SJohn Marino        *  @param  __val  Data to be inserted.
848*e4b17023SJohn Marino        *  @return  An iterator that points to the inserted data.
849*e4b17023SJohn Marino        *
850*e4b17023SJohn Marino        *  This function will insert a copy of the given value after
851*e4b17023SJohn Marino        *  the specified location.  Due to the nature of a %forward_list this
852*e4b17023SJohn Marino        *  operation can be done in constant time, and does not
853*e4b17023SJohn Marino        *  invalidate iterators and references.
854*e4b17023SJohn Marino        */
855*e4b17023SJohn Marino       iterator
856*e4b17023SJohn Marino       insert_after(const_iterator __pos, const _Tp& __val)
857*e4b17023SJohn Marino       { return iterator(this->_M_insert_after(__pos, __val)); }
858*e4b17023SJohn Marino 
859*e4b17023SJohn Marino       /**
860*e4b17023SJohn Marino        *
861*e4b17023SJohn Marino        */
862*e4b17023SJohn Marino       iterator
863*e4b17023SJohn Marino       insert_after(const_iterator __pos, _Tp&& __val)
864*e4b17023SJohn Marino       { return iterator(this->_M_insert_after(__pos, std::move(__val))); }
865*e4b17023SJohn Marino 
866*e4b17023SJohn Marino       /**
867*e4b17023SJohn Marino        *  @brief  Inserts a number of copies of given data into the
868*e4b17023SJohn Marino        *          %forward_list.
869*e4b17023SJohn Marino        *  @param  __pos  An iterator into the %forward_list.
870*e4b17023SJohn Marino        *  @param  __n  Number of elements to be inserted.
871*e4b17023SJohn Marino        *  @param  __val  Data to be inserted.
872*e4b17023SJohn Marino        *  @return  An iterator pointing to the last inserted copy of
873*e4b17023SJohn Marino        *           @a val or @a pos if @a n == 0.
874*e4b17023SJohn Marino        *
875*e4b17023SJohn Marino        *  This function will insert a specified number of copies of the
876*e4b17023SJohn Marino        *  given data after the location specified by @a pos.
877*e4b17023SJohn Marino        *
878*e4b17023SJohn Marino        *  This operation is linear in the number of elements inserted and
879*e4b17023SJohn Marino        *  does not invalidate iterators and references.
880*e4b17023SJohn Marino        */
881*e4b17023SJohn Marino       iterator
882*e4b17023SJohn Marino       insert_after(const_iterator __pos, size_type __n, const _Tp& __val);
883*e4b17023SJohn Marino 
884*e4b17023SJohn Marino       /**
885*e4b17023SJohn Marino        *  @brief  Inserts a range into the %forward_list.
886*e4b17023SJohn Marino        *  @param  __pos  An iterator into the %forward_list.
887*e4b17023SJohn Marino        *  @param  __first  An input iterator.
888*e4b17023SJohn Marino        *  @param  __last   An input iterator.
889*e4b17023SJohn Marino        *  @return  An iterator pointing to the last inserted element or
890*e4b17023SJohn Marino        *           @a __pos if @a __first == @a __last.
891*e4b17023SJohn Marino        *
892*e4b17023SJohn Marino        *  This function will insert copies of the data in the range
893*e4b17023SJohn Marino        *  [@a __first,@a __last) into the %forward_list after the
894*e4b17023SJohn Marino        *  location specified by @a __pos.
895*e4b17023SJohn Marino        *
896*e4b17023SJohn Marino        *  This operation is linear in the number of elements inserted and
897*e4b17023SJohn Marino        *  does not invalidate iterators and references.
898*e4b17023SJohn Marino        */
899*e4b17023SJohn Marino       template<typename _InputIterator>
900*e4b17023SJohn Marino         iterator
901*e4b17023SJohn Marino         insert_after(const_iterator __pos,
902*e4b17023SJohn Marino                      _InputIterator __first, _InputIterator __last);
903*e4b17023SJohn Marino 
904*e4b17023SJohn Marino       /**
905*e4b17023SJohn Marino        *  @brief  Inserts the contents of an initializer_list into
906*e4b17023SJohn Marino        *          %forward_list after the specified iterator.
907*e4b17023SJohn Marino        *  @param  __pos  An iterator into the %forward_list.
908*e4b17023SJohn Marino        *  @param  __il  An initializer_list of value_type.
909*e4b17023SJohn Marino        *  @return  An iterator pointing to the last inserted element
910*e4b17023SJohn Marino        *           or @a __pos if @a __il is empty.
911*e4b17023SJohn Marino        *
912*e4b17023SJohn Marino        *  This function will insert copies of the data in the
913*e4b17023SJohn Marino        *  initializer_list @a __il into the %forward_list before the location
914*e4b17023SJohn Marino        *  specified by @a __pos.
915*e4b17023SJohn Marino        *
916*e4b17023SJohn Marino        *  This operation is linear in the number of elements inserted and
917*e4b17023SJohn Marino        *  does not invalidate iterators and references.
918*e4b17023SJohn Marino        */
919*e4b17023SJohn Marino       iterator
920*e4b17023SJohn Marino       insert_after(const_iterator __pos, std::initializer_list<_Tp> __il)
921*e4b17023SJohn Marino       { return insert_after(__pos, __il.begin(), __il.end()); }
922*e4b17023SJohn Marino 
923*e4b17023SJohn Marino       /**
924*e4b17023SJohn Marino        *  @brief  Removes the element pointed to by the iterator following
925*e4b17023SJohn Marino        *          @c pos.
926*e4b17023SJohn Marino        *  @param  __pos  Iterator pointing before element to be erased.
927*e4b17023SJohn Marino        *  @return  An iterator pointing to the element following the one
928*e4b17023SJohn Marino        *           that was erased, or end() if no such element exists.
929*e4b17023SJohn Marino        *
930*e4b17023SJohn Marino        *  This function will erase the element at the given position and
931*e4b17023SJohn Marino        *  thus shorten the %forward_list by one.
932*e4b17023SJohn Marino        *
933*e4b17023SJohn Marino        *  Due to the nature of a %forward_list this operation can be done
934*e4b17023SJohn Marino        *  in constant time, and only invalidates iterators/references to
935*e4b17023SJohn Marino        *  the element being removed.  The user is also cautioned that
936*e4b17023SJohn Marino        *  this function only erases the element, and that if the element
937*e4b17023SJohn Marino        *  is itself a pointer, the pointed-to memory is not touched in
938*e4b17023SJohn Marino        *  any way.  Managing the pointer is the user's responsibility.
939*e4b17023SJohn Marino        */
940*e4b17023SJohn Marino       iterator
941*e4b17023SJohn Marino       erase_after(const_iterator __pos)
942*e4b17023SJohn Marino       { return iterator(this->_M_erase_after(const_cast<_Node_base*>
943*e4b17023SJohn Marino 					     (__pos._M_node))); }
944*e4b17023SJohn Marino 
945*e4b17023SJohn Marino       /**
946*e4b17023SJohn Marino        *  @brief  Remove a range of elements.
947*e4b17023SJohn Marino        *  @param  __pos  Iterator pointing before the first element to be
948*e4b17023SJohn Marino        *                 erased.
949*e4b17023SJohn Marino        *  @param  __last  Iterator pointing to one past the last element to be
950*e4b17023SJohn Marino        *                  erased.
951*e4b17023SJohn Marino        *  @return  @ __last.
952*e4b17023SJohn Marino        *
953*e4b17023SJohn Marino        *  This function will erase the elements in the range
954*e4b17023SJohn Marino        *  @a (__pos,__last) and shorten the %forward_list accordingly.
955*e4b17023SJohn Marino        *
956*e4b17023SJohn Marino        *  This operation is linear time in the size of the range and only
957*e4b17023SJohn Marino        *  invalidates iterators/references to the element being removed.
958*e4b17023SJohn Marino        *  The user is also cautioned that this function only erases the
959*e4b17023SJohn Marino        *  elements, and that if the elements themselves are pointers, the
960*e4b17023SJohn Marino        *  pointed-to memory is not touched in any way.  Managing the pointer
961*e4b17023SJohn Marino        *  is the user's responsibility.
962*e4b17023SJohn Marino        */
963*e4b17023SJohn Marino       iterator
964*e4b17023SJohn Marino       erase_after(const_iterator __pos, const_iterator __last)
965*e4b17023SJohn Marino       { return iterator(this->_M_erase_after(const_cast<_Node_base*>
966*e4b17023SJohn Marino 					     (__pos._M_node),
967*e4b17023SJohn Marino 					     const_cast<_Node_base*>
968*e4b17023SJohn Marino 					     (__last._M_node))); }
969*e4b17023SJohn Marino 
970*e4b17023SJohn Marino       /**
971*e4b17023SJohn Marino        *  @brief  Swaps data with another %forward_list.
972*e4b17023SJohn Marino        *  @param  __list  A %forward_list of the same element and allocator
973*e4b17023SJohn Marino        *                  types.
974*e4b17023SJohn Marino        *
975*e4b17023SJohn Marino        *  This exchanges the elements between two lists in constant
976*e4b17023SJohn Marino        *  time.  Note that the global std::swap() function is
977*e4b17023SJohn Marino        *  specialized such that std::swap(l1,l2) will feed to this
978*e4b17023SJohn Marino        *  function.
979*e4b17023SJohn Marino        */
980*e4b17023SJohn Marino       void
981*e4b17023SJohn Marino       swap(forward_list& __list)
982*e4b17023SJohn Marino       { std::swap(this->_M_impl._M_head._M_next,
983*e4b17023SJohn Marino 		  __list._M_impl._M_head._M_next); }
984*e4b17023SJohn Marino 
985*e4b17023SJohn Marino       /**
986*e4b17023SJohn Marino        *  @brief Resizes the %forward_list to the specified number of
987*e4b17023SJohn Marino        *         elements.
988*e4b17023SJohn Marino        *  @param __sz Number of elements the %forward_list should contain.
989*e4b17023SJohn Marino        *
990*e4b17023SJohn Marino        *  This function will %resize the %forward_list to the specified
991*e4b17023SJohn Marino        *  number of elements.  If the number is smaller than the
992*e4b17023SJohn Marino        *  %forward_list's current number of elements the %forward_list
993*e4b17023SJohn Marino        *  is truncated, otherwise the %forward_list is extended and the
994*e4b17023SJohn Marino        *  new elements are default constructed.
995*e4b17023SJohn Marino        */
996*e4b17023SJohn Marino       void
997*e4b17023SJohn Marino       resize(size_type __sz);
998*e4b17023SJohn Marino 
999*e4b17023SJohn Marino       /**
1000*e4b17023SJohn Marino        *  @brief Resizes the %forward_list to the specified number of
1001*e4b17023SJohn Marino        *         elements.
1002*e4b17023SJohn Marino        *  @param __sz Number of elements the %forward_list should contain.
1003*e4b17023SJohn Marino        *  @param __val Data with which new elements should be populated.
1004*e4b17023SJohn Marino        *
1005*e4b17023SJohn Marino        *  This function will %resize the %forward_list to the specified
1006*e4b17023SJohn Marino        *  number of elements.  If the number is smaller than the
1007*e4b17023SJohn Marino        *  %forward_list's current number of elements the %forward_list
1008*e4b17023SJohn Marino        *  is truncated, otherwise the %forward_list is extended and new
1009*e4b17023SJohn Marino        *  elements are populated with given data.
1010*e4b17023SJohn Marino        */
1011*e4b17023SJohn Marino       void
1012*e4b17023SJohn Marino       resize(size_type __sz, const value_type& __val);
1013*e4b17023SJohn Marino 
1014*e4b17023SJohn Marino       /**
1015*e4b17023SJohn Marino        *  @brief  Erases all the elements.
1016*e4b17023SJohn Marino        *
1017*e4b17023SJohn Marino        *  Note that this function only erases
1018*e4b17023SJohn Marino        *  the elements, and that if the elements themselves are
1019*e4b17023SJohn Marino        *  pointers, the pointed-to memory is not touched in any way.
1020*e4b17023SJohn Marino        *  Managing the pointer is the user's responsibility.
1021*e4b17023SJohn Marino        */
1022*e4b17023SJohn Marino       void
1023*e4b17023SJohn Marino       clear() noexcept
1024*e4b17023SJohn Marino       { this->_M_erase_after(&this->_M_impl._M_head, 0); }
1025*e4b17023SJohn Marino 
1026*e4b17023SJohn Marino       // 23.2.3.5 forward_list operations:
1027*e4b17023SJohn Marino 
1028*e4b17023SJohn Marino       /**
1029*e4b17023SJohn Marino        *  @brief  Insert contents of another %forward_list.
1030*e4b17023SJohn Marino        *  @param  __pos  Iterator referencing the element to insert after.
1031*e4b17023SJohn Marino        *  @param  __list  Source list.
1032*e4b17023SJohn Marino        *
1033*e4b17023SJohn Marino        *  The elements of @a list are inserted in constant time after
1034*e4b17023SJohn Marino        *  the element referenced by @a pos.  @a list becomes an empty
1035*e4b17023SJohn Marino        *  list.
1036*e4b17023SJohn Marino        *
1037*e4b17023SJohn Marino        *  Requires this != @a x.
1038*e4b17023SJohn Marino        */
1039*e4b17023SJohn Marino       void
1040*e4b17023SJohn Marino       splice_after(const_iterator __pos, forward_list&& __list)
1041*e4b17023SJohn Marino       {
1042*e4b17023SJohn Marino 	if (!__list.empty())
1043*e4b17023SJohn Marino 	  _M_splice_after(__pos, __list.before_begin(), __list.end());
1044*e4b17023SJohn Marino       }
1045*e4b17023SJohn Marino 
1046*e4b17023SJohn Marino       void
1047*e4b17023SJohn Marino       splice_after(const_iterator __pos, forward_list& __list)
1048*e4b17023SJohn Marino       { splice_after(__pos, std::move(__list)); }
1049*e4b17023SJohn Marino 
1050*e4b17023SJohn Marino       /**
1051*e4b17023SJohn Marino        *  @brief  Insert element from another %forward_list.
1052*e4b17023SJohn Marino        *  @param  __pos  Iterator referencing the element to insert after.
1053*e4b17023SJohn Marino        *  @param  __list  Source list.
1054*e4b17023SJohn Marino        *  @param  __i   Iterator referencing the element before the element
1055*e4b17023SJohn Marino        *                to move.
1056*e4b17023SJohn Marino        *
1057*e4b17023SJohn Marino        *  Removes the element in list @a list referenced by @a i and
1058*e4b17023SJohn Marino        *  inserts it into the current list after @a pos.
1059*e4b17023SJohn Marino        */
1060*e4b17023SJohn Marino       void
1061*e4b17023SJohn Marino       splice_after(const_iterator __pos, forward_list&& __list,
1062*e4b17023SJohn Marino                    const_iterator __i);
1063*e4b17023SJohn Marino 
1064*e4b17023SJohn Marino       void
1065*e4b17023SJohn Marino       splice_after(const_iterator __pos, forward_list& __list,
1066*e4b17023SJohn Marino                    const_iterator __i)
1067*e4b17023SJohn Marino       { splice_after(__pos, std::move(__list), __i); }
1068*e4b17023SJohn Marino 
1069*e4b17023SJohn Marino       /**
1070*e4b17023SJohn Marino        *  @brief  Insert range from another %forward_list.
1071*e4b17023SJohn Marino        *  @param  __pos  Iterator referencing the element to insert after.
1072*e4b17023SJohn Marino        *  @param  __list  Source list.
1073*e4b17023SJohn Marino        *  @param  __before  Iterator referencing before the start of range
1074*e4b17023SJohn Marino        *                    in list.
1075*e4b17023SJohn Marino        *  @param  __last  Iterator referencing the end of range in list.
1076*e4b17023SJohn Marino        *
1077*e4b17023SJohn Marino        *  Removes elements in the range (__before,__last) and inserts them
1078*e4b17023SJohn Marino        *  after @a __pos in constant time.
1079*e4b17023SJohn Marino        *
1080*e4b17023SJohn Marino        *  Undefined if @a __pos is in (__before,__last).
1081*e4b17023SJohn Marino        */
1082*e4b17023SJohn Marino       void
1083*e4b17023SJohn Marino       splice_after(const_iterator __pos, forward_list&&,
1084*e4b17023SJohn Marino                    const_iterator __before, const_iterator __last)
1085*e4b17023SJohn Marino       { _M_splice_after(__pos, __before, __last); }
1086*e4b17023SJohn Marino 
1087*e4b17023SJohn Marino       void
1088*e4b17023SJohn Marino       splice_after(const_iterator __pos, forward_list&,
1089*e4b17023SJohn Marino                    const_iterator __before, const_iterator __last)
1090*e4b17023SJohn Marino       { _M_splice_after(__pos, __before, __last); }
1091*e4b17023SJohn Marino 
1092*e4b17023SJohn Marino       /**
1093*e4b17023SJohn Marino        *  @brief  Remove all elements equal to value.
1094*e4b17023SJohn Marino        *  @param  __val  The value to remove.
1095*e4b17023SJohn Marino        *
1096*e4b17023SJohn Marino        *  Removes every element in the list equal to @a __val.
1097*e4b17023SJohn Marino        *  Remaining elements stay in list order.  Note that this
1098*e4b17023SJohn Marino        *  function only erases the elements, and that if the elements
1099*e4b17023SJohn Marino        *  themselves are pointers, the pointed-to memory is not
1100*e4b17023SJohn Marino        *  touched in any way.  Managing the pointer is the user's
1101*e4b17023SJohn Marino        *  responsibility.
1102*e4b17023SJohn Marino        */
1103*e4b17023SJohn Marino       void
1104*e4b17023SJohn Marino       remove(const _Tp& __val);
1105*e4b17023SJohn Marino 
1106*e4b17023SJohn Marino       /**
1107*e4b17023SJohn Marino        *  @brief  Remove all elements satisfying a predicate.
1108*e4b17023SJohn Marino        *  @param  __pred  Unary predicate function or object.
1109*e4b17023SJohn Marino        *
1110*e4b17023SJohn Marino        *  Removes every element in the list for which the predicate
1111*e4b17023SJohn Marino        *  returns true.  Remaining elements stay in list order.  Note
1112*e4b17023SJohn Marino        *  that this function only erases the elements, and that if the
1113*e4b17023SJohn Marino        *  elements themselves are pointers, the pointed-to memory is
1114*e4b17023SJohn Marino        *  not touched in any way.  Managing the pointer is the user's
1115*e4b17023SJohn Marino        *  responsibility.
1116*e4b17023SJohn Marino        */
1117*e4b17023SJohn Marino       template<typename _Pred>
1118*e4b17023SJohn Marino         void
1119*e4b17023SJohn Marino         remove_if(_Pred __pred);
1120*e4b17023SJohn Marino 
1121*e4b17023SJohn Marino       /**
1122*e4b17023SJohn Marino        *  @brief  Remove consecutive duplicate elements.
1123*e4b17023SJohn Marino        *
1124*e4b17023SJohn Marino        *  For each consecutive set of elements with the same value,
1125*e4b17023SJohn Marino        *  remove all but the first one.  Remaining elements stay in
1126*e4b17023SJohn Marino        *  list order.  Note that this function only erases the
1127*e4b17023SJohn Marino        *  elements, and that if the elements themselves are pointers,
1128*e4b17023SJohn Marino        *  the pointed-to memory is not touched in any way.  Managing
1129*e4b17023SJohn Marino        *  the pointer is the user's responsibility.
1130*e4b17023SJohn Marino        */
1131*e4b17023SJohn Marino       void
1132*e4b17023SJohn Marino       unique()
1133*e4b17023SJohn Marino       { unique(std::equal_to<_Tp>()); }
1134*e4b17023SJohn Marino 
1135*e4b17023SJohn Marino       /**
1136*e4b17023SJohn Marino        *  @brief  Remove consecutive elements satisfying a predicate.
1137*e4b17023SJohn Marino        *  @param  __binary_pred  Binary predicate function or object.
1138*e4b17023SJohn Marino        *
1139*e4b17023SJohn Marino        *  For each consecutive set of elements [first,last) that
1140*e4b17023SJohn Marino        *  satisfy predicate(first,i) where i is an iterator in
1141*e4b17023SJohn Marino        *  [first,last), remove all but the first one.  Remaining
1142*e4b17023SJohn Marino        *  elements stay in list order.  Note that this function only
1143*e4b17023SJohn Marino        *  erases the elements, and that if the elements themselves are
1144*e4b17023SJohn Marino        *  pointers, the pointed-to memory is not touched in any way.
1145*e4b17023SJohn Marino        *  Managing the pointer is the user's responsibility.
1146*e4b17023SJohn Marino        */
1147*e4b17023SJohn Marino       template<typename _BinPred>
1148*e4b17023SJohn Marino         void
1149*e4b17023SJohn Marino         unique(_BinPred __binary_pred);
1150*e4b17023SJohn Marino 
1151*e4b17023SJohn Marino       /**
1152*e4b17023SJohn Marino        *  @brief  Merge sorted lists.
1153*e4b17023SJohn Marino        *  @param  __list  Sorted list to merge.
1154*e4b17023SJohn Marino        *
1155*e4b17023SJohn Marino        *  Assumes that both @a list and this list are sorted according to
1156*e4b17023SJohn Marino        *  operator<().  Merges elements of @a __list into this list in
1157*e4b17023SJohn Marino        *  sorted order, leaving @a __list empty when complete.  Elements in
1158*e4b17023SJohn Marino        *  this list precede elements in @a __list that are equal.
1159*e4b17023SJohn Marino        */
1160*e4b17023SJohn Marino       void
1161*e4b17023SJohn Marino       merge(forward_list&& __list)
1162*e4b17023SJohn Marino       { merge(std::move(__list), std::less<_Tp>()); }
1163*e4b17023SJohn Marino 
1164*e4b17023SJohn Marino       void
1165*e4b17023SJohn Marino       merge(forward_list& __list)
1166*e4b17023SJohn Marino       { merge(std::move(__list)); }
1167*e4b17023SJohn Marino 
1168*e4b17023SJohn Marino       /**
1169*e4b17023SJohn Marino        *  @brief  Merge sorted lists according to comparison function.
1170*e4b17023SJohn Marino        *  @param  __list  Sorted list to merge.
1171*e4b17023SJohn Marino        *  @param  __comp Comparison function defining sort order.
1172*e4b17023SJohn Marino        *
1173*e4b17023SJohn Marino        *  Assumes that both @a __list and this list are sorted according to
1174*e4b17023SJohn Marino        *  comp.  Merges elements of @a __list into this list
1175*e4b17023SJohn Marino        *  in sorted order, leaving @a __list empty when complete.  Elements
1176*e4b17023SJohn Marino        *  in this list precede elements in @a __list that are equivalent
1177*e4b17023SJohn Marino        *  according to comp().
1178*e4b17023SJohn Marino        */
1179*e4b17023SJohn Marino       template<typename _Comp>
1180*e4b17023SJohn Marino         void
1181*e4b17023SJohn Marino         merge(forward_list&& __list, _Comp __comp);
1182*e4b17023SJohn Marino 
1183*e4b17023SJohn Marino       template<typename _Comp>
1184*e4b17023SJohn Marino         void
1185*e4b17023SJohn Marino         merge(forward_list& __list, _Comp __comp)
1186*e4b17023SJohn Marino         { merge(std::move(__list), __comp); }
1187*e4b17023SJohn Marino 
1188*e4b17023SJohn Marino       /**
1189*e4b17023SJohn Marino        *  @brief  Sort the elements of the list.
1190*e4b17023SJohn Marino        *
1191*e4b17023SJohn Marino        *  Sorts the elements of this list in NlogN time.  Equivalent
1192*e4b17023SJohn Marino        *  elements remain in list order.
1193*e4b17023SJohn Marino        */
1194*e4b17023SJohn Marino       void
1195*e4b17023SJohn Marino       sort()
1196*e4b17023SJohn Marino       { sort(std::less<_Tp>()); }
1197*e4b17023SJohn Marino 
1198*e4b17023SJohn Marino       /**
1199*e4b17023SJohn Marino        *  @brief  Sort the forward_list using a comparison function.
1200*e4b17023SJohn Marino        *
1201*e4b17023SJohn Marino        *  Sorts the elements of this list in NlogN time.  Equivalent
1202*e4b17023SJohn Marino        *  elements remain in list order.
1203*e4b17023SJohn Marino        */
1204*e4b17023SJohn Marino       template<typename _Comp>
1205*e4b17023SJohn Marino         void
1206*e4b17023SJohn Marino         sort(_Comp __comp);
1207*e4b17023SJohn Marino 
1208*e4b17023SJohn Marino       /**
1209*e4b17023SJohn Marino        *  @brief  Reverse the elements in list.
1210*e4b17023SJohn Marino        *
1211*e4b17023SJohn Marino        *  Reverse the order of elements in the list in linear time.
1212*e4b17023SJohn Marino        */
1213*e4b17023SJohn Marino       void
1214*e4b17023SJohn Marino       reverse() noexcept
1215*e4b17023SJohn Marino       { this->_M_impl._M_head._M_reverse_after(); }
1216*e4b17023SJohn Marino 
1217*e4b17023SJohn Marino     private:
1218*e4b17023SJohn Marino       template<typename _Integer>
1219*e4b17023SJohn Marino         void
1220*e4b17023SJohn Marino         _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type)
1221*e4b17023SJohn Marino         { _M_fill_initialize(static_cast<size_type>(__n), __x); }
1222*e4b17023SJohn Marino 
1223*e4b17023SJohn Marino       // Called by the range constructor to implement [23.1.1]/9
1224*e4b17023SJohn Marino       template<typename _InputIterator>
1225*e4b17023SJohn Marino         void
1226*e4b17023SJohn Marino         _M_initialize_dispatch(_InputIterator __first, _InputIterator __last,
1227*e4b17023SJohn Marino                                __false_type);
1228*e4b17023SJohn Marino 
1229*e4b17023SJohn Marino       // Called by forward_list(n,v,a), and the range constructor when it
1230*e4b17023SJohn Marino       // turns out to be the same thing.
1231*e4b17023SJohn Marino       void
1232*e4b17023SJohn Marino       _M_fill_initialize(size_type __n, const value_type& __value);
1233*e4b17023SJohn Marino 
1234*e4b17023SJohn Marino       // Called by splice_after and insert_after.
1235*e4b17023SJohn Marino       iterator
1236*e4b17023SJohn Marino       _M_splice_after(const_iterator __pos, const_iterator __before,
1237*e4b17023SJohn Marino 		      const_iterator __last);
1238*e4b17023SJohn Marino 
1239*e4b17023SJohn Marino       // Called by forward_list(n).
1240*e4b17023SJohn Marino       void
1241*e4b17023SJohn Marino       _M_default_initialize(size_type __n);
1242*e4b17023SJohn Marino 
1243*e4b17023SJohn Marino       // Called by resize(sz).
1244*e4b17023SJohn Marino       void
1245*e4b17023SJohn Marino       _M_default_insert_after(const_iterator __pos, size_type __n);
1246*e4b17023SJohn Marino     };
1247*e4b17023SJohn Marino 
1248*e4b17023SJohn Marino   /**
1249*e4b17023SJohn Marino    *  @brief  Forward list equality comparison.
1250*e4b17023SJohn Marino    *  @param  __lx  A %forward_list
1251*e4b17023SJohn Marino    *  @param  __ly  A %forward_list of the same type as @a __lx.
1252*e4b17023SJohn Marino    *  @return  True iff the elements of the forward lists are equal.
1253*e4b17023SJohn Marino    *
1254*e4b17023SJohn Marino    *  This is an equivalence relation.  It is linear in the number of
1255*e4b17023SJohn Marino    *  elements of the forward lists.  Deques are considered equivalent
1256*e4b17023SJohn Marino    *  if corresponding elements compare equal.
1257*e4b17023SJohn Marino    */
1258*e4b17023SJohn Marino   template<typename _Tp, typename _Alloc>
1259*e4b17023SJohn Marino     bool
1260*e4b17023SJohn Marino     operator==(const forward_list<_Tp, _Alloc>& __lx,
1261*e4b17023SJohn Marino                const forward_list<_Tp, _Alloc>& __ly);
1262*e4b17023SJohn Marino 
1263*e4b17023SJohn Marino   /**
1264*e4b17023SJohn Marino    *  @brief  Forward list ordering relation.
1265*e4b17023SJohn Marino    *  @param  __lx  A %forward_list.
1266*e4b17023SJohn Marino    *  @param  __ly  A %forward_list of the same type as @a __lx.
1267*e4b17023SJohn Marino    *  @return  True iff @a __lx is lexicographically less than @a __ly.
1268*e4b17023SJohn Marino    *
1269*e4b17023SJohn Marino    *  This is a total ordering relation.  It is linear in the number of
1270*e4b17023SJohn Marino    *  elements of the forward lists.  The elements must be comparable
1271*e4b17023SJohn Marino    *  with @c <.
1272*e4b17023SJohn Marino    *
1273*e4b17023SJohn Marino    *  See std::lexicographical_compare() for how the determination is made.
1274*e4b17023SJohn Marino    */
1275*e4b17023SJohn Marino   template<typename _Tp, typename _Alloc>
1276*e4b17023SJohn Marino     inline bool
1277*e4b17023SJohn Marino     operator<(const forward_list<_Tp, _Alloc>& __lx,
1278*e4b17023SJohn Marino               const forward_list<_Tp, _Alloc>& __ly)
1279*e4b17023SJohn Marino     { return std::lexicographical_compare(__lx.cbegin(), __lx.cend(),
1280*e4b17023SJohn Marino 					  __ly.cbegin(), __ly.cend()); }
1281*e4b17023SJohn Marino 
1282*e4b17023SJohn Marino   /// Based on operator==
1283*e4b17023SJohn Marino   template<typename _Tp, typename _Alloc>
1284*e4b17023SJohn Marino     inline bool
1285*e4b17023SJohn Marino     operator!=(const forward_list<_Tp, _Alloc>& __lx,
1286*e4b17023SJohn Marino                const forward_list<_Tp, _Alloc>& __ly)
1287*e4b17023SJohn Marino     { return !(__lx == __ly); }
1288*e4b17023SJohn Marino 
1289*e4b17023SJohn Marino   /// Based on operator<
1290*e4b17023SJohn Marino   template<typename _Tp, typename _Alloc>
1291*e4b17023SJohn Marino     inline bool
1292*e4b17023SJohn Marino     operator>(const forward_list<_Tp, _Alloc>& __lx,
1293*e4b17023SJohn Marino               const forward_list<_Tp, _Alloc>& __ly)
1294*e4b17023SJohn Marino     { return (__ly < __lx); }
1295*e4b17023SJohn Marino 
1296*e4b17023SJohn Marino   /// Based on operator<
1297*e4b17023SJohn Marino   template<typename _Tp, typename _Alloc>
1298*e4b17023SJohn Marino     inline bool
1299*e4b17023SJohn Marino     operator>=(const forward_list<_Tp, _Alloc>& __lx,
1300*e4b17023SJohn Marino                const forward_list<_Tp, _Alloc>& __ly)
1301*e4b17023SJohn Marino     { return !(__lx < __ly); }
1302*e4b17023SJohn Marino 
1303*e4b17023SJohn Marino   /// Based on operator<
1304*e4b17023SJohn Marino   template<typename _Tp, typename _Alloc>
1305*e4b17023SJohn Marino     inline bool
1306*e4b17023SJohn Marino     operator<=(const forward_list<_Tp, _Alloc>& __lx,
1307*e4b17023SJohn Marino                const forward_list<_Tp, _Alloc>& __ly)
1308*e4b17023SJohn Marino     { return !(__ly < __lx); }
1309*e4b17023SJohn Marino 
1310*e4b17023SJohn Marino   /// See std::forward_list::swap().
1311*e4b17023SJohn Marino   template<typename _Tp, typename _Alloc>
1312*e4b17023SJohn Marino     inline void
1313*e4b17023SJohn Marino     swap(forward_list<_Tp, _Alloc>& __lx,
1314*e4b17023SJohn Marino 	 forward_list<_Tp, _Alloc>& __ly)
1315*e4b17023SJohn Marino     { __lx.swap(__ly); }
1316*e4b17023SJohn Marino 
1317*e4b17023SJohn Marino _GLIBCXX_END_NAMESPACE_CONTAINER
1318*e4b17023SJohn Marino } // namespace std
1319*e4b17023SJohn Marino 
1320*e4b17023SJohn Marino #endif // _FORWARD_LIST_H
1321