xref: /haiku/headers/cpp/stl_slist.h (revision f2ced752a08ff5d2618826bcd3ae3976c9f3e92e)
1*f2ced752SOliver Tappe /*
2*f2ced752SOliver Tappe  * Copyright (c) 1997
3*f2ced752SOliver Tappe  * Silicon Graphics Computer Systems, Inc.
4*f2ced752SOliver Tappe  *
5*f2ced752SOliver Tappe  * Permission to use, copy, modify, distribute and sell this software
6*f2ced752SOliver Tappe  * and its documentation for any purpose is hereby granted without fee,
7*f2ced752SOliver Tappe  * provided that the above copyright notice appear in all copies and
8*f2ced752SOliver Tappe  * that both that copyright notice and this permission notice appear
9*f2ced752SOliver Tappe  * in supporting documentation.  Silicon Graphics makes no
10*f2ced752SOliver Tappe  * representations about the suitability of this software for any
11*f2ced752SOliver Tappe  * purpose.  It is provided "as is" without express or implied warranty.
12*f2ced752SOliver Tappe  *
13*f2ced752SOliver Tappe  */
14*f2ced752SOliver Tappe 
15*f2ced752SOliver Tappe /* NOTE: This is an internal header file, included by other STL headers.
16*f2ced752SOliver Tappe  *   You should not attempt to use it directly.
17*f2ced752SOliver Tappe  */
18*f2ced752SOliver Tappe 
19*f2ced752SOliver Tappe #ifndef __SGI_STL_INTERNAL_SLIST_H
20*f2ced752SOliver Tappe #define __SGI_STL_INTERNAL_SLIST_H
21*f2ced752SOliver Tappe 
22*f2ced752SOliver Tappe 
23*f2ced752SOliver Tappe __STL_BEGIN_NAMESPACE
24*f2ced752SOliver Tappe 
25*f2ced752SOliver Tappe #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
26*f2ced752SOliver Tappe #pragma set woff 1174
27*f2ced752SOliver Tappe #pragma set woff 1375
28*f2ced752SOliver Tappe #endif
29*f2ced752SOliver Tappe 
30*f2ced752SOliver Tappe struct _Slist_node_base
31*f2ced752SOliver Tappe {
32*f2ced752SOliver Tappe   _Slist_node_base* _M_next;
33*f2ced752SOliver Tappe };
34*f2ced752SOliver Tappe 
35*f2ced752SOliver Tappe inline _Slist_node_base*
__slist_make_link(_Slist_node_base * __prev_node,_Slist_node_base * __new_node)36*f2ced752SOliver Tappe __slist_make_link(_Slist_node_base* __prev_node,
37*f2ced752SOliver Tappe                   _Slist_node_base* __new_node)
38*f2ced752SOliver Tappe {
39*f2ced752SOliver Tappe   __new_node->_M_next = __prev_node->_M_next;
40*f2ced752SOliver Tappe   __prev_node->_M_next = __new_node;
41*f2ced752SOliver Tappe   return __new_node;
42*f2ced752SOliver Tappe }
43*f2ced752SOliver Tappe 
44*f2ced752SOliver Tappe inline _Slist_node_base*
__slist_previous(_Slist_node_base * __head,const _Slist_node_base * __node)45*f2ced752SOliver Tappe __slist_previous(_Slist_node_base* __head,
46*f2ced752SOliver Tappe                  const _Slist_node_base* __node)
47*f2ced752SOliver Tappe {
48*f2ced752SOliver Tappe   while (__head && __head->_M_next != __node)
49*f2ced752SOliver Tappe     __head = __head->_M_next;
50*f2ced752SOliver Tappe   return __head;
51*f2ced752SOliver Tappe }
52*f2ced752SOliver Tappe 
53*f2ced752SOliver Tappe inline const _Slist_node_base*
__slist_previous(const _Slist_node_base * __head,const _Slist_node_base * __node)54*f2ced752SOliver Tappe __slist_previous(const _Slist_node_base* __head,
55*f2ced752SOliver Tappe                  const _Slist_node_base* __node)
56*f2ced752SOliver Tappe {
57*f2ced752SOliver Tappe   while (__head && __head->_M_next != __node)
58*f2ced752SOliver Tappe     __head = __head->_M_next;
59*f2ced752SOliver Tappe   return __head;
60*f2ced752SOliver Tappe }
61*f2ced752SOliver Tappe 
__slist_splice_after(_Slist_node_base * __pos,_Slist_node_base * __before_first,_Slist_node_base * __before_last)62*f2ced752SOliver Tappe inline void __slist_splice_after(_Slist_node_base* __pos,
63*f2ced752SOliver Tappe                                  _Slist_node_base* __before_first,
64*f2ced752SOliver Tappe                                  _Slist_node_base* __before_last)
65*f2ced752SOliver Tappe {
66*f2ced752SOliver Tappe   if (__pos != __before_first && __pos != __before_last) {
67*f2ced752SOliver Tappe     _Slist_node_base* __first = __before_first->_M_next;
68*f2ced752SOliver Tappe     _Slist_node_base* __after = __pos->_M_next;
69*f2ced752SOliver Tappe     __before_first->_M_next = __before_last->_M_next;
70*f2ced752SOliver Tappe     __pos->_M_next = __first;
71*f2ced752SOliver Tappe     __before_last->_M_next = __after;
72*f2ced752SOliver Tappe   }
73*f2ced752SOliver Tappe }
74*f2ced752SOliver Tappe 
__slist_reverse(_Slist_node_base * __node)75*f2ced752SOliver Tappe inline _Slist_node_base* __slist_reverse(_Slist_node_base* __node)
76*f2ced752SOliver Tappe {
77*f2ced752SOliver Tappe   _Slist_node_base* __result = __node;
78*f2ced752SOliver Tappe   __node = __node->_M_next;
79*f2ced752SOliver Tappe   __result->_M_next = 0;
80*f2ced752SOliver Tappe   while(__node) {
81*f2ced752SOliver Tappe     _Slist_node_base* __next = __node->_M_next;
82*f2ced752SOliver Tappe     __node->_M_next = __result;
83*f2ced752SOliver Tappe     __result = __node;
84*f2ced752SOliver Tappe     __node = __next;
85*f2ced752SOliver Tappe   }
86*f2ced752SOliver Tappe   return __result;
87*f2ced752SOliver Tappe }
88*f2ced752SOliver Tappe 
__slist_size(_Slist_node_base * __node)89*f2ced752SOliver Tappe inline size_t __slist_size(_Slist_node_base* __node)
90*f2ced752SOliver Tappe {
91*f2ced752SOliver Tappe   size_t __result = 0;
92*f2ced752SOliver Tappe   for ( ; __node != 0; __node = __node->_M_next)
93*f2ced752SOliver Tappe     ++__result;
94*f2ced752SOliver Tappe   return __result;
95*f2ced752SOliver Tappe }
96*f2ced752SOliver Tappe 
97*f2ced752SOliver Tappe template <class _Tp>
98*f2ced752SOliver Tappe struct _Slist_node : public _Slist_node_base
99*f2ced752SOliver Tappe {
100*f2ced752SOliver Tappe   _Tp _M_data;
101*f2ced752SOliver Tappe };
102*f2ced752SOliver Tappe 
103*f2ced752SOliver Tappe struct _Slist_iterator_base
104*f2ced752SOliver Tappe {
105*f2ced752SOliver Tappe   typedef size_t               size_type;
106*f2ced752SOliver Tappe   typedef ptrdiff_t            difference_type;
107*f2ced752SOliver Tappe   typedef forward_iterator_tag iterator_category;
108*f2ced752SOliver Tappe 
109*f2ced752SOliver Tappe   _Slist_node_base* _M_node;
110*f2ced752SOliver Tappe 
_Slist_iterator_base_Slist_iterator_base111*f2ced752SOliver Tappe   _Slist_iterator_base(_Slist_node_base* __x) : _M_node(__x) {}
_M_incr_Slist_iterator_base112*f2ced752SOliver Tappe   void _M_incr() { _M_node = _M_node->_M_next; }
113*f2ced752SOliver Tappe 
114*f2ced752SOliver Tappe   bool operator==(const _Slist_iterator_base& __x) const {
115*f2ced752SOliver Tappe     return _M_node == __x._M_node;
116*f2ced752SOliver Tappe   }
117*f2ced752SOliver Tappe   bool operator!=(const _Slist_iterator_base& __x) const {
118*f2ced752SOliver Tappe     return _M_node != __x._M_node;
119*f2ced752SOliver Tappe   }
120*f2ced752SOliver Tappe };
121*f2ced752SOliver Tappe 
122*f2ced752SOliver Tappe template <class _Tp, class _Ref, class _Ptr>
123*f2ced752SOliver Tappe struct _Slist_iterator : public _Slist_iterator_base
124*f2ced752SOliver Tappe {
125*f2ced752SOliver Tappe   typedef _Slist_iterator<_Tp, _Tp&, _Tp*>             iterator;
126*f2ced752SOliver Tappe   typedef _Slist_iterator<_Tp, const _Tp&, const _Tp*> const_iterator;
127*f2ced752SOliver Tappe   typedef _Slist_iterator<_Tp, _Ref, _Ptr>             _Self;
128*f2ced752SOliver Tappe 
129*f2ced752SOliver Tappe   typedef _Tp              value_type;
130*f2ced752SOliver Tappe   typedef _Ptr             pointer;
131*f2ced752SOliver Tappe   typedef _Ref             reference;
132*f2ced752SOliver Tappe   typedef _Slist_node<_Tp> _Node;
133*f2ced752SOliver Tappe 
_Slist_iterator_Slist_iterator134*f2ced752SOliver Tappe   _Slist_iterator(_Node* __x) : _Slist_iterator_base(__x) {}
_Slist_iterator_Slist_iterator135*f2ced752SOliver Tappe   _Slist_iterator() : _Slist_iterator_base(0) {}
_Slist_iterator_Slist_iterator136*f2ced752SOliver Tappe   _Slist_iterator(const iterator& __x) : _Slist_iterator_base(__x._M_node) {}
137*f2ced752SOliver Tappe 
138*f2ced752SOliver Tappe   reference operator*() const { return ((_Node*) _M_node)->_M_data; }
139*f2ced752SOliver Tappe #ifndef __SGI_STL_NO_ARROW_OPERATOR
140*f2ced752SOliver Tappe   pointer operator->() const { return &(operator*()); }
141*f2ced752SOliver Tappe #endif /* __SGI_STL_NO_ARROW_OPERATOR */
142*f2ced752SOliver Tappe 
143*f2ced752SOliver Tappe   _Self& operator++()
144*f2ced752SOliver Tappe   {
145*f2ced752SOliver Tappe     _M_incr();
146*f2ced752SOliver Tappe     return *this;
147*f2ced752SOliver Tappe   }
148*f2ced752SOliver Tappe   _Self operator++(int)
149*f2ced752SOliver Tappe   {
150*f2ced752SOliver Tappe     _Self __tmp = *this;
151*f2ced752SOliver Tappe     _M_incr();
152*f2ced752SOliver Tappe     return __tmp;
153*f2ced752SOliver Tappe   }
154*f2ced752SOliver Tappe };
155*f2ced752SOliver Tappe 
156*f2ced752SOliver Tappe #ifndef __STL_CLASS_PARTIAL_SPECIALIZATION
157*f2ced752SOliver Tappe 
distance_type(const _Slist_iterator_base &)158*f2ced752SOliver Tappe inline ptrdiff_t* distance_type(const _Slist_iterator_base&) {
159*f2ced752SOliver Tappe   return 0;
160*f2ced752SOliver Tappe }
161*f2ced752SOliver Tappe 
iterator_category(const _Slist_iterator_base &)162*f2ced752SOliver Tappe inline forward_iterator_tag iterator_category(const _Slist_iterator_base&) {
163*f2ced752SOliver Tappe   return forward_iterator_tag();
164*f2ced752SOliver Tappe }
165*f2ced752SOliver Tappe 
166*f2ced752SOliver Tappe template <class _Tp, class _Ref, class _Ptr>
value_type(const _Slist_iterator<_Tp,_Ref,_Ptr> &)167*f2ced752SOliver Tappe inline _Tp* value_type(const _Slist_iterator<_Tp, _Ref, _Ptr>&) {
168*f2ced752SOliver Tappe   return 0;
169*f2ced752SOliver Tappe }
170*f2ced752SOliver Tappe 
171*f2ced752SOliver Tappe #endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
172*f2ced752SOliver Tappe 
173*f2ced752SOliver Tappe // Base class that encapsulates details of allocators.  Three cases:
174*f2ced752SOliver Tappe // an ordinary standard-conforming allocator, a standard-conforming
175*f2ced752SOliver Tappe // allocator with no non-static data, and an SGI-style allocator.
176*f2ced752SOliver Tappe // This complexity is necessary only because we're worrying about backward
177*f2ced752SOliver Tappe // compatibility and because we want to avoid wasting storage on an
178*f2ced752SOliver Tappe // allocator instance if it isn't necessary.
179*f2ced752SOliver Tappe 
180*f2ced752SOliver Tappe #ifdef __STL_USE_STD_ALLOCATORS
181*f2ced752SOliver Tappe 
182*f2ced752SOliver Tappe // Base for general standard-conforming allocators.
183*f2ced752SOliver Tappe template <class _Tp, class _Allocator, bool _IsStatic>
184*f2ced752SOliver Tappe class _Slist_alloc_base {
185*f2ced752SOliver Tappe public:
186*f2ced752SOliver Tappe   typedef typename _Alloc_traits<_Tp,_Allocator>::allocator_type
187*f2ced752SOliver Tappe           allocator_type;
get_allocator()188*f2ced752SOliver Tappe   allocator_type get_allocator() const { return _M_node_allocator; }
189*f2ced752SOliver Tappe 
_Slist_alloc_base(const allocator_type & __a)190*f2ced752SOliver Tappe   _Slist_alloc_base(const allocator_type& __a) : _M_node_allocator(__a) {}
191*f2ced752SOliver Tappe 
192*f2ced752SOliver Tappe protected:
_M_get_node()193*f2ced752SOliver Tappe   _Slist_node<_Tp>* _M_get_node()
194*f2ced752SOliver Tappe     { return _M_node_allocator.allocate(1); }
_M_put_node(_Slist_node<_Tp> * __p)195*f2ced752SOliver Tappe   void _M_put_node(_Slist_node<_Tp>* __p)
196*f2ced752SOliver Tappe     { _M_node_allocator.deallocate(__p, 1); }
197*f2ced752SOliver Tappe 
198*f2ced752SOliver Tappe protected:
199*f2ced752SOliver Tappe   typename _Alloc_traits<_Slist_node<_Tp>,_Allocator>::allocator_type
200*f2ced752SOliver Tappe            _M_node_allocator;
201*f2ced752SOliver Tappe   _Slist_node_base _M_head;
202*f2ced752SOliver Tappe };
203*f2ced752SOliver Tappe 
204*f2ced752SOliver Tappe // Specialization for instanceless allocators.
205*f2ced752SOliver Tappe template <class _Tp, class _Allocator>
206*f2ced752SOliver Tappe class _Slist_alloc_base<_Tp,_Allocator, true> {
207*f2ced752SOliver Tappe public:
208*f2ced752SOliver Tappe   typedef typename _Alloc_traits<_Tp,_Allocator>::allocator_type
209*f2ced752SOliver Tappe           allocator_type;
get_allocator()210*f2ced752SOliver Tappe   allocator_type get_allocator() const { return allocator_type(); }
211*f2ced752SOliver Tappe 
_Slist_alloc_base(const allocator_type &)212*f2ced752SOliver Tappe   _Slist_alloc_base(const allocator_type&) {}
213*f2ced752SOliver Tappe 
214*f2ced752SOliver Tappe protected:
215*f2ced752SOliver Tappe   typedef typename _Alloc_traits<_Slist_node<_Tp>, _Allocator>::_Alloc_type
216*f2ced752SOliver Tappe           _Alloc_type;
_M_get_node()217*f2ced752SOliver Tappe   _Slist_node<_Tp>* _M_get_node() { return _Alloc_type::allocate(1); }
_M_put_node(_Slist_node<_Tp> * __p)218*f2ced752SOliver Tappe   void _M_put_node(_Slist_node<_Tp>* __p) { _Alloc_type::deallocate(__p, 1); }
219*f2ced752SOliver Tappe 
220*f2ced752SOliver Tappe protected:
221*f2ced752SOliver Tappe   _Slist_node_base _M_head;
222*f2ced752SOliver Tappe };
223*f2ced752SOliver Tappe 
224*f2ced752SOliver Tappe 
225*f2ced752SOliver Tappe template <class _Tp, class _Alloc>
226*f2ced752SOliver Tappe struct _Slist_base
227*f2ced752SOliver Tappe   : public _Slist_alloc_base<_Tp, _Alloc,
228*f2ced752SOliver Tappe                              _Alloc_traits<_Tp, _Alloc>::_S_instanceless>
229*f2ced752SOliver Tappe {
230*f2ced752SOliver Tappe   typedef _Slist_alloc_base<_Tp, _Alloc,
231*f2ced752SOliver Tappe                             _Alloc_traits<_Tp, _Alloc>::_S_instanceless>
232*f2ced752SOliver Tappe           _Base;
233*f2ced752SOliver Tappe   typedef typename _Base::allocator_type allocator_type;
234*f2ced752SOliver Tappe 
_Slist_base_Slist_base235*f2ced752SOliver Tappe   _Slist_base(const allocator_type& __a) : _Base(__a) { _M_head._M_next = 0; }
~_Slist_base_Slist_base236*f2ced752SOliver Tappe   ~_Slist_base() { _M_erase_after(&_M_head, 0); }
237*f2ced752SOliver Tappe 
238*f2ced752SOliver Tappe protected:
239*f2ced752SOliver Tappe 
_M_erase_after_Slist_base240*f2ced752SOliver Tappe   _Slist_node_base* _M_erase_after(_Slist_node_base* __pos)
241*f2ced752SOliver Tappe   {
242*f2ced752SOliver Tappe     _Slist_node<_Tp>* __next = (_Slist_node<_Tp>*) (__pos->_M_next);
243*f2ced752SOliver Tappe     _Slist_node_base* __next_next = __next->_M_next;
244*f2ced752SOliver Tappe     __pos->_M_next = __next_next;
245*f2ced752SOliver Tappe     destroy(&__next->_M_data);
246*f2ced752SOliver Tappe     _M_put_node(__next);
247*f2ced752SOliver Tappe     return __next_next;
248*f2ced752SOliver Tappe   }
249*f2ced752SOliver Tappe   _Slist_node_base* _M_erase_after(_Slist_node_base*, _Slist_node_base*);
250*f2ced752SOliver Tappe };
251*f2ced752SOliver Tappe 
252*f2ced752SOliver Tappe #else /* __STL_USE_STD_ALLOCATORS */
253*f2ced752SOliver Tappe 
254*f2ced752SOliver Tappe template <class _Tp, class _Alloc>
255*f2ced752SOliver Tappe struct _Slist_base {
256*f2ced752SOliver Tappe   typedef _Alloc allocator_type;
get_allocator_Slist_base257*f2ced752SOliver Tappe   allocator_type get_allocator() const { return allocator_type(); }
258*f2ced752SOliver Tappe 
_Slist_base_Slist_base259*f2ced752SOliver Tappe   _Slist_base(const allocator_type&) { _M_head._M_next = 0; }
~_Slist_base_Slist_base260*f2ced752SOliver Tappe   ~_Slist_base() { _M_erase_after(&_M_head, 0); }
261*f2ced752SOliver Tappe 
262*f2ced752SOliver Tappe protected:
263*f2ced752SOliver Tappe   typedef simple_alloc<_Slist_node<_Tp>, _Alloc> _Alloc_type;
_M_get_node_Slist_base264*f2ced752SOliver Tappe   _Slist_node<_Tp>* _M_get_node() { return _Alloc_type::allocate(1); }
_M_put_node_Slist_base265*f2ced752SOliver Tappe   void _M_put_node(_Slist_node<_Tp>* __p) { _Alloc_type::deallocate(__p, 1); }
266*f2ced752SOliver Tappe 
_M_erase_after_Slist_base267*f2ced752SOliver Tappe   _Slist_node_base* _M_erase_after(_Slist_node_base* __pos)
268*f2ced752SOliver Tappe   {
269*f2ced752SOliver Tappe     _Slist_node<_Tp>* __next = (_Slist_node<_Tp>*) (__pos->_M_next);
270*f2ced752SOliver Tappe     _Slist_node_base* __next_next = __next->_M_next;
271*f2ced752SOliver Tappe     __pos->_M_next = __next_next;
272*f2ced752SOliver Tappe     destroy(&__next->_M_data);
273*f2ced752SOliver Tappe     _M_put_node(__next);
274*f2ced752SOliver Tappe     return __next_next;
275*f2ced752SOliver Tappe   }
276*f2ced752SOliver Tappe   _Slist_node_base* _M_erase_after(_Slist_node_base*, _Slist_node_base*);
277*f2ced752SOliver Tappe 
278*f2ced752SOliver Tappe protected:
279*f2ced752SOliver Tappe   _Slist_node_base _M_head;
280*f2ced752SOliver Tappe };
281*f2ced752SOliver Tappe 
282*f2ced752SOliver Tappe #endif /* __STL_USE_STD_ALLOCATORS */
283*f2ced752SOliver Tappe 
284*f2ced752SOliver Tappe template <class _Tp, class _Alloc>
285*f2ced752SOliver Tappe _Slist_node_base*
_M_erase_after(_Slist_node_base * __before_first,_Slist_node_base * __last_node)286*f2ced752SOliver Tappe _Slist_base<_Tp,_Alloc>::_M_erase_after(_Slist_node_base* __before_first,
287*f2ced752SOliver Tappe                                         _Slist_node_base* __last_node) {
288*f2ced752SOliver Tappe   _Slist_node<_Tp>* __cur = (_Slist_node<_Tp>*) (__before_first->_M_next);
289*f2ced752SOliver Tappe   while (__cur != __last_node) {
290*f2ced752SOliver Tappe     _Slist_node<_Tp>* __tmp = __cur;
291*f2ced752SOliver Tappe     __cur = (_Slist_node<_Tp>*) __cur->_M_next;
292*f2ced752SOliver Tappe     destroy(&__tmp->_M_data);
293*f2ced752SOliver Tappe     _M_put_node(__tmp);
294*f2ced752SOliver Tappe   }
295*f2ced752SOliver Tappe   __before_first->_M_next = __last_node;
296*f2ced752SOliver Tappe   return __last_node;
297*f2ced752SOliver Tappe }
298*f2ced752SOliver Tappe 
299*f2ced752SOliver Tappe template <class _Tp, class _Alloc = __STL_DEFAULT_ALLOCATOR(_Tp) >
300*f2ced752SOliver Tappe class slist : private _Slist_base<_Tp,_Alloc>
301*f2ced752SOliver Tappe {
302*f2ced752SOliver Tappe private:
303*f2ced752SOliver Tappe   typedef _Slist_base<_Tp,_Alloc> _Base;
304*f2ced752SOliver Tappe public:
305*f2ced752SOliver Tappe   typedef _Tp                value_type;
306*f2ced752SOliver Tappe   typedef value_type*       pointer;
307*f2ced752SOliver Tappe   typedef const value_type* const_pointer;
308*f2ced752SOliver Tappe   typedef value_type&       reference;
309*f2ced752SOliver Tappe   typedef const value_type& const_reference;
310*f2ced752SOliver Tappe   typedef size_t            size_type;
311*f2ced752SOliver Tappe   typedef ptrdiff_t         difference_type;
312*f2ced752SOliver Tappe 
313*f2ced752SOliver Tappe   typedef _Slist_iterator<_Tp, _Tp&, _Tp*>             iterator;
314*f2ced752SOliver Tappe   typedef _Slist_iterator<_Tp, const _Tp&, const _Tp*> const_iterator;
315*f2ced752SOliver Tappe 
316*f2ced752SOliver Tappe   typedef typename _Base::allocator_type allocator_type;
get_allocator()317*f2ced752SOliver Tappe   allocator_type get_allocator() const { return _Base::get_allocator(); }
318*f2ced752SOliver Tappe 
319*f2ced752SOliver Tappe private:
320*f2ced752SOliver Tappe   typedef _Slist_node<_Tp>      _Node;
321*f2ced752SOliver Tappe   typedef _Slist_node_base      _Node_base;
322*f2ced752SOliver Tappe   typedef _Slist_iterator_base  _Iterator_base;
323*f2ced752SOliver Tappe 
_M_create_node(const value_type & __x)324*f2ced752SOliver Tappe   _Node* _M_create_node(const value_type& __x) {
325*f2ced752SOliver Tappe     _Node* __node = _M_get_node();
326*f2ced752SOliver Tappe     __STL_TRY {
327*f2ced752SOliver Tappe       construct(&__node->_M_data, __x);
328*f2ced752SOliver Tappe       __node->_M_next = 0;
329*f2ced752SOliver Tappe     }
330*f2ced752SOliver Tappe     __STL_UNWIND(_M_put_node(__node));
331*f2ced752SOliver Tappe     return __node;
332*f2ced752SOliver Tappe   }
333*f2ced752SOliver Tappe 
_M_create_node()334*f2ced752SOliver Tappe   _Node* _M_create_node() {
335*f2ced752SOliver Tappe     _Node* __node = _M_get_node();
336*f2ced752SOliver Tappe     __STL_TRY {
337*f2ced752SOliver Tappe       construct(&__node->_M_data);
338*f2ced752SOliver Tappe       __node->_M_next = 0;
339*f2ced752SOliver Tappe     }
340*f2ced752SOliver Tappe     __STL_UNWIND(_M_put_node(__node));
341*f2ced752SOliver Tappe     return __node;
342*f2ced752SOliver Tappe   }
343*f2ced752SOliver Tappe 
344*f2ced752SOliver Tappe private:
345*f2ced752SOliver Tappe #ifdef __STL_USE_NAMESPACES
346*f2ced752SOliver Tappe   using _Base::_M_get_node;
347*f2ced752SOliver Tappe   using _Base::_M_put_node;
348*f2ced752SOliver Tappe   using _Base::_M_erase_after;
349*f2ced752SOliver Tappe   using _Base::_M_head;
350*f2ced752SOliver Tappe #endif /* __STL_USE_NAMESPACES */
351*f2ced752SOliver Tappe 
352*f2ced752SOliver Tappe public:
_Base(__a)353*f2ced752SOliver Tappe   explicit slist(const allocator_type& __a = allocator_type()) : _Base(__a) {}
354*f2ced752SOliver Tappe 
355*f2ced752SOliver Tappe   slist(size_type __n, const value_type& __x,
_Base(__a)356*f2ced752SOliver Tappe         const allocator_type& __a =  allocator_type()) : _Base(__a)
357*f2ced752SOliver Tappe     { _M_insert_after_fill(&_M_head, __n, __x); }
358*f2ced752SOliver Tappe 
slist(size_type __n)359*f2ced752SOliver Tappe   explicit slist(size_type __n) : _Base(allocator_type())
360*f2ced752SOliver Tappe     { _M_insert_after_fill(&_M_head, __n, value_type()); }
361*f2ced752SOliver Tappe 
362*f2ced752SOliver Tappe #ifdef __STL_MEMBER_TEMPLATES
363*f2ced752SOliver Tappe   // We don't need any dispatching tricks here, because _M_insert_after_range
364*f2ced752SOliver Tappe   // already does them.
365*f2ced752SOliver Tappe   template <class _InputIterator>
366*f2ced752SOliver Tappe   slist(_InputIterator __first, _InputIterator __last,
_Base(__a)367*f2ced752SOliver Tappe         const allocator_type& __a =  allocator_type()) : _Base(__a)
368*f2ced752SOliver Tappe     { _M_insert_after_range(&_M_head, __first, __last); }
369*f2ced752SOliver Tappe 
370*f2ced752SOliver Tappe #else /* __STL_MEMBER_TEMPLATES */
371*f2ced752SOliver Tappe   slist(const_iterator __first, const_iterator __last,
_Base(__a)372*f2ced752SOliver Tappe         const allocator_type& __a =  allocator_type()) : _Base(__a)
373*f2ced752SOliver Tappe     { _M_insert_after_range(&_M_head, __first, __last); }
374*f2ced752SOliver Tappe   slist(const value_type* __first, const value_type* __last,
_Base(__a)375*f2ced752SOliver Tappe         const allocator_type& __a =  allocator_type()) : _Base(__a)
376*f2ced752SOliver Tappe     { _M_insert_after_range(&_M_head, __first, __last); }
377*f2ced752SOliver Tappe #endif /* __STL_MEMBER_TEMPLATES */
378*f2ced752SOliver Tappe 
slist(const slist & __x)379*f2ced752SOliver Tappe   slist(const slist& __x) : _Base(__x.get_allocator())
380*f2ced752SOliver Tappe     { _M_insert_after_range(&_M_head, __x.begin(), __x.end()); }
381*f2ced752SOliver Tappe 
382*f2ced752SOliver Tappe   slist& operator= (const slist& __x);
383*f2ced752SOliver Tappe 
~slist()384*f2ced752SOliver Tappe   ~slist() {}
385*f2ced752SOliver Tappe 
386*f2ced752SOliver Tappe public:
387*f2ced752SOliver Tappe   // assign(), a generalized assignment member function.  Two
388*f2ced752SOliver Tappe   // versions: one that takes a count, and one that takes a range.
389*f2ced752SOliver Tappe   // The range version is a member template, so we dispatch on whether
390*f2ced752SOliver Tappe   // or not the type is an integer.
391*f2ced752SOliver Tappe 
392*f2ced752SOliver Tappe   void assign(size_type __n, const _Tp& __val);
393*f2ced752SOliver Tappe 
394*f2ced752SOliver Tappe #ifdef __STL_MEMBER_TEMPLATES
395*f2ced752SOliver Tappe 
396*f2ced752SOliver Tappe   template <class _InputIterator>
assign(_InputIterator __first,_InputIterator __last)397*f2ced752SOliver Tappe   void assign(_InputIterator __first, _InputIterator __last) {
398*f2ced752SOliver Tappe     typedef typename _Is_integer<_InputIterator>::_Integral _Integral;
399*f2ced752SOliver Tappe     _M_assign_dispatch(__first, __last, _Integral());
400*f2ced752SOliver Tappe   }
401*f2ced752SOliver Tappe 
402*f2ced752SOliver Tappe   template <class _Integer>
_M_assign_dispatch(_Integer __n,_Integer __val,__true_type)403*f2ced752SOliver Tappe   void _M_assign_dispatch(_Integer __n, _Integer __val, __true_type)
404*f2ced752SOliver Tappe     { assign((size_type) __n, (_Tp) __val); }
405*f2ced752SOliver Tappe 
406*f2ced752SOliver Tappe   template <class _InputIterator>
407*f2ced752SOliver Tappe   void _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
408*f2ced752SOliver Tappe                           __false_type);
409*f2ced752SOliver Tappe 
410*f2ced752SOliver Tappe #endif /* __STL_MEMBER_TEMPLATES */
411*f2ced752SOliver Tappe 
412*f2ced752SOliver Tappe public:
413*f2ced752SOliver Tappe 
begin()414*f2ced752SOliver Tappe   iterator begin() { return iterator((_Node*)_M_head._M_next); }
begin()415*f2ced752SOliver Tappe   const_iterator begin() const
416*f2ced752SOliver Tappe     { return const_iterator((_Node*)_M_head._M_next);}
417*f2ced752SOliver Tappe 
end()418*f2ced752SOliver Tappe   iterator end() { return iterator(0); }
end()419*f2ced752SOliver Tappe   const_iterator end() const { return const_iterator(0); }
420*f2ced752SOliver Tappe 
size()421*f2ced752SOliver Tappe   size_type size() const { return __slist_size(_M_head._M_next); }
422*f2ced752SOliver Tappe 
max_size()423*f2ced752SOliver Tappe   size_type max_size() const { return size_type(-1); }
424*f2ced752SOliver Tappe 
empty()425*f2ced752SOliver Tappe   bool empty() const { return _M_head._M_next == 0; }
426*f2ced752SOliver Tappe 
swap(slist & __x)427*f2ced752SOliver Tappe   void swap(slist& __x) { __STD::swap(_M_head._M_next, __x._M_head._M_next); }
428*f2ced752SOliver Tappe 
429*f2ced752SOliver Tappe public:
430*f2ced752SOliver Tappe   friend bool operator== __STL_NULL_TMPL_ARGS (const slist<_Tp,_Alloc>& _SL1,
431*f2ced752SOliver Tappe                                                const slist<_Tp,_Alloc>& _SL2);
432*f2ced752SOliver Tappe 
433*f2ced752SOliver Tappe public:
434*f2ced752SOliver Tappe 
front()435*f2ced752SOliver Tappe   reference front() { return ((_Node*) _M_head._M_next)->_M_data; }
front()436*f2ced752SOliver Tappe   const_reference front() const
437*f2ced752SOliver Tappe     { return ((_Node*) _M_head._M_next)->_M_data; }
push_front(const value_type & __x)438*f2ced752SOliver Tappe   void push_front(const value_type& __x)   {
439*f2ced752SOliver Tappe     __slist_make_link(&_M_head, _M_create_node(__x));
440*f2ced752SOliver Tappe   }
push_front()441*f2ced752SOliver Tappe   void push_front() { __slist_make_link(&_M_head, _M_create_node());}
pop_front()442*f2ced752SOliver Tappe   void pop_front() {
443*f2ced752SOliver Tappe     _Node* __node = (_Node*) _M_head._M_next;
444*f2ced752SOliver Tappe     _M_head._M_next = __node->_M_next;
445*f2ced752SOliver Tappe     destroy(&__node->_M_data);
446*f2ced752SOliver Tappe     _M_put_node(__node);
447*f2ced752SOliver Tappe   }
448*f2ced752SOliver Tappe 
previous(const_iterator __pos)449*f2ced752SOliver Tappe   iterator previous(const_iterator __pos) {
450*f2ced752SOliver Tappe     return iterator((_Node*) __slist_previous(&_M_head, __pos._M_node));
451*f2ced752SOliver Tappe   }
previous(const_iterator __pos)452*f2ced752SOliver Tappe   const_iterator previous(const_iterator __pos) const {
453*f2ced752SOliver Tappe     return const_iterator((_Node*) __slist_previous(&_M_head, __pos._M_node));
454*f2ced752SOliver Tappe   }
455*f2ced752SOliver Tappe 
456*f2ced752SOliver Tappe private:
_M_insert_after(_Node_base * __pos,const value_type & __x)457*f2ced752SOliver Tappe   _Node* _M_insert_after(_Node_base* __pos, const value_type& __x) {
458*f2ced752SOliver Tappe     return (_Node*) (__slist_make_link(__pos, _M_create_node(__x)));
459*f2ced752SOliver Tappe   }
460*f2ced752SOliver Tappe 
_M_insert_after(_Node_base * __pos)461*f2ced752SOliver Tappe   _Node* _M_insert_after(_Node_base* __pos) {
462*f2ced752SOliver Tappe     return (_Node*) (__slist_make_link(__pos, _M_create_node()));
463*f2ced752SOliver Tappe   }
464*f2ced752SOliver Tappe 
_M_insert_after_fill(_Node_base * __pos,size_type __n,const value_type & __x)465*f2ced752SOliver Tappe   void _M_insert_after_fill(_Node_base* __pos,
466*f2ced752SOliver Tappe                             size_type __n, const value_type& __x) {
467*f2ced752SOliver Tappe     for (size_type __i = 0; __i < __n; ++__i)
468*f2ced752SOliver Tappe       __pos = __slist_make_link(__pos, _M_create_node(__x));
469*f2ced752SOliver Tappe   }
470*f2ced752SOliver Tappe 
471*f2ced752SOliver Tappe #ifdef __STL_MEMBER_TEMPLATES
472*f2ced752SOliver Tappe 
473*f2ced752SOliver Tappe   // Check whether it's an integral type.  If so, it's not an iterator.
474*f2ced752SOliver Tappe   template <class _InIter>
_M_insert_after_range(_Node_base * __pos,_InIter __first,_InIter __last)475*f2ced752SOliver Tappe   void _M_insert_after_range(_Node_base* __pos,
476*f2ced752SOliver Tappe                              _InIter __first, _InIter __last) {
477*f2ced752SOliver Tappe     typedef typename _Is_integer<_InIter>::_Integral _Integral;
478*f2ced752SOliver Tappe     _M_insert_after_range(__pos, __first, __last, _Integral());
479*f2ced752SOliver Tappe   }
480*f2ced752SOliver Tappe 
481*f2ced752SOliver Tappe   template <class _Integer>
_M_insert_after_range(_Node_base * __pos,_Integer __n,_Integer __x,__true_type)482*f2ced752SOliver Tappe   void _M_insert_after_range(_Node_base* __pos, _Integer __n, _Integer __x,
483*f2ced752SOliver Tappe                              __true_type) {
484*f2ced752SOliver Tappe     _M_insert_after_fill(__pos, __n, __x);
485*f2ced752SOliver Tappe   }
486*f2ced752SOliver Tappe 
487*f2ced752SOliver Tappe   template <class _InIter>
_M_insert_after_range(_Node_base * __pos,_InIter __first,_InIter __last,__false_type)488*f2ced752SOliver Tappe   void _M_insert_after_range(_Node_base* __pos,
489*f2ced752SOliver Tappe                              _InIter __first, _InIter __last,
490*f2ced752SOliver Tappe                              __false_type) {
491*f2ced752SOliver Tappe     while (__first != __last) {
492*f2ced752SOliver Tappe       __pos = __slist_make_link(__pos, _M_create_node(*__first));
493*f2ced752SOliver Tappe       ++__first;
494*f2ced752SOliver Tappe     }
495*f2ced752SOliver Tappe   }
496*f2ced752SOliver Tappe 
497*f2ced752SOliver Tappe #else /* __STL_MEMBER_TEMPLATES */
498*f2ced752SOliver Tappe 
_M_insert_after_range(_Node_base * __pos,const_iterator __first,const_iterator __last)499*f2ced752SOliver Tappe   void _M_insert_after_range(_Node_base* __pos,
500*f2ced752SOliver Tappe                              const_iterator __first, const_iterator __last) {
501*f2ced752SOliver Tappe     while (__first != __last) {
502*f2ced752SOliver Tappe       __pos = __slist_make_link(__pos, _M_create_node(*__first));
503*f2ced752SOliver Tappe       ++__first;
504*f2ced752SOliver Tappe     }
505*f2ced752SOliver Tappe   }
_M_insert_after_range(_Node_base * __pos,const value_type * __first,const value_type * __last)506*f2ced752SOliver Tappe   void _M_insert_after_range(_Node_base* __pos,
507*f2ced752SOliver Tappe                              const value_type* __first,
508*f2ced752SOliver Tappe                              const value_type* __last) {
509*f2ced752SOliver Tappe     while (__first != __last) {
510*f2ced752SOliver Tappe       __pos = __slist_make_link(__pos, _M_create_node(*__first));
511*f2ced752SOliver Tappe       ++__first;
512*f2ced752SOliver Tappe     }
513*f2ced752SOliver Tappe   }
514*f2ced752SOliver Tappe 
515*f2ced752SOliver Tappe #endif /* __STL_MEMBER_TEMPLATES */
516*f2ced752SOliver Tappe 
517*f2ced752SOliver Tappe public:
518*f2ced752SOliver Tappe 
insert_after(iterator __pos,const value_type & __x)519*f2ced752SOliver Tappe   iterator insert_after(iterator __pos, const value_type& __x) {
520*f2ced752SOliver Tappe     return iterator(_M_insert_after(__pos._M_node, __x));
521*f2ced752SOliver Tappe   }
522*f2ced752SOliver Tappe 
insert_after(iterator __pos)523*f2ced752SOliver Tappe   iterator insert_after(iterator __pos) {
524*f2ced752SOliver Tappe     return insert_after(__pos, value_type());
525*f2ced752SOliver Tappe   }
526*f2ced752SOliver Tappe 
insert_after(iterator __pos,size_type __n,const value_type & __x)527*f2ced752SOliver Tappe   void insert_after(iterator __pos, size_type __n, const value_type& __x) {
528*f2ced752SOliver Tappe     _M_insert_after_fill(__pos._M_node, __n, __x);
529*f2ced752SOliver Tappe   }
530*f2ced752SOliver Tappe 
531*f2ced752SOliver Tappe #ifdef __STL_MEMBER_TEMPLATES
532*f2ced752SOliver Tappe 
533*f2ced752SOliver Tappe   // We don't need any dispatching tricks here, because _M_insert_after_range
534*f2ced752SOliver Tappe   // already does them.
535*f2ced752SOliver Tappe   template <class _InIter>
insert_after(iterator __pos,_InIter __first,_InIter __last)536*f2ced752SOliver Tappe   void insert_after(iterator __pos, _InIter __first, _InIter __last) {
537*f2ced752SOliver Tappe     _M_insert_after_range(__pos._M_node, __first, __last);
538*f2ced752SOliver Tappe   }
539*f2ced752SOliver Tappe 
540*f2ced752SOliver Tappe #else /* __STL_MEMBER_TEMPLATES */
541*f2ced752SOliver Tappe 
insert_after(iterator __pos,const_iterator __first,const_iterator __last)542*f2ced752SOliver Tappe   void insert_after(iterator __pos,
543*f2ced752SOliver Tappe                     const_iterator __first, const_iterator __last) {
544*f2ced752SOliver Tappe     _M_insert_after_range(__pos._M_node, __first, __last);
545*f2ced752SOliver Tappe   }
insert_after(iterator __pos,const value_type * __first,const value_type * __last)546*f2ced752SOliver Tappe   void insert_after(iterator __pos,
547*f2ced752SOliver Tappe                     const value_type* __first, const value_type* __last) {
548*f2ced752SOliver Tappe     _M_insert_after_range(__pos._M_node, __first, __last);
549*f2ced752SOliver Tappe   }
550*f2ced752SOliver Tappe 
551*f2ced752SOliver Tappe #endif /* __STL_MEMBER_TEMPLATES */
552*f2ced752SOliver Tappe 
insert(iterator __pos,const value_type & __x)553*f2ced752SOliver Tappe   iterator insert(iterator __pos, const value_type& __x) {
554*f2ced752SOliver Tappe     return iterator(_M_insert_after(__slist_previous(&_M_head, __pos._M_node),
555*f2ced752SOliver Tappe                     __x));
556*f2ced752SOliver Tappe   }
557*f2ced752SOliver Tappe 
insert(iterator __pos)558*f2ced752SOliver Tappe   iterator insert(iterator __pos) {
559*f2ced752SOliver Tappe     return iterator(_M_insert_after(__slist_previous(&_M_head, __pos._M_node),
560*f2ced752SOliver Tappe                                     value_type()));
561*f2ced752SOliver Tappe   }
562*f2ced752SOliver Tappe 
insert(iterator __pos,size_type __n,const value_type & __x)563*f2ced752SOliver Tappe   void insert(iterator __pos, size_type __n, const value_type& __x) {
564*f2ced752SOliver Tappe     _M_insert_after_fill(__slist_previous(&_M_head, __pos._M_node), __n, __x);
565*f2ced752SOliver Tappe   }
566*f2ced752SOliver Tappe 
567*f2ced752SOliver Tappe #ifdef __STL_MEMBER_TEMPLATES
568*f2ced752SOliver Tappe 
569*f2ced752SOliver Tappe   // We don't need any dispatching tricks here, because _M_insert_after_range
570*f2ced752SOliver Tappe   // already does them.
571*f2ced752SOliver Tappe   template <class _InIter>
insert(iterator __pos,_InIter __first,_InIter __last)572*f2ced752SOliver Tappe   void insert(iterator __pos, _InIter __first, _InIter __last) {
573*f2ced752SOliver Tappe     _M_insert_after_range(__slist_previous(&_M_head, __pos._M_node),
574*f2ced752SOliver Tappe                           __first, __last);
575*f2ced752SOliver Tappe   }
576*f2ced752SOliver Tappe 
577*f2ced752SOliver Tappe #else /* __STL_MEMBER_TEMPLATES */
578*f2ced752SOliver Tappe 
insert(iterator __pos,const_iterator __first,const_iterator __last)579*f2ced752SOliver Tappe   void insert(iterator __pos, const_iterator __first, const_iterator __last) {
580*f2ced752SOliver Tappe     _M_insert_after_range(__slist_previous(&_M_head, __pos._M_node),
581*f2ced752SOliver Tappe                           __first, __last);
582*f2ced752SOliver Tappe   }
insert(iterator __pos,const value_type * __first,const value_type * __last)583*f2ced752SOliver Tappe   void insert(iterator __pos, const value_type* __first,
584*f2ced752SOliver Tappe                               const value_type* __last) {
585*f2ced752SOliver Tappe     _M_insert_after_range(__slist_previous(&_M_head, __pos._M_node),
586*f2ced752SOliver Tappe                           __first, __last);
587*f2ced752SOliver Tappe   }
588*f2ced752SOliver Tappe 
589*f2ced752SOliver Tappe #endif /* __STL_MEMBER_TEMPLATES */
590*f2ced752SOliver Tappe 
591*f2ced752SOliver Tappe 
592*f2ced752SOliver Tappe public:
erase_after(iterator __pos)593*f2ced752SOliver Tappe   iterator erase_after(iterator __pos) {
594*f2ced752SOliver Tappe     return iterator((_Node*) _M_erase_after(__pos._M_node));
595*f2ced752SOliver Tappe   }
erase_after(iterator __before_first,iterator __last)596*f2ced752SOliver Tappe   iterator erase_after(iterator __before_first, iterator __last) {
597*f2ced752SOliver Tappe     return iterator((_Node*) _M_erase_after(__before_first._M_node,
598*f2ced752SOliver Tappe                                             __last._M_node));
599*f2ced752SOliver Tappe   }
600*f2ced752SOliver Tappe 
erase(iterator __pos)601*f2ced752SOliver Tappe   iterator erase(iterator __pos) {
602*f2ced752SOliver Tappe     return (_Node*) _M_erase_after(__slist_previous(&_M_head,
603*f2ced752SOliver Tappe                                                     __pos._M_node));
604*f2ced752SOliver Tappe   }
erase(iterator __first,iterator __last)605*f2ced752SOliver Tappe   iterator erase(iterator __first, iterator __last) {
606*f2ced752SOliver Tappe     return (_Node*) _M_erase_after(
607*f2ced752SOliver Tappe       __slist_previous(&_M_head, __first._M_node), __last._M_node);
608*f2ced752SOliver Tappe   }
609*f2ced752SOliver Tappe 
610*f2ced752SOliver Tappe   void resize(size_type new_size, const _Tp& __x);
resize(size_type new_size)611*f2ced752SOliver Tappe   void resize(size_type new_size) { resize(new_size, _Tp()); }
clear()612*f2ced752SOliver Tappe   void clear() { _M_erase_after(&_M_head, 0); }
613*f2ced752SOliver Tappe 
614*f2ced752SOliver Tappe public:
615*f2ced752SOliver Tappe   // Moves the range [__before_first + 1, __before_last + 1) to *this,
616*f2ced752SOliver Tappe   //  inserting it immediately after __pos.  This is constant time.
splice_after(iterator __pos,iterator __before_first,iterator __before_last)617*f2ced752SOliver Tappe   void splice_after(iterator __pos,
618*f2ced752SOliver Tappe                     iterator __before_first, iterator __before_last)
619*f2ced752SOliver Tappe   {
620*f2ced752SOliver Tappe     if (__before_first != __before_last)
621*f2ced752SOliver Tappe       __slist_splice_after(__pos._M_node, __before_first._M_node,
622*f2ced752SOliver Tappe                            __before_last._M_node);
623*f2ced752SOliver Tappe   }
624*f2ced752SOliver Tappe 
625*f2ced752SOliver Tappe   // Moves the element that follows __prev to *this, inserting it immediately
626*f2ced752SOliver Tappe   //  after __pos.  This is constant time.
splice_after(iterator __pos,iterator __prev)627*f2ced752SOliver Tappe   void splice_after(iterator __pos, iterator __prev)
628*f2ced752SOliver Tappe   {
629*f2ced752SOliver Tappe     __slist_splice_after(__pos._M_node,
630*f2ced752SOliver Tappe                          __prev._M_node, __prev._M_node->_M_next);
631*f2ced752SOliver Tappe   }
632*f2ced752SOliver Tappe 
633*f2ced752SOliver Tappe 
634*f2ced752SOliver Tappe   // Linear in distance(begin(), __pos), and linear in __x.size().
splice(iterator __pos,slist & __x)635*f2ced752SOliver Tappe   void splice(iterator __pos, slist& __x) {
636*f2ced752SOliver Tappe     if (__x._M_head._M_next)
637*f2ced752SOliver Tappe       __slist_splice_after(__slist_previous(&_M_head, __pos._M_node),
638*f2ced752SOliver Tappe                            &__x._M_head, __slist_previous(&__x._M_head, 0));
639*f2ced752SOliver Tappe   }
640*f2ced752SOliver Tappe 
641*f2ced752SOliver Tappe   // Linear in distance(begin(), __pos), and in distance(__x.begin(), __i).
splice(iterator __pos,slist & __x,iterator __i)642*f2ced752SOliver Tappe   void splice(iterator __pos, slist& __x, iterator __i) {
643*f2ced752SOliver Tappe     __slist_splice_after(__slist_previous(&_M_head, __pos._M_node),
644*f2ced752SOliver Tappe                          __slist_previous(&__x._M_head, __i._M_node),
645*f2ced752SOliver Tappe                          __i._M_node);
646*f2ced752SOliver Tappe   }
647*f2ced752SOliver Tappe 
648*f2ced752SOliver Tappe   // Linear in distance(begin(), __pos), in distance(__x.begin(), __first),
649*f2ced752SOliver Tappe   // and in distance(__first, __last).
splice(iterator __pos,slist & __x,iterator __first,iterator __last)650*f2ced752SOliver Tappe   void splice(iterator __pos, slist& __x, iterator __first, iterator __last)
651*f2ced752SOliver Tappe   {
652*f2ced752SOliver Tappe     if (__first != __last)
653*f2ced752SOliver Tappe       __slist_splice_after(__slist_previous(&_M_head, __pos._M_node),
654*f2ced752SOliver Tappe                            __slist_previous(&__x._M_head, __first._M_node),
655*f2ced752SOliver Tappe                            __slist_previous(__first._M_node, __last._M_node));
656*f2ced752SOliver Tappe   }
657*f2ced752SOliver Tappe 
658*f2ced752SOliver Tappe public:
reverse()659*f2ced752SOliver Tappe   void reverse() {
660*f2ced752SOliver Tappe     if (_M_head._M_next)
661*f2ced752SOliver Tappe       _M_head._M_next = __slist_reverse(_M_head._M_next);
662*f2ced752SOliver Tappe   }
663*f2ced752SOliver Tappe 
664*f2ced752SOliver Tappe   void remove(const _Tp& __val);
665*f2ced752SOliver Tappe   void unique();
666*f2ced752SOliver Tappe   void merge(slist& __x);
667*f2ced752SOliver Tappe   void sort();
668*f2ced752SOliver Tappe 
669*f2ced752SOliver Tappe #ifdef __STL_MEMBER_TEMPLATES
670*f2ced752SOliver Tappe   template <class _Predicate>
671*f2ced752SOliver Tappe   void remove_if(_Predicate __pred);
672*f2ced752SOliver Tappe 
673*f2ced752SOliver Tappe   template <class _BinaryPredicate>
674*f2ced752SOliver Tappe   void unique(_BinaryPredicate __pred);
675*f2ced752SOliver Tappe 
676*f2ced752SOliver Tappe   template <class _StrictWeakOrdering>
677*f2ced752SOliver Tappe   void merge(slist&, _StrictWeakOrdering);
678*f2ced752SOliver Tappe 
679*f2ced752SOliver Tappe   template <class _StrictWeakOrdering>
680*f2ced752SOliver Tappe   void sort(_StrictWeakOrdering __comp);
681*f2ced752SOliver Tappe #endif /* __STL_MEMBER_TEMPLATES */
682*f2ced752SOliver Tappe };
683*f2ced752SOliver Tappe 
684*f2ced752SOliver Tappe template <class _Tp, class _Alloc>
685*f2ced752SOliver Tappe slist<_Tp,_Alloc>& slist<_Tp,_Alloc>::operator=(const slist<_Tp,_Alloc>& __x)
686*f2ced752SOliver Tappe {
687*f2ced752SOliver Tappe   if (&__x != this) {
688*f2ced752SOliver Tappe     _Node_base* __p1 = &_M_head;
689*f2ced752SOliver Tappe     _Node* __n1 = (_Node*) _M_head._M_next;
690*f2ced752SOliver Tappe     const _Node* __n2 = (const _Node*) __x._M_head._M_next;
691*f2ced752SOliver Tappe     while (__n1 && __n2) {
692*f2ced752SOliver Tappe       __n1->_M_data = __n2->_M_data;
693*f2ced752SOliver Tappe       __p1 = __n1;
694*f2ced752SOliver Tappe       __n1 = (_Node*) __n1->_M_next;
695*f2ced752SOliver Tappe       __n2 = (const _Node*) __n2->_M_next;
696*f2ced752SOliver Tappe     }
697*f2ced752SOliver Tappe     if (__n2 == 0)
698*f2ced752SOliver Tappe       _M_erase_after(__p1, 0);
699*f2ced752SOliver Tappe     else
700*f2ced752SOliver Tappe       _M_insert_after_range(__p1, const_iterator((_Node*)__n2),
701*f2ced752SOliver Tappe                                   const_iterator(0));
702*f2ced752SOliver Tappe   }
703*f2ced752SOliver Tappe   return *this;
704*f2ced752SOliver Tappe }
705*f2ced752SOliver Tappe 
706*f2ced752SOliver Tappe template <class _Tp, class _Alloc>
assign(size_type __n,const _Tp & __val)707*f2ced752SOliver Tappe void slist<_Tp, _Alloc>::assign(size_type __n, const _Tp& __val) {
708*f2ced752SOliver Tappe   _Node_base* __prev = &_M_head;
709*f2ced752SOliver Tappe   _Node* __node = (_Node*) _M_head._M_next;
710*f2ced752SOliver Tappe   for ( ; __node != 0 && __n > 0 ; --__n) {
711*f2ced752SOliver Tappe     __node->_M_data = __val;
712*f2ced752SOliver Tappe     __prev = __node;
713*f2ced752SOliver Tappe     __node = (_Node*) __node->_M_next;
714*f2ced752SOliver Tappe   }
715*f2ced752SOliver Tappe   if (__n > 0)
716*f2ced752SOliver Tappe     _M_insert_after_fill(__prev, __n, __val);
717*f2ced752SOliver Tappe   else
718*f2ced752SOliver Tappe     _M_erase_after(__prev, 0);
719*f2ced752SOliver Tappe }
720*f2ced752SOliver Tappe 
721*f2ced752SOliver Tappe #ifdef __STL_MEMBER_TEMPLATES
722*f2ced752SOliver Tappe 
723*f2ced752SOliver Tappe template <class _Tp, class _Alloc> template <class _InputIter>
724*f2ced752SOliver Tappe void
_M_assign_dispatch(_InputIter __first,_InputIter __last,__false_type)725*f2ced752SOliver Tappe slist<_Tp, _Alloc>::_M_assign_dispatch(_InputIter __first, _InputIter __last,
726*f2ced752SOliver Tappe                                        __false_type)
727*f2ced752SOliver Tappe {
728*f2ced752SOliver Tappe   _Node_base* __prev = &_M_head;
729*f2ced752SOliver Tappe   _Node* __node = (_Node*) _M_head._M_next;
730*f2ced752SOliver Tappe   while (__node != 0 && __first != __last) {
731*f2ced752SOliver Tappe     __node->_M_data = *__first;
732*f2ced752SOliver Tappe     __prev = __node;
733*f2ced752SOliver Tappe     __node = (_Node*) __node->_M_next;
734*f2ced752SOliver Tappe     ++__first;
735*f2ced752SOliver Tappe   }
736*f2ced752SOliver Tappe   if (__first != __last)
737*f2ced752SOliver Tappe     _M_insert_after_range(__prev, __first, __last);
738*f2ced752SOliver Tappe   else
739*f2ced752SOliver Tappe     _M_erase_after(__prev, 0);
740*f2ced752SOliver Tappe }
741*f2ced752SOliver Tappe 
742*f2ced752SOliver Tappe #endif /* __STL_MEMBER_TEMPLATES */
743*f2ced752SOliver Tappe 
744*f2ced752SOliver Tappe template <class _Tp, class _Alloc>
745*f2ced752SOliver Tappe inline bool
746*f2ced752SOliver Tappe operator==(const slist<_Tp,_Alloc>& _SL1, const slist<_Tp,_Alloc>& _SL2)
747*f2ced752SOliver Tappe {
748*f2ced752SOliver Tappe   typedef typename slist<_Tp,_Alloc>::_Node _Node;
749*f2ced752SOliver Tappe   _Node* __n1 = (_Node*) _SL1._M_head._M_next;
750*f2ced752SOliver Tappe   _Node* __n2 = (_Node*) _SL2._M_head._M_next;
751*f2ced752SOliver Tappe   while (__n1 && __n2 && __n1->_M_data == __n2->_M_data) {
752*f2ced752SOliver Tappe     __n1 = (_Node*) __n1->_M_next;
753*f2ced752SOliver Tappe     __n2 = (_Node*) __n2->_M_next;
754*f2ced752SOliver Tappe   }
755*f2ced752SOliver Tappe   return __n1 == 0 && __n2 == 0;
756*f2ced752SOliver Tappe }
757*f2ced752SOliver Tappe 
758*f2ced752SOliver Tappe template <class _Tp, class _Alloc>
759*f2ced752SOliver Tappe inline bool operator<(const slist<_Tp,_Alloc>& _SL1,
760*f2ced752SOliver Tappe                       const slist<_Tp,_Alloc>& _SL2)
761*f2ced752SOliver Tappe {
762*f2ced752SOliver Tappe   return lexicographical_compare(_SL1.begin(), _SL1.end(),
763*f2ced752SOliver Tappe                                  _SL2.begin(), _SL2.end());
764*f2ced752SOliver Tappe }
765*f2ced752SOliver Tappe 
766*f2ced752SOliver Tappe #ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
767*f2ced752SOliver Tappe 
768*f2ced752SOliver Tappe template <class _Tp, class _Alloc>
swap(slist<_Tp,_Alloc> & __x,slist<_Tp,_Alloc> & __y)769*f2ced752SOliver Tappe inline void swap(slist<_Tp,_Alloc>& __x, slist<_Tp,_Alloc>& __y) {
770*f2ced752SOliver Tappe   __x.swap(__y);
771*f2ced752SOliver Tappe }
772*f2ced752SOliver Tappe 
773*f2ced752SOliver Tappe #endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
774*f2ced752SOliver Tappe 
775*f2ced752SOliver Tappe 
776*f2ced752SOliver Tappe template <class _Tp, class _Alloc>
resize(size_type __len,const _Tp & __x)777*f2ced752SOliver Tappe void slist<_Tp,_Alloc>::resize(size_type __len, const _Tp& __x)
778*f2ced752SOliver Tappe {
779*f2ced752SOliver Tappe   _Node_base* __cur = &_M_head;
780*f2ced752SOliver Tappe   while (__cur->_M_next != 0 && __len > 0) {
781*f2ced752SOliver Tappe     --__len;
782*f2ced752SOliver Tappe     __cur = __cur->_M_next;
783*f2ced752SOliver Tappe   }
784*f2ced752SOliver Tappe   if (__cur->_M_next)
785*f2ced752SOliver Tappe     _M_erase_after(__cur, 0);
786*f2ced752SOliver Tappe   else
787*f2ced752SOliver Tappe     _M_insert_after_fill(__cur, __len, __x);
788*f2ced752SOliver Tappe }
789*f2ced752SOliver Tappe 
790*f2ced752SOliver Tappe template <class _Tp, class _Alloc>
remove(const _Tp & __val)791*f2ced752SOliver Tappe void slist<_Tp,_Alloc>::remove(const _Tp& __val)
792*f2ced752SOliver Tappe {
793*f2ced752SOliver Tappe   _Node_base* __cur = &_M_head;
794*f2ced752SOliver Tappe   while (__cur && __cur->_M_next) {
795*f2ced752SOliver Tappe     if (((_Node*) __cur->_M_next)->_M_data == __val)
796*f2ced752SOliver Tappe       _M_erase_after(__cur);
797*f2ced752SOliver Tappe     else
798*f2ced752SOliver Tappe       __cur = __cur->_M_next;
799*f2ced752SOliver Tappe   }
800*f2ced752SOliver Tappe }
801*f2ced752SOliver Tappe 
802*f2ced752SOliver Tappe template <class _Tp, class _Alloc>
unique()803*f2ced752SOliver Tappe void slist<_Tp,_Alloc>::unique()
804*f2ced752SOliver Tappe {
805*f2ced752SOliver Tappe   _Node_base* __cur = _M_head._M_next;
806*f2ced752SOliver Tappe   if (__cur) {
807*f2ced752SOliver Tappe     while (__cur->_M_next) {
808*f2ced752SOliver Tappe       if (((_Node*)__cur)->_M_data ==
809*f2ced752SOliver Tappe           ((_Node*)(__cur->_M_next))->_M_data)
810*f2ced752SOliver Tappe         _M_erase_after(__cur);
811*f2ced752SOliver Tappe       else
812*f2ced752SOliver Tappe         __cur = __cur->_M_next;
813*f2ced752SOliver Tappe     }
814*f2ced752SOliver Tappe   }
815*f2ced752SOliver Tappe }
816*f2ced752SOliver Tappe 
817*f2ced752SOliver Tappe template <class _Tp, class _Alloc>
merge(slist<_Tp,_Alloc> & __x)818*f2ced752SOliver Tappe void slist<_Tp,_Alloc>::merge(slist<_Tp,_Alloc>& __x)
819*f2ced752SOliver Tappe {
820*f2ced752SOliver Tappe   _Node_base* __n1 = &_M_head;
821*f2ced752SOliver Tappe   while (__n1->_M_next && __x._M_head._M_next) {
822*f2ced752SOliver Tappe     if (((_Node*) __x._M_head._M_next)->_M_data <
823*f2ced752SOliver Tappe         ((_Node*)       __n1->_M_next)->_M_data)
824*f2ced752SOliver Tappe       __slist_splice_after(__n1, &__x._M_head, __x._M_head._M_next);
825*f2ced752SOliver Tappe     __n1 = __n1->_M_next;
826*f2ced752SOliver Tappe   }
827*f2ced752SOliver Tappe   if (__x._M_head._M_next) {
828*f2ced752SOliver Tappe     __n1->_M_next = __x._M_head._M_next;
829*f2ced752SOliver Tappe     __x._M_head._M_next = 0;
830*f2ced752SOliver Tappe   }
831*f2ced752SOliver Tappe }
832*f2ced752SOliver Tappe 
833*f2ced752SOliver Tappe template <class _Tp, class _Alloc>
sort()834*f2ced752SOliver Tappe void slist<_Tp,_Alloc>::sort()
835*f2ced752SOliver Tappe {
836*f2ced752SOliver Tappe   if (_M_head._M_next && _M_head._M_next->_M_next) {
837*f2ced752SOliver Tappe     slist __carry;
838*f2ced752SOliver Tappe     slist __counter[64];
839*f2ced752SOliver Tappe     int __fill = 0;
840*f2ced752SOliver Tappe     while (!empty()) {
841*f2ced752SOliver Tappe       __slist_splice_after(&__carry._M_head, &_M_head, _M_head._M_next);
842*f2ced752SOliver Tappe       int __i = 0;
843*f2ced752SOliver Tappe       while (__i < __fill && !__counter[__i].empty()) {
844*f2ced752SOliver Tappe         __counter[__i].merge(__carry);
845*f2ced752SOliver Tappe         __carry.swap(__counter[__i]);
846*f2ced752SOliver Tappe         ++__i;
847*f2ced752SOliver Tappe       }
848*f2ced752SOliver Tappe       __carry.swap(__counter[__i]);
849*f2ced752SOliver Tappe       if (__i == __fill)
850*f2ced752SOliver Tappe         ++__fill;
851*f2ced752SOliver Tappe     }
852*f2ced752SOliver Tappe 
853*f2ced752SOliver Tappe     for (int __i = 1; __i < __fill; ++__i)
854*f2ced752SOliver Tappe       __counter[__i].merge(__counter[__i-1]);
855*f2ced752SOliver Tappe     this->swap(__counter[__fill-1]);
856*f2ced752SOliver Tappe   }
857*f2ced752SOliver Tappe }
858*f2ced752SOliver Tappe 
859*f2ced752SOliver Tappe #ifdef __STL_MEMBER_TEMPLATES
860*f2ced752SOliver Tappe 
861*f2ced752SOliver Tappe template <class _Tp, class _Alloc>
862*f2ced752SOliver Tappe template <class _Predicate>
remove_if(_Predicate __pred)863*f2ced752SOliver Tappe void slist<_Tp,_Alloc>::remove_if(_Predicate __pred)
864*f2ced752SOliver Tappe {
865*f2ced752SOliver Tappe   _Node_base* __cur = &_M_head;
866*f2ced752SOliver Tappe   while (__cur->_M_next) {
867*f2ced752SOliver Tappe     if (__pred(((_Node*) __cur->_M_next)->_M_data))
868*f2ced752SOliver Tappe       _M_erase_after(__cur);
869*f2ced752SOliver Tappe     else
870*f2ced752SOliver Tappe       __cur = __cur->_M_next;
871*f2ced752SOliver Tappe   }
872*f2ced752SOliver Tappe }
873*f2ced752SOliver Tappe 
874*f2ced752SOliver Tappe template <class _Tp, class _Alloc> template <class _BinaryPredicate>
unique(_BinaryPredicate __pred)875*f2ced752SOliver Tappe void slist<_Tp,_Alloc>::unique(_BinaryPredicate __pred)
876*f2ced752SOliver Tappe {
877*f2ced752SOliver Tappe   _Node* __cur = (_Node*) _M_head._M_next;
878*f2ced752SOliver Tappe   if (__cur) {
879*f2ced752SOliver Tappe     while (__cur->_M_next) {
880*f2ced752SOliver Tappe       if (__pred(((_Node*)__cur)->_M_data,
881*f2ced752SOliver Tappe                  ((_Node*)(__cur->_M_next))->_M_data))
882*f2ced752SOliver Tappe         _M_erase_after(__cur);
883*f2ced752SOliver Tappe       else
884*f2ced752SOliver Tappe         __cur = (_Node*) __cur->_M_next;
885*f2ced752SOliver Tappe     }
886*f2ced752SOliver Tappe   }
887*f2ced752SOliver Tappe }
888*f2ced752SOliver Tappe 
889*f2ced752SOliver Tappe template <class _Tp, class _Alloc> template <class _StrictWeakOrdering>
merge(slist<_Tp,_Alloc> & __x,_StrictWeakOrdering __comp)890*f2ced752SOliver Tappe void slist<_Tp,_Alloc>::merge(slist<_Tp,_Alloc>& __x,
891*f2ced752SOliver Tappe                               _StrictWeakOrdering __comp)
892*f2ced752SOliver Tappe {
893*f2ced752SOliver Tappe   _Node_base* __n1 = &_M_head;
894*f2ced752SOliver Tappe   while (__n1->_M_next && __x._M_head._M_next) {
895*f2ced752SOliver Tappe     if (__comp(((_Node*) __x._M_head._M_next)->_M_data,
896*f2ced752SOliver Tappe                ((_Node*)       __n1->_M_next)->_M_data))
897*f2ced752SOliver Tappe       __slist_splice_after(__n1, &__x._M_head, __x._M_head._M_next);
898*f2ced752SOliver Tappe     __n1 = __n1->_M_next;
899*f2ced752SOliver Tappe   }
900*f2ced752SOliver Tappe   if (__x._M_head._M_next) {
901*f2ced752SOliver Tappe     __n1->_M_next = __x._M_head._M_next;
902*f2ced752SOliver Tappe     __x._M_head._M_next = 0;
903*f2ced752SOliver Tappe   }
904*f2ced752SOliver Tappe }
905*f2ced752SOliver Tappe 
906*f2ced752SOliver Tappe template <class _Tp, class _Alloc> template <class _StrictWeakOrdering>
sort(_StrictWeakOrdering __comp)907*f2ced752SOliver Tappe void slist<_Tp,_Alloc>::sort(_StrictWeakOrdering __comp)
908*f2ced752SOliver Tappe {
909*f2ced752SOliver Tappe   if (_M_head._M_next && _M_head._M_next->_M_next) {
910*f2ced752SOliver Tappe     slist __carry;
911*f2ced752SOliver Tappe     slist __counter[64];
912*f2ced752SOliver Tappe     int __fill = 0;
913*f2ced752SOliver Tappe     while (!empty()) {
914*f2ced752SOliver Tappe       __slist_splice_after(&__carry._M_head, &_M_head, _M_head._M_next);
915*f2ced752SOliver Tappe       int __i = 0;
916*f2ced752SOliver Tappe       while (__i < __fill && !__counter[__i].empty()) {
917*f2ced752SOliver Tappe         __counter[__i].merge(__carry, __comp);
918*f2ced752SOliver Tappe         __carry.swap(__counter[__i]);
919*f2ced752SOliver Tappe         ++__i;
920*f2ced752SOliver Tappe       }
921*f2ced752SOliver Tappe       __carry.swap(__counter[__i]);
922*f2ced752SOliver Tappe       if (__i == __fill)
923*f2ced752SOliver Tappe         ++__fill;
924*f2ced752SOliver Tappe     }
925*f2ced752SOliver Tappe 
926*f2ced752SOliver Tappe     for (int __i = 1; __i < __fill; ++__i)
927*f2ced752SOliver Tappe       __counter[__i].merge(__counter[__i-1], __comp);
928*f2ced752SOliver Tappe     this->swap(__counter[__fill-1]);
929*f2ced752SOliver Tappe   }
930*f2ced752SOliver Tappe }
931*f2ced752SOliver Tappe 
932*f2ced752SOliver Tappe #endif /* __STL_MEMBER_TEMPLATES */
933*f2ced752SOliver Tappe 
934*f2ced752SOliver Tappe #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
935*f2ced752SOliver Tappe #pragma reset woff 1174
936*f2ced752SOliver Tappe #pragma reset woff 1375
937*f2ced752SOliver Tappe #endif
938*f2ced752SOliver Tappe 
939*f2ced752SOliver Tappe __STL_END_NAMESPACE
940*f2ced752SOliver Tappe 
941*f2ced752SOliver Tappe #endif /* __SGI_STL_INTERNAL_SLIST_H */
942*f2ced752SOliver Tappe 
943*f2ced752SOliver Tappe // Local Variables:
944*f2ced752SOliver Tappe // mode:C++
945*f2ced752SOliver Tappe // End:
946