williamr@4
|
1 |
/*
|
williamr@4
|
2 |
*
|
williamr@4
|
3 |
* Copyright (c) 1996,1997
|
williamr@4
|
4 |
* Silicon Graphics Computer Systems, Inc.
|
williamr@4
|
5 |
*
|
williamr@4
|
6 |
* Copyright (c) 1997
|
williamr@4
|
7 |
* Moscow Center for SPARC Technology
|
williamr@4
|
8 |
*
|
williamr@4
|
9 |
* Copyright (c) 1999
|
williamr@4
|
10 |
* Boris Fomitchev
|
williamr@4
|
11 |
*
|
williamr@4
|
12 |
* This material is provided "as is", with absolutely no warranty expressed
|
williamr@4
|
13 |
* or implied. Any use is at your own risk.
|
williamr@4
|
14 |
*
|
williamr@4
|
15 |
* Permission to use or copy this software for any purpose is hereby granted
|
williamr@4
|
16 |
* without fee, provided the above notices are retained on all copies.
|
williamr@4
|
17 |
* Permission to modify the code and to distribute modified code is granted,
|
williamr@4
|
18 |
* provided the above notices are retained, and a notice that the code was
|
williamr@4
|
19 |
* modified is included with the above copyright notice.
|
williamr@4
|
20 |
*
|
williamr@4
|
21 |
*/
|
williamr@4
|
22 |
|
williamr@4
|
23 |
/* NOTE: This is an internal header file, included by other STL headers.
|
williamr@4
|
24 |
* You should not attempt to use it directly.
|
williamr@4
|
25 |
*/
|
williamr@4
|
26 |
|
williamr@4
|
27 |
#ifndef _STLP_INTERNAL_SLIST_H
|
williamr@4
|
28 |
#define _STLP_INTERNAL_SLIST_H
|
williamr@4
|
29 |
|
williamr@4
|
30 |
#ifndef _STLP_INTERNAL_ALGOBASE_H
|
williamr@4
|
31 |
# include <stl/_algobase.h>
|
williamr@4
|
32 |
#endif
|
williamr@4
|
33 |
|
williamr@4
|
34 |
#ifndef _STLP_INTERNAL_ALLOC_H
|
williamr@4
|
35 |
# include <stl/_alloc.h>
|
williamr@4
|
36 |
#endif
|
williamr@4
|
37 |
|
williamr@4
|
38 |
#ifndef _STLP_INTERNAL_ITERATOR_H
|
williamr@4
|
39 |
# include <stl/_iterator.h>
|
williamr@4
|
40 |
#endif
|
williamr@4
|
41 |
|
williamr@4
|
42 |
#ifndef _STLP_INTERNAL_CONSTRUCT_H
|
williamr@4
|
43 |
# include <stl/_construct.h>
|
williamr@4
|
44 |
#endif
|
williamr@4
|
45 |
|
williamr@4
|
46 |
#ifndef _STLP_INTERNAL_FUNCTION_BASE_H
|
williamr@4
|
47 |
# include <stl/_function_base.h>
|
williamr@4
|
48 |
#endif
|
williamr@4
|
49 |
|
williamr@4
|
50 |
#ifndef _STLP_INTERNAL_SLIST_BASE_H
|
williamr@4
|
51 |
# include <stl/_slist_base.h>
|
williamr@4
|
52 |
#endif
|
williamr@4
|
53 |
|
williamr@4
|
54 |
_STLP_BEGIN_NAMESPACE
|
williamr@4
|
55 |
|
williamr@4
|
56 |
_STLP_MOVE_TO_PRIV_NAMESPACE
|
williamr@4
|
57 |
|
williamr@4
|
58 |
template <class _Tp>
|
williamr@4
|
59 |
class _Slist_node : public _Slist_node_base {
|
williamr@4
|
60 |
public:
|
williamr@4
|
61 |
_Tp _M_data;
|
williamr@4
|
62 |
__TRIVIAL_STUFF(_Slist_node)
|
williamr@4
|
63 |
};
|
williamr@4
|
64 |
|
williamr@4
|
65 |
struct _Slist_iterator_base {
|
williamr@4
|
66 |
typedef size_t size_type;
|
williamr@4
|
67 |
typedef ptrdiff_t difference_type;
|
williamr@4
|
68 |
typedef forward_iterator_tag iterator_category;
|
williamr@4
|
69 |
|
williamr@4
|
70 |
_Slist_node_base *_M_node;
|
williamr@4
|
71 |
|
williamr@4
|
72 |
_Slist_iterator_base(_Slist_node_base *__x) : _M_node(__x) {}
|
williamr@4
|
73 |
|
williamr@4
|
74 |
void _M_incr() {
|
williamr@4
|
75 |
_M_node = _M_node->_M_next;
|
williamr@4
|
76 |
}
|
williamr@4
|
77 |
};
|
williamr@4
|
78 |
|
williamr@4
|
79 |
template <class _Tp, class _Traits>
|
williamr@4
|
80 |
class _Slist_iterator : public _Slist_iterator_base {
|
williamr@4
|
81 |
public:
|
williamr@4
|
82 |
typedef typename _Traits::value_type value_type;
|
williamr@4
|
83 |
typedef typename _Traits::pointer pointer;
|
williamr@4
|
84 |
typedef typename _Traits::reference reference;
|
williamr@4
|
85 |
typedef forward_iterator_tag iterator_category;
|
williamr@4
|
86 |
typedef size_t size_type;
|
williamr@4
|
87 |
typedef ptrdiff_t difference_type;
|
williamr@4
|
88 |
|
williamr@4
|
89 |
typedef _Slist_iterator<_Tp, _Traits> _Self;
|
williamr@4
|
90 |
typedef typename _Traits::_NonConstTraits _NonConstTraits;
|
williamr@4
|
91 |
typedef _Slist_iterator<_Tp, _NonConstTraits> iterator;
|
williamr@4
|
92 |
typedef typename _Traits::_ConstTraits _ConstTraits;
|
williamr@4
|
93 |
typedef _Slist_iterator<_Tp, _ConstTraits> const_iterator;
|
williamr@4
|
94 |
|
williamr@4
|
95 |
typedef _Slist_node<value_type> _Node;
|
williamr@4
|
96 |
|
williamr@4
|
97 |
explicit _Slist_iterator(_Slist_node_base *__x) : _Slist_iterator_base(__x) {}
|
williamr@4
|
98 |
_Slist_iterator() : _Slist_iterator_base(0) {}
|
williamr@4
|
99 |
//copy constructor for iterator and constructor from iterator for const_iterator
|
williamr@4
|
100 |
_Slist_iterator(const iterator& __x) : _Slist_iterator_base(__x._M_node) {}
|
williamr@4
|
101 |
|
williamr@4
|
102 |
reference operator*() const { return __STATIC_CAST(_Node*, this->_M_node)->_M_data; }
|
williamr@4
|
103 |
|
williamr@4
|
104 |
_STLP_DEFINE_ARROW_OPERATOR
|
williamr@4
|
105 |
|
williamr@4
|
106 |
_Self& operator++() {
|
williamr@4
|
107 |
_M_incr();
|
williamr@4
|
108 |
return *this;
|
williamr@4
|
109 |
}
|
williamr@4
|
110 |
_Self operator++(int) {
|
williamr@4
|
111 |
_Self __tmp = *this;
|
williamr@4
|
112 |
_M_incr();
|
williamr@4
|
113 |
return __tmp;
|
williamr@4
|
114 |
}
|
williamr@4
|
115 |
|
williamr@4
|
116 |
bool operator==(const_iterator __y ) const {
|
williamr@4
|
117 |
return this->_M_node == __y._M_node;
|
williamr@4
|
118 |
}
|
williamr@4
|
119 |
bool operator!=(const_iterator __y ) const {
|
williamr@4
|
120 |
return this->_M_node != __y._M_node;
|
williamr@4
|
121 |
}
|
williamr@4
|
122 |
};
|
williamr@4
|
123 |
|
williamr@4
|
124 |
#if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
|
williamr@4
|
125 |
_STLP_MOVE_TO_STD_NAMESPACE
|
williamr@4
|
126 |
template <class _Tp, class _Traits>
|
williamr@4
|
127 |
struct __type_traits<_STLP_PRIV _Slist_iterator<_Tp, _Traits> > {
|
williamr@4
|
128 |
typedef __false_type has_trivial_default_constructor;
|
williamr@4
|
129 |
typedef __true_type has_trivial_copy_constructor;
|
williamr@4
|
130 |
typedef __true_type has_trivial_assignment_operator;
|
williamr@4
|
131 |
typedef __true_type has_trivial_destructor;
|
williamr@4
|
132 |
typedef __false_type is_POD_type;
|
williamr@4
|
133 |
};
|
williamr@4
|
134 |
_STLP_MOVE_TO_PRIV_NAMESPACE
|
williamr@4
|
135 |
#endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
|
williamr@4
|
136 |
|
williamr@4
|
137 |
#if defined (_STLP_USE_OLD_HP_ITERATOR_QUERIES)
|
williamr@4
|
138 |
_STLP_MOVE_TO_STD_NAMESPACE
|
williamr@4
|
139 |
template <class _Tp, class _Traits>
|
williamr@4
|
140 |
inline _Tp* _STLP_CALL value_type(const _STLP_PRIV _Slist_iterator<_Tp, _Traits>&) { return __STATIC_CAST(_Tp*, 0); }
|
williamr@4
|
141 |
inline ptrdiff_t* _STLP_CALL distance_type(const _STLP_PRIV _Slist_iterator_base&) { return 0; }
|
williamr@4
|
142 |
inline forward_iterator_tag _STLP_CALL iterator_category(const _STLP_PRIV _Slist_iterator_base&) { return forward_iterator_tag(); }
|
williamr@4
|
143 |
_STLP_MOVE_TO_PRIV_NAMESPACE
|
williamr@4
|
144 |
#endif /* OLD_QUERIES */
|
williamr@4
|
145 |
|
williamr@4
|
146 |
// Base class that encapsulates details of allocators and simplifies EH
|
williamr@4
|
147 |
template <class _Tp, class _Alloc>
|
williamr@4
|
148 |
class _Slist_base {
|
williamr@4
|
149 |
protected:
|
williamr@4
|
150 |
typedef _Slist_node<_Tp> _Node;
|
williamr@4
|
151 |
typedef typename _Alloc_traits<_Node,_Alloc>::allocator_type _M_node_allocator_type;
|
williamr@4
|
152 |
typedef _Slist_base<_Tp, _Alloc> _Self;
|
williamr@4
|
153 |
|
williamr@4
|
154 |
public:
|
williamr@4
|
155 |
typedef _STLP_alloc_proxy<_Slist_node_base, _Node, _M_node_allocator_type> _AllocProxy;
|
williamr@4
|
156 |
|
williamr@4
|
157 |
_STLP_FORCE_ALLOCATORS(_Tp, _Alloc)
|
williamr@4
|
158 |
typedef typename _Alloc_traits<_Tp,_Alloc>::allocator_type allocator_type;
|
williamr@4
|
159 |
|
williamr@4
|
160 |
_Slist_base(const allocator_type& __a) :
|
williamr@4
|
161 |
_M_head(_STLP_CONVERT_ALLOCATOR(__a, _Node), _Slist_node_base() ) {
|
williamr@4
|
162 |
_M_head._M_data._M_next = 0;
|
williamr@4
|
163 |
}
|
williamr@4
|
164 |
_Slist_base(__move_source<_Self> src) :
|
williamr@4
|
165 |
_M_head(__move_source<_AllocProxy>(src.get()._M_head)) {
|
williamr@4
|
166 |
src.get()._M_head._M_data._M_next = 0;
|
williamr@4
|
167 |
}
|
williamr@4
|
168 |
~_Slist_base() { _M_erase_after(&_M_head._M_data, 0); }
|
williamr@4
|
169 |
|
williamr@4
|
170 |
protected:
|
williamr@4
|
171 |
_Slist_node_base* _M_erase_after(_Slist_node_base* __pos) {
|
williamr@4
|
172 |
_Node* __next = __STATIC_CAST(_Node*, __pos->_M_next);
|
williamr@4
|
173 |
_Slist_node_base* __next_next = __next->_M_next;
|
williamr@4
|
174 |
__pos->_M_next = __next_next;
|
williamr@4
|
175 |
_STLP_STD::_Destroy(&__next->_M_data);
|
williamr@4
|
176 |
_M_head.deallocate(__next,1);
|
williamr@4
|
177 |
return __next_next;
|
williamr@4
|
178 |
}
|
williamr@4
|
179 |
_Slist_node_base* _M_erase_after(_Slist_node_base*, _Slist_node_base*);
|
williamr@4
|
180 |
|
williamr@4
|
181 |
public:
|
williamr@4
|
182 |
allocator_type get_allocator() const
|
williamr@4
|
183 |
{ return _STLP_CONVERT_ALLOCATOR((const _M_node_allocator_type&)_M_head, _Tp); }
|
williamr@4
|
184 |
_AllocProxy _M_head;
|
williamr@4
|
185 |
};
|
williamr@4
|
186 |
|
williamr@4
|
187 |
#if defined (_STLP_USE_PTR_SPECIALIZATIONS)
|
williamr@4
|
188 |
# define slist _STLP_PTR_IMPL_NAME(slist)
|
williamr@4
|
189 |
#elif defined (_STLP_DEBUG)
|
williamr@4
|
190 |
# define slist _STLP_NON_DBG_NAME(slist)
|
williamr@4
|
191 |
#else
|
williamr@4
|
192 |
_STLP_MOVE_TO_STD_NAMESPACE
|
williamr@4
|
193 |
#endif
|
williamr@4
|
194 |
|
williamr@4
|
195 |
template <class _Tp, _STLP_DEFAULT_ALLOCATOR_SELECT(_Tp) >
|
williamr@4
|
196 |
class slist;
|
williamr@4
|
197 |
|
williamr@4
|
198 |
#if !defined (slist)
|
williamr@4
|
199 |
_STLP_MOVE_TO_PRIV_NAMESPACE
|
williamr@4
|
200 |
#endif
|
williamr@4
|
201 |
|
williamr@4
|
202 |
// helper functions to reduce code duplication
|
williamr@4
|
203 |
template <class _Tp, class _Alloc, class _BinaryPredicate>
|
williamr@4
|
204 |
void _Slist_unique(slist<_Tp, _Alloc>& __that, _BinaryPredicate __binary_pred);
|
williamr@4
|
205 |
|
williamr@4
|
206 |
template <class _Tp, class _Alloc, class _StrictWeakOrdering>
|
williamr@4
|
207 |
void _Slist_merge(slist<_Tp, _Alloc>& __that, slist<_Tp, _Alloc>& __x,
|
williamr@4
|
208 |
_StrictWeakOrdering __comp);
|
williamr@4
|
209 |
|
williamr@4
|
210 |
template <class _Tp, class _Alloc, class _StrictWeakOrdering>
|
williamr@4
|
211 |
void _Slist_sort(slist<_Tp, _Alloc>& __that, _StrictWeakOrdering __comp);
|
williamr@4
|
212 |
|
williamr@4
|
213 |
#if !defined (slist)
|
williamr@4
|
214 |
_STLP_MOVE_TO_STD_NAMESPACE
|
williamr@4
|
215 |
#endif
|
williamr@4
|
216 |
|
williamr@4
|
217 |
template <class _Tp, class _Alloc>
|
williamr@4
|
218 |
class slist : protected _STLP_PRIV _Slist_base<_Tp,_Alloc>
|
williamr@4
|
219 |
#if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (slist)
|
williamr@4
|
220 |
, public __stlport_class<slist<_Tp, _Alloc> >
|
williamr@4
|
221 |
#endif
|
williamr@4
|
222 |
{
|
williamr@4
|
223 |
private:
|
williamr@4
|
224 |
typedef _STLP_PRIV _Slist_base<_Tp,_Alloc> _Base;
|
williamr@4
|
225 |
typedef slist<_Tp,_Alloc> _Self;
|
williamr@4
|
226 |
public:
|
williamr@4
|
227 |
typedef _Tp value_type;
|
williamr@4
|
228 |
|
williamr@4
|
229 |
typedef value_type* pointer;
|
williamr@4
|
230 |
typedef const value_type* const_pointer;
|
williamr@4
|
231 |
typedef value_type& reference;
|
williamr@4
|
232 |
typedef const value_type& const_reference;
|
williamr@4
|
233 |
typedef size_t size_type;
|
williamr@4
|
234 |
typedef ptrdiff_t difference_type;
|
williamr@4
|
235 |
typedef forward_iterator_tag _Iterator_category;
|
williamr@4
|
236 |
|
williamr@4
|
237 |
typedef _STLP_PRIV _Slist_iterator<_Tp, _Nonconst_traits<_Tp> > iterator;
|
williamr@4
|
238 |
typedef _STLP_PRIV _Slist_iterator<_Tp, _Const_traits<_Tp> > const_iterator;
|
williamr@4
|
239 |
|
williamr@4
|
240 |
_STLP_FORCE_ALLOCATORS(_Tp, _Alloc)
|
williamr@4
|
241 |
typedef typename _Base::allocator_type allocator_type;
|
williamr@4
|
242 |
|
williamr@4
|
243 |
private:
|
williamr@4
|
244 |
typedef _STLP_PRIV _Slist_node<_Tp> _Node;
|
williamr@4
|
245 |
typedef _STLP_PRIV _Slist_node_base _Node_base;
|
williamr@4
|
246 |
|
williamr@4
|
247 |
#if !defined(_STLP_DONT_SUP_DFLT_PARAM)
|
williamr@4
|
248 |
_Node* _M_create_node(const value_type& __x = _Tp()) {
|
williamr@4
|
249 |
#else
|
williamr@4
|
250 |
_Node* _M_create_node(const value_type& __x) {
|
williamr@4
|
251 |
#endif /*_STLP_DONT_SUP_DFLT_PARAM*/
|
williamr@4
|
252 |
_Node* __node = this->_M_head.allocate(1);
|
williamr@4
|
253 |
_STLP_TRY {
|
williamr@4
|
254 |
_Copy_Construct(&__node->_M_data, __x);
|
williamr@4
|
255 |
__node->_M_next = 0;
|
williamr@4
|
256 |
}
|
williamr@4
|
257 |
_STLP_UNWIND(this->_M_head.deallocate(__node, 1))
|
williamr@4
|
258 |
return __node;
|
williamr@4
|
259 |
}
|
williamr@4
|
260 |
|
williamr@4
|
261 |
#if defined(_STLP_DONT_SUP_DFLT_PARAM)
|
williamr@4
|
262 |
_Node* _M_create_node() {
|
williamr@4
|
263 |
_Node* __node = this->_M_head.allocate(1);
|
williamr@4
|
264 |
_STLP_TRY {
|
williamr@4
|
265 |
_STLP_STD::_Construct(&__node->_M_data);
|
williamr@4
|
266 |
__node->_M_next = 0;
|
williamr@4
|
267 |
}
|
williamr@4
|
268 |
_STLP_UNWIND(this->_M_head.deallocate(__node, 1))
|
williamr@4
|
269 |
return __node;
|
williamr@4
|
270 |
}
|
williamr@4
|
271 |
#endif /*_STLP_DONT_SUP_DFLT_PARAM*/
|
williamr@4
|
272 |
|
williamr@4
|
273 |
public:
|
williamr@4
|
274 |
|
williamr@4
|
275 |
allocator_type get_allocator() const { return _Base::get_allocator(); }
|
williamr@4
|
276 |
|
williamr@4
|
277 |
#if !defined (_STLP_DONT_SUP_DFLT_PARAM)
|
williamr@4
|
278 |
explicit slist(const allocator_type& __a = allocator_type())
|
williamr@4
|
279 |
#else
|
williamr@4
|
280 |
slist()
|
williamr@4
|
281 |
: _STLP_PRIV _Slist_base<_Tp,_Alloc>(allocator_type()) {}
|
williamr@4
|
282 |
slist(const allocator_type& __a)
|
williamr@4
|
283 |
#endif
|
williamr@4
|
284 |
: _STLP_PRIV _Slist_base<_Tp,_Alloc>(__a) {}
|
williamr@4
|
285 |
|
williamr@4
|
286 |
#if !defined (_STLP_DONT_SUP_DFLT_PARAM)
|
williamr@4
|
287 |
explicit slist(size_type __n, const value_type& __x = _STLP_DEFAULT_CONSTRUCTED(_Tp),
|
williamr@4
|
288 |
const allocator_type& __a = allocator_type())
|
williamr@4
|
289 |
#else
|
williamr@4
|
290 |
explicit slist(size_type __n)
|
williamr@4
|
291 |
: _STLP_PRIV _Slist_base<_Tp,_Alloc>(allocator_type())
|
williamr@4
|
292 |
{ _M_insert_after_fill(&this->_M_head._M_data, __n, _STLP_DEFAULT_CONSTRUCTED(_Tp)); }
|
williamr@4
|
293 |
slist(size_type __n, const value_type& __x)
|
williamr@4
|
294 |
: _STLP_PRIV _Slist_base<_Tp,_Alloc>(allocator_type())
|
williamr@4
|
295 |
{ _M_insert_after_fill(&this->_M_head._M_data, __n, __x); }
|
williamr@4
|
296 |
slist(size_type __n, const value_type& __x, const allocator_type& __a)
|
williamr@4
|
297 |
#endif
|
williamr@4
|
298 |
: _STLP_PRIV _Slist_base<_Tp,_Alloc>(__a)
|
williamr@4
|
299 |
{ _M_insert_after_fill(&this->_M_head._M_data, __n, __x); }
|
williamr@4
|
300 |
|
williamr@4
|
301 |
#if defined (_STLP_MEMBER_TEMPLATES)
|
williamr@4
|
302 |
// We don't need any dispatching tricks here, because _M_insert_after_range
|
williamr@4
|
303 |
// already does them.
|
williamr@4
|
304 |
template <class _InputIterator>
|
williamr@4
|
305 |
slist(_InputIterator __first, _InputIterator __last,
|
williamr@4
|
306 |
const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
|
williamr@4
|
307 |
: _STLP_PRIV _Slist_base<_Tp,_Alloc>(__a)
|
williamr@4
|
308 |
{ _M_insert_after_range(&this->_M_head._M_data, __first, __last); }
|
williamr@4
|
309 |
# if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
|
williamr@4
|
310 |
// VC++ needs this crazyness
|
williamr@4
|
311 |
template <class _InputIterator>
|
williamr@4
|
312 |
slist(_InputIterator __first, _InputIterator __last)
|
williamr@4
|
313 |
: _STLP_PRIV _Slist_base<_Tp,_Alloc>(allocator_type())
|
williamr@4
|
314 |
{ _M_insert_after_range(&this->_M_head._M_data, __first, __last); }
|
williamr@4
|
315 |
# endif
|
williamr@4
|
316 |
#else /* _STLP_MEMBER_TEMPLATES */
|
williamr@4
|
317 |
slist(const_iterator __first, const_iterator __last,
|
williamr@4
|
318 |
const allocator_type& __a = allocator_type() )
|
williamr@4
|
319 |
: _STLP_PRIV _Slist_base<_Tp,_Alloc>(__a)
|
williamr@4
|
320 |
{ _M_insert_after_range(&this->_M_head._M_data, __first, __last); }
|
williamr@4
|
321 |
slist(const value_type* __first, const value_type* __last,
|
williamr@4
|
322 |
const allocator_type& __a = allocator_type())
|
williamr@4
|
323 |
: _STLP_PRIV _Slist_base<_Tp,_Alloc>(__a)
|
williamr@4
|
324 |
{ _M_insert_after_range(&this->_M_head._M_data, __first, __last); }
|
williamr@4
|
325 |
#endif /* _STLP_MEMBER_TEMPLATES */
|
williamr@4
|
326 |
|
williamr@4
|
327 |
slist(const _Self& __x)
|
williamr@4
|
328 |
: _STLP_PRIV _Slist_base<_Tp,_Alloc>(__x.get_allocator())
|
williamr@4
|
329 |
{ _M_insert_after_range(&this->_M_head._M_data, __x.begin(), __x.end()); }
|
williamr@4
|
330 |
|
williamr@4
|
331 |
slist(__move_source<_Self> src)
|
williamr@4
|
332 |
: _STLP_PRIV _Slist_base<_Tp, _Alloc>(__move_source<_Base>(src.get())) {}
|
williamr@4
|
333 |
|
williamr@4
|
334 |
_Self& operator= (const _Self& __x);
|
williamr@4
|
335 |
|
williamr@4
|
336 |
~slist() {}
|
williamr@4
|
337 |
|
williamr@4
|
338 |
public:
|
williamr@4
|
339 |
// assign(), a generalized assignment member function. Two
|
williamr@4
|
340 |
// versions: one that takes a count, and one that takes a range.
|
williamr@4
|
341 |
// The range version is a member template, so we dispatch on whether
|
williamr@4
|
342 |
// or not the type is an integer.
|
williamr@4
|
343 |
|
williamr@4
|
344 |
void assign(size_type __n, const _Tp& __val) { _M_fill_assign(__n, __val); }
|
williamr@4
|
345 |
|
williamr@4
|
346 |
private:
|
williamr@4
|
347 |
void _M_fill_assign(size_type __n, const _Tp& __val);
|
williamr@4
|
348 |
|
williamr@4
|
349 |
#if defined (_STLP_MEMBER_TEMPLATES)
|
williamr@4
|
350 |
public:
|
williamr@4
|
351 |
template <class _InputIterator>
|
williamr@4
|
352 |
void assign(_InputIterator __first, _InputIterator __last) {
|
williamr@4
|
353 |
typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
|
williamr@4
|
354 |
_M_assign_dispatch(__first, __last, _Integral());
|
williamr@4
|
355 |
}
|
williamr@4
|
356 |
|
williamr@4
|
357 |
private:
|
williamr@4
|
358 |
template <class _Integer>
|
williamr@4
|
359 |
void _M_assign_dispatch(_Integer __n, _Integer __val,
|
williamr@4
|
360 |
const __true_type& /*_IsIntegral*/) {
|
williamr@4
|
361 |
_M_fill_assign((size_type) __n, (_Tp) __val);
|
williamr@4
|
362 |
}
|
williamr@4
|
363 |
|
williamr@4
|
364 |
template <class _InputIter>
|
williamr@4
|
365 |
void _M_assign_dispatch(_InputIter __first, _InputIter __last,
|
williamr@4
|
366 |
const __false_type& /*_IsIntegral*/) {
|
williamr@4
|
367 |
#else
|
williamr@4
|
368 |
public:
|
williamr@4
|
369 |
void assign(const_pointer __first, const_pointer __last) {
|
williamr@4
|
370 |
_Node_base* __prev = &this->_M_head._M_data;
|
williamr@4
|
371 |
_Node_base* __node = this->_M_head._M_data._M_next;
|
williamr@4
|
372 |
while (__node != 0 && __first != __last) {
|
williamr@4
|
373 |
__STATIC_CAST(_Node*, __node)->_M_data = *__first;
|
williamr@4
|
374 |
__prev = __node;
|
williamr@4
|
375 |
__node = __node->_M_next;
|
williamr@4
|
376 |
++__first;
|
williamr@4
|
377 |
}
|
williamr@4
|
378 |
if (__first != __last)
|
williamr@4
|
379 |
_M_insert_after_range(__prev, __first, __last);
|
williamr@4
|
380 |
else
|
williamr@4
|
381 |
this->_M_erase_after(__prev, 0);
|
williamr@4
|
382 |
}
|
williamr@4
|
383 |
void assign(const_iterator __first, const_iterator __last) {
|
williamr@4
|
384 |
#endif /* _STLP_MEMBER_TEMPLATES */
|
williamr@4
|
385 |
_Node_base* __prev = &this->_M_head._M_data;
|
williamr@4
|
386 |
_Node_base* __node = this->_M_head._M_data._M_next;
|
williamr@4
|
387 |
while (__node != 0 && __first != __last) {
|
williamr@4
|
388 |
__STATIC_CAST(_Node*, __node)->_M_data = *__first;
|
williamr@4
|
389 |
__prev = __node;
|
williamr@4
|
390 |
__node = __node->_M_next;
|
williamr@4
|
391 |
++__first;
|
williamr@4
|
392 |
}
|
williamr@4
|
393 |
if (__first != __last)
|
williamr@4
|
394 |
_M_insert_after_range(__prev, __first, __last);
|
williamr@4
|
395 |
else
|
williamr@4
|
396 |
this->_M_erase_after(__prev, 0);
|
williamr@4
|
397 |
}
|
williamr@4
|
398 |
|
williamr@4
|
399 |
public:
|
williamr@4
|
400 |
|
williamr@4
|
401 |
// Experimental new feature: before_begin() returns a
|
williamr@4
|
402 |
// non-dereferenceable iterator that, when incremented, yields
|
williamr@4
|
403 |
// begin(). This iterator may be used as the argument to
|
williamr@4
|
404 |
// insert_after, erase_after, etc. Note that even for an empty
|
williamr@4
|
405 |
// slist, before_begin() is not the same iterator as end(). It
|
williamr@4
|
406 |
// is always necessary to increment before_begin() at least once to
|
williamr@4
|
407 |
// obtain end().
|
williamr@4
|
408 |
iterator before_begin() { return iterator(&this->_M_head._M_data); }
|
williamr@4
|
409 |
const_iterator before_begin() const
|
williamr@4
|
410 |
{ return const_iterator(__CONST_CAST(_Node_base*, &this->_M_head._M_data)); }
|
williamr@4
|
411 |
|
williamr@4
|
412 |
iterator begin() { return iterator(this->_M_head._M_data._M_next); }
|
williamr@4
|
413 |
const_iterator begin() const
|
williamr@4
|
414 |
{ return const_iterator(this->_M_head._M_data._M_next);}
|
williamr@4
|
415 |
|
williamr@4
|
416 |
iterator end() { return iterator(); }
|
williamr@4
|
417 |
const_iterator end() const { return const_iterator(); }
|
williamr@4
|
418 |
|
williamr@4
|
419 |
size_type size() const
|
williamr@4
|
420 |
{ return _STLP_PRIV _Sl_global_inst::size(this->_M_head._M_data._M_next); }
|
williamr@4
|
421 |
|
williamr@4
|
422 |
size_type max_size() const { return size_type(-1); }
|
williamr@4
|
423 |
|
williamr@4
|
424 |
bool empty() const { return this->_M_head._M_data._M_next == 0; }
|
williamr@4
|
425 |
|
williamr@4
|
426 |
void swap(_Self& __x) {
|
williamr@4
|
427 |
this->_M_head.swap(__x._M_head);
|
williamr@4
|
428 |
}
|
williamr@4
|
429 |
|
williamr@4
|
430 |
public:
|
williamr@4
|
431 |
reference front() { return *begin(); }
|
williamr@4
|
432 |
const_reference front() const { return *begin(); }
|
williamr@4
|
433 |
#if !defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
|
williamr@4
|
434 |
void push_front(const value_type& __x = _Tp()) {
|
williamr@4
|
435 |
#else
|
williamr@4
|
436 |
void push_front(const value_type& __x) {
|
williamr@4
|
437 |
#endif /*!_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
|
williamr@4
|
438 |
_STLP_PRIV __slist_make_link(&this->_M_head._M_data, _M_create_node(__x));
|
williamr@4
|
439 |
}
|
williamr@4
|
440 |
|
williamr@4
|
441 |
#if defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
|
williamr@4
|
442 |
void push_front() { _STLP_PRIV __slist_make_link(&this->_M_head._M_data, _M_create_node());}
|
williamr@4
|
443 |
#endif /*_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
|
williamr@4
|
444 |
|
williamr@4
|
445 |
void pop_front() {
|
williamr@4
|
446 |
_Node* __node = __STATIC_CAST(_Node*, this->_M_head._M_data._M_next);
|
williamr@4
|
447 |
this->_M_head._M_data._M_next = __node->_M_next;
|
williamr@4
|
448 |
_STLP_STD::_Destroy(&__node->_M_data);
|
williamr@4
|
449 |
this->_M_head.deallocate(__node, 1);
|
williamr@4
|
450 |
}
|
williamr@4
|
451 |
|
williamr@4
|
452 |
iterator previous(const_iterator __pos) {
|
williamr@4
|
453 |
return iterator(_STLP_PRIV _Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node));
|
williamr@4
|
454 |
}
|
williamr@4
|
455 |
const_iterator previous(const_iterator __pos) const {
|
williamr@4
|
456 |
return const_iterator(__CONST_CAST(_Node_base*,
|
williamr@4
|
457 |
_STLP_PRIV _Sl_global_inst::__previous(&this->_M_head._M_data,
|
williamr@4
|
458 |
__pos._M_node)));
|
williamr@4
|
459 |
}
|
williamr@4
|
460 |
|
williamr@4
|
461 |
private:
|
williamr@4
|
462 |
#if !defined (_STLP_DONT_SUP_DFLT_PARAM)
|
williamr@4
|
463 |
_Node* _M_insert_after(_Node_base* __pos, const value_type& __x = _Tp()) {
|
williamr@4
|
464 |
#else
|
williamr@4
|
465 |
_Node* _M_insert_after(_Node_base* __pos, const value_type& __x) {
|
williamr@4
|
466 |
#endif /*_STLP_DONT_SUP_DFLT_PARAM*/
|
williamr@4
|
467 |
return __STATIC_CAST(_Node*, _STLP_PRIV __slist_make_link(__pos, _M_create_node(__x)));
|
williamr@4
|
468 |
}
|
williamr@4
|
469 |
|
williamr@4
|
470 |
#if defined (_STLP_DONT_SUP_DFLT_PARAM)
|
williamr@4
|
471 |
_Node* _M_insert_after(_Node_base* __pos) {
|
williamr@4
|
472 |
return __STATIC_CAST(_Node*, _STLP_PRIV __slist_make_link(__pos, _M_create_node()));
|
williamr@4
|
473 |
}
|
williamr@4
|
474 |
#endif /*_STLP_DONT_SUP_DFLT_PARAM*/
|
williamr@4
|
475 |
|
williamr@4
|
476 |
void _M_insert_after_fill(_Node_base* __pos,
|
williamr@4
|
477 |
size_type __n, const value_type& __x) {
|
williamr@4
|
478 |
for (size_type __i = 0; __i < __n; ++__i)
|
williamr@4
|
479 |
__pos = _STLP_PRIV __slist_make_link(__pos, _M_create_node(__x));
|
williamr@4
|
480 |
}
|
williamr@4
|
481 |
|
williamr@4
|
482 |
#if defined (_STLP_MEMBER_TEMPLATES)
|
williamr@4
|
483 |
// Check whether it's an integral type. If so, it's not an iterator.
|
williamr@4
|
484 |
template <class _InIter>
|
williamr@4
|
485 |
void _M_insert_after_range(_Node_base* __pos,
|
williamr@4
|
486 |
_InIter __first, _InIter __last) {
|
williamr@4
|
487 |
typedef typename _IsIntegral<_InIter>::_Ret _Integral;
|
williamr@4
|
488 |
_M_insert_after_range(__pos, __first, __last, _Integral());
|
williamr@4
|
489 |
}
|
williamr@4
|
490 |
|
williamr@4
|
491 |
template <class _Integer>
|
williamr@4
|
492 |
void _M_insert_after_range(_Node_base* __pos, _Integer __n, _Integer __x,
|
williamr@4
|
493 |
const __true_type&) {
|
williamr@4
|
494 |
_M_insert_after_fill(__pos, __n, __x);
|
williamr@4
|
495 |
}
|
williamr@4
|
496 |
|
williamr@4
|
497 |
template <class _InIter>
|
williamr@4
|
498 |
void _M_insert_after_range(_Node_base* __pos,
|
williamr@4
|
499 |
_InIter __first, _InIter __last,
|
williamr@4
|
500 |
const __false_type&) {
|
williamr@4
|
501 |
#else /* _STLP_MEMBER_TEMPLATES */
|
williamr@4
|
502 |
void _M_insert_after_range(_Node_base* __pos,
|
williamr@4
|
503 |
const value_type* __first,
|
williamr@4
|
504 |
const value_type* __last) {
|
williamr@4
|
505 |
while (__first != __last) {
|
williamr@4
|
506 |
__pos = _STLP_PRIV __slist_make_link(__pos, _M_create_node(*__first));
|
williamr@4
|
507 |
++__first;
|
williamr@4
|
508 |
}
|
williamr@4
|
509 |
}
|
williamr@4
|
510 |
void _M_insert_after_range(_Node_base* __pos,
|
williamr@4
|
511 |
const_iterator __first, const_iterator __last) {
|
williamr@4
|
512 |
#endif /* _STLP_MEMBER_TEMPLATES */
|
williamr@4
|
513 |
while (__first != __last) {
|
williamr@4
|
514 |
__pos = _STLP_PRIV __slist_make_link(__pos, _M_create_node(*__first));
|
williamr@4
|
515 |
++__first;
|
williamr@4
|
516 |
}
|
williamr@4
|
517 |
}
|
williamr@4
|
518 |
|
williamr@4
|
519 |
#if defined (_STLP_MEMBER_TEMPLATES)
|
williamr@4
|
520 |
// Check whether it's an integral type. If so, it's not an iterator.
|
williamr@4
|
521 |
template <class _InIter>
|
williamr@4
|
522 |
void _M_splice_after_range(_Node_base* __pos,
|
williamr@4
|
523 |
_InIter __first, _InIter __last) {
|
williamr@4
|
524 |
typedef typename _IsIntegral<_InIter>::_Ret _Integral;
|
williamr@4
|
525 |
_M_splice_after_range(__pos, __first, __last, _Integral());
|
williamr@4
|
526 |
}
|
williamr@4
|
527 |
|
williamr@4
|
528 |
template <class _Integer>
|
williamr@4
|
529 |
void _M_splice_after_range(_Node_base* __pos, _Integer __n, _Integer __x,
|
williamr@4
|
530 |
const __true_type&) {
|
williamr@4
|
531 |
_M_insert_after_fill(__pos, __n, __x);
|
williamr@4
|
532 |
}
|
williamr@4
|
533 |
|
williamr@4
|
534 |
template <class _InIter>
|
williamr@4
|
535 |
void _M_splice_after_range(_Node_base* __pos,
|
williamr@4
|
536 |
_InIter __first, _InIter __last,
|
williamr@4
|
537 |
const __false_type&) {
|
williamr@4
|
538 |
#else /* _STLP_MEMBER_TEMPLATES */
|
williamr@4
|
539 |
void _M_splice_after_range(_Node_base* __pos,
|
williamr@4
|
540 |
const value_type* __first,
|
williamr@4
|
541 |
const value_type* __last) {
|
williamr@4
|
542 |
while (__first != __last) {
|
williamr@4
|
543 |
__pos = _STLP_PRIV __slist_make_link(__pos, _M_create_node(*__first));
|
williamr@4
|
544 |
++__first;
|
williamr@4
|
545 |
}
|
williamr@4
|
546 |
}
|
williamr@4
|
547 |
void _M_splice_after_range(_Node_base* __pos,
|
williamr@4
|
548 |
const_iterator __first, const_iterator __last) {
|
williamr@4
|
549 |
#endif /* _STLP_MEMBER_TEMPLATES */
|
williamr@4
|
550 |
//We use a temporary slist to avoid the auto reference troubles (infinite loop)
|
williamr@4
|
551 |
_Self __tmp(__first, __last, this->get_allocator());
|
williamr@4
|
552 |
splice_after(iterator(__pos), __tmp);
|
williamr@4
|
553 |
}
|
williamr@4
|
554 |
|
williamr@4
|
555 |
#if defined (_STLP_MEMBER_TEMPLATES)
|
williamr@4
|
556 |
// Check whether it's an integral type. If so, it's not an iterator.
|
williamr@4
|
557 |
template <class _InIter>
|
williamr@4
|
558 |
void _M_splice_range(_Node_base* __pos,
|
williamr@4
|
559 |
_InIter __first, _InIter __last) {
|
williamr@4
|
560 |
typedef typename _IsIntegral<_InIter>::_Ret _Integral;
|
williamr@4
|
561 |
_M_splice_range(__pos, __first, __last, _Integral());
|
williamr@4
|
562 |
}
|
williamr@4
|
563 |
|
williamr@4
|
564 |
template <class _Integer>
|
williamr@4
|
565 |
void _M_splice_range(_Node_base* __pos, _Integer __n, _Integer __x,
|
williamr@4
|
566 |
const __true_type&) {
|
williamr@4
|
567 |
_M_insert_after_fill(_STLP_PRIV _Sl_global_inst::__previous(&this->_M_head._M_data, __pos),
|
williamr@4
|
568 |
__n, __x);
|
williamr@4
|
569 |
}
|
williamr@4
|
570 |
|
williamr@4
|
571 |
template <class _InIter>
|
williamr@4
|
572 |
void _M_splice_range(_Node_base* __pos,
|
williamr@4
|
573 |
_InIter __first, _InIter __last,
|
williamr@4
|
574 |
const __false_type&) {
|
williamr@4
|
575 |
#else /* _STLP_MEMBER_TEMPLATES */
|
williamr@4
|
576 |
void _M_splice_range(_Node_base* __pos,
|
williamr@4
|
577 |
const value_type* __first,
|
williamr@4
|
578 |
const value_type* __last) {
|
williamr@4
|
579 |
while (__first != __last) {
|
williamr@4
|
580 |
__pos = _STLP_PRIV __slist_make_link(__pos, _M_create_node(*__first));
|
williamr@4
|
581 |
++__first;
|
williamr@4
|
582 |
}
|
williamr@4
|
583 |
}
|
williamr@4
|
584 |
void _M_splice_range(_Node_base* __pos,
|
williamr@4
|
585 |
const_iterator __first, const_iterator __last) {
|
williamr@4
|
586 |
#endif /* _STLP_MEMBER_TEMPLATES */
|
williamr@4
|
587 |
//We use a temporary slist to avoid the auto reference troubles (infinite loop)
|
williamr@4
|
588 |
_Self __tmp(__first, __last, this->get_allocator());
|
williamr@4
|
589 |
splice(iterator(__pos), __tmp);
|
williamr@4
|
590 |
}
|
williamr@4
|
591 |
|
williamr@4
|
592 |
public:
|
williamr@4
|
593 |
|
williamr@4
|
594 |
#if !defined (_STLP_DONT_SUP_DFLT_PARAM)
|
williamr@4
|
595 |
iterator insert_after(iterator __pos, const value_type& __x = _Tp()) {
|
williamr@4
|
596 |
#else
|
williamr@4
|
597 |
iterator insert_after(iterator __pos, const value_type& __x) {
|
williamr@4
|
598 |
#endif /*_STLP_DONT_SUP_DFLT_PARAM*/
|
williamr@4
|
599 |
return iterator(_M_insert_after(__pos._M_node, __x));
|
williamr@4
|
600 |
}
|
williamr@4
|
601 |
|
williamr@4
|
602 |
#if defined (_STLP_DONT_SUP_DFLT_PARAM)
|
williamr@4
|
603 |
iterator insert_after(iterator __pos) {
|
williamr@4
|
604 |
return insert_after(__pos, _STLP_DEFAULT_CONSTRUCTED(_Tp));
|
williamr@4
|
605 |
}
|
williamr@4
|
606 |
#endif /*_STLP_DONT_SUP_DFLT_PARAM*/
|
williamr@4
|
607 |
|
williamr@4
|
608 |
void insert_after(iterator __pos, size_type __n, const value_type& __x) {
|
williamr@4
|
609 |
_M_insert_after_fill(__pos._M_node, __n, __x);
|
williamr@4
|
610 |
}
|
williamr@4
|
611 |
|
williamr@4
|
612 |
#if defined (_STLP_MEMBER_TEMPLATES)
|
williamr@4
|
613 |
// We don't need any dispatching tricks here, because _M_insert_after_range
|
williamr@4
|
614 |
// already does them.
|
williamr@4
|
615 |
template <class _InIter>
|
williamr@4
|
616 |
void insert_after(iterator __pos, _InIter __first, _InIter __last) {
|
williamr@4
|
617 |
#else /* _STLP_MEMBER_TEMPLATES */
|
williamr@4
|
618 |
void insert_after(iterator __pos,
|
williamr@4
|
619 |
const value_type* __first, const value_type* __last) {
|
williamr@4
|
620 |
_M_insert_after_range(__pos._M_node, __first, __last);
|
williamr@4
|
621 |
}
|
williamr@4
|
622 |
void insert_after(iterator __pos,
|
williamr@4
|
623 |
const_iterator __first, const_iterator __last) {
|
williamr@4
|
624 |
#endif /* _STLP_MEMBER_TEMPLATES */
|
williamr@4
|
625 |
_M_splice_after_range(__pos._M_node, __first, __last);
|
williamr@4
|
626 |
}
|
williamr@4
|
627 |
|
williamr@4
|
628 |
#if !defined (_STLP_DONT_SUP_DFLT_PARAM)
|
williamr@4
|
629 |
iterator insert(iterator __pos, const value_type& __x = _Tp()) {
|
williamr@4
|
630 |
#else
|
williamr@4
|
631 |
iterator insert(iterator __pos, const value_type& __x) {
|
williamr@4
|
632 |
#endif /*_STLP_DONT_SUP_DFLT_PARAM*/
|
williamr@4
|
633 |
return iterator(_M_insert_after(_STLP_PRIV _Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node),
|
williamr@4
|
634 |
__x));
|
williamr@4
|
635 |
}
|
williamr@4
|
636 |
|
williamr@4
|
637 |
#if defined (_STLP_DONT_SUP_DFLT_PARAM)
|
williamr@4
|
638 |
iterator insert(iterator __pos) {
|
williamr@4
|
639 |
return iterator(_M_insert_after(_STLP_PRIV _Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node),
|
williamr@4
|
640 |
_STLP_DEFAULT_CONSTRUCTED(_Tp)));
|
williamr@4
|
641 |
}
|
williamr@4
|
642 |
#endif /*_STLP_DONT_SUP_DFLT_PARAM*/
|
williamr@4
|
643 |
|
williamr@4
|
644 |
void insert(iterator __pos, size_type __n, const value_type& __x) {
|
williamr@4
|
645 |
_M_insert_after_fill(_STLP_PRIV _Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node), __n, __x);
|
williamr@4
|
646 |
}
|
williamr@4
|
647 |
|
williamr@4
|
648 |
#if defined (_STLP_MEMBER_TEMPLATES)
|
williamr@4
|
649 |
// We don't need any dispatching tricks here, because _M_insert_after_range
|
williamr@4
|
650 |
// already does them.
|
williamr@4
|
651 |
template <class _InIter>
|
williamr@4
|
652 |
void insert(iterator __pos, _InIter __first, _InIter __last) {
|
williamr@4
|
653 |
#else /* _STLP_MEMBER_TEMPLATES */
|
williamr@4
|
654 |
void insert(iterator __pos, const value_type* __first,
|
williamr@4
|
655 |
const value_type* __last) {
|
williamr@4
|
656 |
_M_insert_after_range(_STLP_PRIV _Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node),
|
williamr@4
|
657 |
__first, __last);
|
williamr@4
|
658 |
}
|
williamr@4
|
659 |
void insert(iterator __pos, const_iterator __first, const_iterator __last) {
|
williamr@4
|
660 |
#endif /* _STLP_MEMBER_TEMPLATES */
|
williamr@4
|
661 |
_M_splice_range(__pos._M_node, __first, __last);
|
williamr@4
|
662 |
}
|
williamr@4
|
663 |
|
williamr@4
|
664 |
public:
|
williamr@4
|
665 |
iterator erase_after(iterator __pos)
|
williamr@4
|
666 |
{ return iterator(this->_M_erase_after(__pos._M_node)); }
|
williamr@4
|
667 |
iterator erase_after(iterator __before_first, iterator __last)
|
williamr@4
|
668 |
{ return iterator(this->_M_erase_after(__before_first._M_node, __last._M_node)); }
|
williamr@4
|
669 |
|
williamr@4
|
670 |
iterator erase(iterator __pos)
|
williamr@4
|
671 |
{ return iterator(this->_M_erase_after(_STLP_PRIV _Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node))); }
|
williamr@4
|
672 |
iterator erase(iterator __first, iterator __last)
|
williamr@4
|
673 |
{ return iterator(this->_M_erase_after(_STLP_PRIV _Sl_global_inst::__previous(&this->_M_head._M_data, __first._M_node), __last._M_node)); }
|
williamr@4
|
674 |
|
williamr@4
|
675 |
#if !defined (_STLP_DONT_SUP_DFLT_PARAM)
|
williamr@4
|
676 |
void resize(size_type new_size, const value_type& __x = _Tp());
|
williamr@4
|
677 |
#else
|
williamr@4
|
678 |
void resize(size_type new_size, const value_type& __x);
|
williamr@4
|
679 |
#endif /*_STLP_DONT_SUP_DFLT_PARAM*/
|
williamr@4
|
680 |
|
williamr@4
|
681 |
#if defined (_STLP_DONT_SUP_DFLT_PARAM)
|
williamr@4
|
682 |
void resize(size_type new_size) { resize(new_size, _STLP_DEFAULT_CONSTRUCTED(_Tp)); }
|
williamr@4
|
683 |
#endif /*_STLP_DONT_SUP_DFLT_PARAM*/
|
williamr@4
|
684 |
|
williamr@4
|
685 |
void clear()
|
williamr@4
|
686 |
{ this->_M_erase_after(&this->_M_head._M_data, 0); }
|
williamr@4
|
687 |
|
williamr@4
|
688 |
public:
|
williamr@4
|
689 |
// Moves the range [__before_first + 1, __before_last + 1) to *this,
|
williamr@4
|
690 |
// inserting it immediately after __pos. This is constant time.
|
williamr@4
|
691 |
void splice_after(iterator __pos, _Self& __x,
|
williamr@4
|
692 |
iterator __before_first, iterator __before_last) {
|
williamr@4
|
693 |
if (__before_first != __before_last) {
|
williamr@4
|
694 |
if (this->get_allocator() == __x.get_allocator()) {
|
williamr@4
|
695 |
_STLP_PRIV _Sl_global_inst::__splice_after(__pos._M_node,
|
williamr@4
|
696 |
__before_first._M_node, __before_last._M_node);
|
williamr@4
|
697 |
}
|
williamr@4
|
698 |
else {
|
williamr@4
|
699 |
this->insert_after(__pos, iterator(__before_first._M_node->_M_next), iterator(__before_last._M_node->_M_next));
|
williamr@4
|
700 |
__x.erase_after(__before_first, ++__before_last);
|
williamr@4
|
701 |
}
|
williamr@4
|
702 |
}
|
williamr@4
|
703 |
}
|
williamr@4
|
704 |
|
williamr@4
|
705 |
// Moves the element that follows __prev to *this, inserting it immediately
|
williamr@4
|
706 |
// after __pos. This is constant time.
|
williamr@4
|
707 |
void splice_after(iterator __pos, _Self& __x, iterator __prev) {
|
williamr@4
|
708 |
if (this->get_allocator() == __x.get_allocator()) {
|
williamr@4
|
709 |
_STLP_PRIV _Sl_global_inst::__splice_after(__pos._M_node,
|
williamr@4
|
710 |
__prev._M_node, __prev._M_node->_M_next);
|
williamr@4
|
711 |
}
|
williamr@4
|
712 |
else {
|
williamr@4
|
713 |
this->insert_after(__pos, __STATIC_CAST(_Node*, __prev._M_node->_M_next)->_M_data);
|
williamr@4
|
714 |
__x.erase_after(__prev);
|
williamr@4
|
715 |
}
|
williamr@4
|
716 |
}
|
williamr@4
|
717 |
|
williamr@4
|
718 |
// Removes all of the elements from the list __x to *this, inserting
|
williamr@4
|
719 |
// them immediately after __pos. __x must not be *this. Complexity:
|
williamr@4
|
720 |
// linear in __x.size().
|
williamr@4
|
721 |
void splice_after(iterator __pos, _Self& __x) {
|
williamr@4
|
722 |
if (this->get_allocator() == __x.get_allocator())
|
williamr@4
|
723 |
_STLP_PRIV _Sl_global_inst::__splice_after(__pos._M_node, &__x._M_head._M_data);
|
williamr@4
|
724 |
else {
|
williamr@4
|
725 |
this->insert_after(__pos, __x.begin(), __x.end());
|
williamr@4
|
726 |
__x.clear();
|
williamr@4
|
727 |
}
|
williamr@4
|
728 |
}
|
williamr@4
|
729 |
|
williamr@4
|
730 |
// Linear in distance(begin(), __pos), and linear in __x.size().
|
williamr@4
|
731 |
void splice(iterator __pos, _Self& __x) {
|
williamr@4
|
732 |
if (__x._M_head._M_data._M_next) {
|
williamr@4
|
733 |
if (this->get_allocator() == __x.get_allocator()) {
|
williamr@4
|
734 |
_STLP_PRIV _Sl_global_inst::__splice_after(_STLP_PRIV _Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node),
|
williamr@4
|
735 |
&__x._M_head._M_data,
|
williamr@4
|
736 |
_STLP_PRIV _Sl_global_inst::__previous(&__x._M_head._M_data, 0));
|
williamr@4
|
737 |
}
|
williamr@4
|
738 |
else {
|
williamr@4
|
739 |
insert(__pos, __x.begin(), __x.end());
|
williamr@4
|
740 |
__x.clear();
|
williamr@4
|
741 |
}
|
williamr@4
|
742 |
}
|
williamr@4
|
743 |
}
|
williamr@4
|
744 |
|
williamr@4
|
745 |
// Linear in distance(begin(), __pos), and in distance(__x.begin(), __i).
|
williamr@4
|
746 |
void splice(iterator __pos, _Self& __x, iterator __i) {
|
williamr@4
|
747 |
if (this->get_allocator() == __x.get_allocator()) {
|
williamr@4
|
748 |
_STLP_PRIV _Sl_global_inst::__splice_after(_STLP_PRIV _Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node),
|
williamr@4
|
749 |
_STLP_PRIV _Sl_global_inst::__previous(&__x._M_head._M_data, __i._M_node),
|
williamr@4
|
750 |
__i._M_node);
|
williamr@4
|
751 |
}
|
williamr@4
|
752 |
else {
|
williamr@4
|
753 |
insert(__pos, *__i);
|
williamr@4
|
754 |
__x.erase(__i);
|
williamr@4
|
755 |
}
|
williamr@4
|
756 |
}
|
williamr@4
|
757 |
|
williamr@4
|
758 |
// Linear in distance(begin(), __pos), in distance(__x.begin(), __first),
|
williamr@4
|
759 |
// and in distance(__first, __last).
|
williamr@4
|
760 |
void splice(iterator __pos, _Self& __x, iterator __first, iterator __last) {
|
williamr@4
|
761 |
if (__first != __last) {
|
williamr@4
|
762 |
if (this->get_allocator() == __x.get_allocator()) {
|
williamr@4
|
763 |
_STLP_PRIV _Sl_global_inst::__splice_after(_STLP_PRIV _Sl_global_inst::__previous(&this->_M_head._M_data, __pos._M_node),
|
williamr@4
|
764 |
_STLP_PRIV _Sl_global_inst::__previous(&__x._M_head._M_data, __first._M_node),
|
williamr@4
|
765 |
_STLP_PRIV _Sl_global_inst::__previous(__first._M_node, __last._M_node));
|
williamr@4
|
766 |
}
|
williamr@4
|
767 |
else {
|
williamr@4
|
768 |
insert(__pos, __first, __last);
|
williamr@4
|
769 |
__x.erase(__first, __last);
|
williamr@4
|
770 |
}
|
williamr@4
|
771 |
}
|
williamr@4
|
772 |
}
|
williamr@4
|
773 |
|
williamr@4
|
774 |
public:
|
williamr@4
|
775 |
void reverse() {
|
williamr@4
|
776 |
if (this->_M_head._M_data._M_next)
|
williamr@4
|
777 |
this->_M_head._M_data._M_next = _STLP_PRIV _Sl_global_inst::__reverse(this->_M_head._M_data._M_next);
|
williamr@4
|
778 |
}
|
williamr@4
|
779 |
|
williamr@4
|
780 |
void remove(const _Tp& __val);
|
williamr@4
|
781 |
|
williamr@4
|
782 |
void unique() { _STLP_PRIV _Slist_unique(*this, equal_to<value_type>()); }
|
williamr@4
|
783 |
void merge(_Self& __x) { _STLP_PRIV _Slist_merge(*this, __x, less<value_type>()); }
|
williamr@4
|
784 |
void sort() { _STLP_PRIV _Slist_sort(*this, less<value_type>()); }
|
williamr@4
|
785 |
|
williamr@4
|
786 |
#if defined (_STLP_MEMBER_TEMPLATES)
|
williamr@4
|
787 |
template <class _Predicate>
|
williamr@4
|
788 |
void remove_if(_Predicate __pred) {
|
williamr@4
|
789 |
_Node_base* __cur = &this->_M_head._M_data;
|
williamr@4
|
790 |
while (__cur->_M_next) {
|
williamr@4
|
791 |
if (__pred(__STATIC_CAST(_Node*, __cur->_M_next)->_M_data))
|
williamr@4
|
792 |
this->_M_erase_after(__cur);
|
williamr@4
|
793 |
else
|
williamr@4
|
794 |
__cur = __cur->_M_next;
|
williamr@4
|
795 |
}
|
williamr@4
|
796 |
}
|
williamr@4
|
797 |
|
williamr@4
|
798 |
template <class _BinaryPredicate>
|
williamr@4
|
799 |
void unique(_BinaryPredicate __pred)
|
williamr@4
|
800 |
{ _STLP_PRIV _Slist_unique(*this, __pred); }
|
williamr@4
|
801 |
|
williamr@4
|
802 |
template <class _StrictWeakOrdering>
|
williamr@4
|
803 |
void merge(_Self& __x, _StrictWeakOrdering __comp)
|
williamr@4
|
804 |
{ _STLP_PRIV _Slist_merge(*this, __x, __comp); }
|
williamr@4
|
805 |
|
williamr@4
|
806 |
template <class _StrictWeakOrdering>
|
williamr@4
|
807 |
void sort(_StrictWeakOrdering __comp)
|
williamr@4
|
808 |
{ _STLP_PRIV _Slist_sort(*this, __comp); }
|
williamr@4
|
809 |
#endif /* _STLP_MEMBER_TEMPLATES */
|
williamr@4
|
810 |
};
|
williamr@4
|
811 |
|
williamr@4
|
812 |
#if defined (slist)
|
williamr@4
|
813 |
# undef slist
|
williamr@4
|
814 |
_STLP_MOVE_TO_STD_NAMESPACE
|
williamr@4
|
815 |
#endif
|
williamr@4
|
816 |
|
williamr@4
|
817 |
_STLP_END_NAMESPACE
|
williamr@4
|
818 |
|
williamr@4
|
819 |
#if !defined (_STLP_LINK_TIME_INSTANTIATION)
|
williamr@4
|
820 |
# include <stl/_slist.c>
|
williamr@4
|
821 |
#endif
|
williamr@4
|
822 |
|
williamr@4
|
823 |
#if defined (_STLP_USE_PTR_SPECIALIZATIONS)
|
williamr@4
|
824 |
# include <stl/pointers/_slist.h>
|
williamr@4
|
825 |
#endif
|
williamr@4
|
826 |
|
williamr@4
|
827 |
#if defined (_STLP_DEBUG)
|
williamr@4
|
828 |
# include <stl/debug/_slist.h>
|
williamr@4
|
829 |
#endif
|
williamr@4
|
830 |
|
williamr@4
|
831 |
_STLP_BEGIN_NAMESPACE
|
williamr@4
|
832 |
|
williamr@4
|
833 |
template <class _Tp, class _Alloc>
|
williamr@4
|
834 |
inline bool _STLP_CALL
|
williamr@4
|
835 |
operator == (const slist<_Tp,_Alloc>& _SL1, const slist<_Tp,_Alloc>& _SL2) {
|
williamr@4
|
836 |
typedef typename slist<_Tp,_Alloc>::const_iterator const_iterator;
|
williamr@4
|
837 |
const_iterator __end1 = _SL1.end();
|
williamr@4
|
838 |
const_iterator __end2 = _SL2.end();
|
williamr@4
|
839 |
|
williamr@4
|
840 |
const_iterator __i1 = _SL1.begin();
|
williamr@4
|
841 |
const_iterator __i2 = _SL2.begin();
|
williamr@4
|
842 |
while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2) {
|
williamr@4
|
843 |
++__i1;
|
williamr@4
|
844 |
++__i2;
|
williamr@4
|
845 |
}
|
williamr@4
|
846 |
return __i1 == __end1 && __i2 == __end2;
|
williamr@4
|
847 |
}
|
williamr@4
|
848 |
|
williamr@4
|
849 |
#define _STLP_EQUAL_OPERATOR_SPECIALIZED
|
williamr@4
|
850 |
#define _STLP_TEMPLATE_HEADER template <class _Tp, class _Alloc>
|
williamr@4
|
851 |
#define _STLP_TEMPLATE_CONTAINER slist<_Tp, _Alloc>
|
williamr@4
|
852 |
#include <stl/_relops_cont.h>
|
williamr@4
|
853 |
#undef _STLP_TEMPLATE_CONTAINER
|
williamr@4
|
854 |
#undef _STLP_TEMPLATE_HEADER
|
williamr@4
|
855 |
#undef _STLP_EQUAL_OPERATOR_SPECIALIZED
|
williamr@4
|
856 |
|
williamr@4
|
857 |
#if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
|
williamr@4
|
858 |
template <class _Tp, class _Alloc>
|
williamr@4
|
859 |
struct __move_traits<slist<_Tp, _Alloc> > {
|
williamr@4
|
860 |
typedef __stlp_movable implemented;
|
williamr@4
|
861 |
typedef typename __move_traits<_Alloc>::complete complete;
|
williamr@4
|
862 |
};
|
williamr@4
|
863 |
|
williamr@4
|
864 |
// Specialization of insert_iterator so that insertions will be constant
|
williamr@4
|
865 |
// time rather than linear time.
|
williamr@4
|
866 |
template <class _Tp, class _Alloc>
|
williamr@4
|
867 |
class insert_iterator<slist<_Tp, _Alloc> > {
|
williamr@4
|
868 |
protected:
|
williamr@4
|
869 |
typedef slist<_Tp, _Alloc> _Container;
|
williamr@4
|
870 |
_Container* _M_container;
|
williamr@4
|
871 |
typename _Container::iterator _M_iter;
|
williamr@4
|
872 |
public:
|
williamr@4
|
873 |
typedef _Container container_type;
|
williamr@4
|
874 |
typedef output_iterator_tag iterator_category;
|
williamr@4
|
875 |
typedef void value_type;
|
williamr@4
|
876 |
typedef void difference_type;
|
williamr@4
|
877 |
typedef void pointer;
|
williamr@4
|
878 |
typedef void reference;
|
williamr@4
|
879 |
|
williamr@4
|
880 |
insert_iterator(_Container& __x, typename _Container::iterator __i)
|
williamr@4
|
881 |
: _M_container(&__x) {
|
williamr@4
|
882 |
if (__i == __x.begin())
|
williamr@4
|
883 |
_M_iter = __x.before_begin();
|
williamr@4
|
884 |
else
|
williamr@4
|
885 |
_M_iter = __x.previous(__i);
|
williamr@4
|
886 |
}
|
williamr@4
|
887 |
|
williamr@4
|
888 |
insert_iterator<_Container>&
|
williamr@4
|
889 |
operator = (const typename _Container::value_type& __val) {
|
williamr@4
|
890 |
_M_iter = _M_container->insert_after(_M_iter, __val);
|
williamr@4
|
891 |
return *this;
|
williamr@4
|
892 |
}
|
williamr@4
|
893 |
|
williamr@4
|
894 |
insert_iterator<_Container>& operator*() { return *this; }
|
williamr@4
|
895 |
insert_iterator<_Container>& operator++() { return *this; }
|
williamr@4
|
896 |
insert_iterator<_Container>& operator++(int) { return *this; }
|
williamr@4
|
897 |
};
|
williamr@4
|
898 |
#endif /* _STLP_CLASS_PARTIAL_SPECIALIZATION */
|
williamr@4
|
899 |
|
williamr@4
|
900 |
_STLP_END_NAMESPACE
|
williamr@4
|
901 |
|
williamr@4
|
902 |
#endif /* _STLP_INTERNAL_SLIST_H */
|
williamr@4
|
903 |
|
williamr@4
|
904 |
// Local Variables:
|
williamr@4
|
905 |
// mode:C++
|
williamr@4
|
906 |
// End:
|