[CMAKE]
[reactos.git] / lib / 3rdparty / stlport / stlport / stl / pointers / _slist.h
1 /*
2 * Copyright (c) 2003
3 * Francois Dumont
4 *
5 * This material is provided "as is", with absolutely no warranty expressed
6 * or implied. Any use is at your own risk.
7 *
8 * Permission to use or copy this software for any purpose is hereby granted
9 * without fee, provided the above notices are retained on all copies.
10 * Permission to modify the code and to distribute modified code is granted,
11 * provided the above notices are retained, and a notice that the code was
12 * modified is included with the above copyright notice.
13 *
14 */
15
16 /* NOTE: This is an internal header file, included by other STL headers.
17 * You should not attempt to use it directly.
18 */
19
20 #ifndef _STLP_SPECIALIZED_SLIST_H
21 #define _STLP_SPECIALIZED_SLIST_H
22
23 #ifndef _STLP_POINTERS_SPEC_TOOLS_H
24 # include <stl/pointers/_tools.h>
25 #endif
26
27 _STLP_BEGIN_NAMESPACE
28
29 #define SLIST_IMPL _STLP_PTR_IMPL_NAME(slist)
30
31 #if defined (__BORLANDC__) || defined (__DMC__)
32 # define typename
33 #endif
34
35 #if defined (_STLP_USE_TEMPLATE_EXPORT) && !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
36 _STLP_MOVE_TO_PRIV_NAMESPACE
37
38 _STLP_EXPORT_TEMPLATE_CLASS _Slist_node<void*>;
39 typedef _Slist_node<void*> _VoidPtrSNode;
40 _STLP_EXPORT_TEMPLATE_CLASS _STLP_alloc_proxy<_Slist_node_base, _VoidPtrSNode, allocator<_VoidPtrSNode> >;
41 _STLP_EXPORT_TEMPLATE_CLASS _Slist_base<void*, allocator<void*> >;
42 _STLP_EXPORT_TEMPLATE_CLASS SLIST_IMPL<void*, allocator<void*> >;
43
44 _STLP_MOVE_TO_STD_NAMESPACE
45 #endif
46
47 #if defined (_STLP_DEBUG)
48 # define slist _STLP_NON_DBG_NAME(slist)
49 _STLP_MOVE_TO_PRIV_NAMESPACE
50 #endif
51
52 template <class _Tp, _STLP_DFL_TMPL_PARAM(_Alloc, allocator<_Tp>) >
53 class slist
54 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (slist)
55 : public __stlport_class<slist<_Tp, _Alloc> >
56 #endif
57 {
58 typedef _STLP_TYPENAME _STLP_PRIV _StorageType<_Tp>::_Type _StorageType;
59 typedef typename _Alloc_traits<_StorageType, _Alloc>::allocator_type _StorageTypeAlloc;
60 typedef _STLP_PRIV SLIST_IMPL<_StorageType, _StorageTypeAlloc> _Base;
61 typedef typename _Base::iterator _BaseIte;
62 typedef typename _Base::const_iterator _BaseConstIte;
63 typedef slist<_Tp, _Alloc> _Self;
64 typedef _STLP_PRIV _CastTraits<_StorageType, _Tp> cast_traits;
65 typedef _STLP_PRIV _Slist_node_base _Node_base;
66
67 public:
68 typedef _Tp value_type;
69 typedef value_type* pointer;
70 typedef const value_type* const_pointer;
71 typedef value_type& reference;
72 typedef const value_type& const_reference;
73 typedef size_t size_type;
74 typedef ptrdiff_t difference_type;
75 typedef forward_iterator_tag _Iterator_category;
76
77 typedef _STLP_PRIV _Slist_iterator<value_type, _Nonconst_traits<value_type> > iterator;
78 typedef _STLP_PRIV _Slist_iterator<value_type, _Const_traits<value_type> > const_iterator;
79
80 _STLP_FORCE_ALLOCATORS(value_type, _Alloc)
81 typedef typename _Alloc_traits<value_type, _Alloc>::allocator_type allocator_type;
82
83 public:
84 allocator_type get_allocator() const
85 { return _STLP_CONVERT_ALLOCATOR(_M_impl.get_allocator(), value_type); }
86
87 explicit slist(const allocator_type& __a = allocator_type())
88 : _M_impl(_STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
89
90 #if !defined(_STLP_DONT_SUP_DFLT_PARAM)
91 explicit slist(size_type __n, const value_type& __x = _STLP_DEFAULT_CONSTRUCTED(value_type),
92 #else
93 slist(size_type __n, const value_type& __x,
94 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
95 const allocator_type& __a = allocator_type())
96 : _M_impl(__n, cast_traits::to_storage_type_cref(__x), _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
97
98 #if defined(_STLP_DONT_SUP_DFLT_PARAM)
99 explicit slist(size_type __n) : _M_impl(__n) {}
100 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
101
102 #if defined (_STLP_MEMBER_TEMPLATES)
103 // We don't need any dispatching tricks here, because _M_insert_after_range
104 // already does them.
105 template <class _InputIterator>
106 slist(_InputIterator __first, _InputIterator __last,
107 const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
108 # if !defined (_STLP_USE_ITERATOR_WRAPPER)
109 : _M_impl(__first, __last, _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
110 # else
111 : _M_impl(_STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {
112 insert_after(before_begin(), __first, __last);
113 }
114 # endif
115 # if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
116 // VC++ needs this crazyness
117 template <class _InputIterator>
118 slist(_InputIterator __first, _InputIterator __last)
119 # if !defined (_STLP_USE_WRAPPER_ITERATOR)
120 : _M_impl(__first, __last) {}
121 # else
122 { insert_after(before_begin(), __first, __last); }
123 # endif
124 # endif
125 #else /* _STLP_MEMBER_TEMPLATES */
126 slist(const_iterator __first, const_iterator __last,
127 const allocator_type& __a = allocator_type() )
128 : _M_impl(_BaseConstIte(__first._M_node), _BaseConstIte(__last._M_node),
129 _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
130 slist(const value_type* __first, const value_type* __last,
131 const allocator_type& __a = allocator_type())
132 : _M_impl(cast_traits::to_storage_type_cptr(__first), cast_traits::to_storage_type_cptr(__last),
133 _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
134 #endif /* _STLP_MEMBER_TEMPLATES */
135
136 slist(const _Self& __x) : _M_impl(__x._M_impl) {}
137
138 #if !defined (_STLP_NO_MOVE_SEMANTIC)
139 slist(__move_source<_Self> src)
140 : _M_impl(__move_source<_Base>(src.get()._M_impl)) {}
141 #endif
142
143 _Self& operator= (const _Self& __x) { _M_impl = __x._M_impl; return *this; }
144
145 void assign(size_type __n, const value_type& __val)
146 { _M_impl.assign(__n, cast_traits::to_storage_type_cref(__val)); }
147
148 #if defined (_STLP_MEMBER_TEMPLATES)
149 # if defined (_STLP_USE_ITERATOR_WRAPPER)
150 private:
151 template <class _Integer>
152 void _M_assign_dispatch(_Integer __n, _Integer __val,
153 const __true_type&)
154 { _M_impl.assign(__n, __val); }
155
156 template <class _InputIterator>
157 void _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
158 const __false_type&) {
159 _M_impl.assign(_STLP_TYPENAME _STLP_PRIV _IteWrapper<_StorageType, _Tp, _InputIterator>::_Ite(__first),
160 _STLP_TYPENAME _STLP_PRIV _IteWrapper<_StorageType, _Tp, _InputIterator>::_Ite(__last));
161 }
162
163 public:
164 # endif
165
166 template <class _InputIterator>
167 void assign(_InputIterator __first, _InputIterator __last) {
168 # if defined (_STLP_USE_ITERATOR_WRAPPER)
169 typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
170 _M_assign_dispatch(__first, __last, _Integral());
171 # else
172 _M_impl.assign(__first, __last);
173 # endif
174 }
175 #else
176 void assign(const value_type *__first, const value_type *__last) {
177 _M_impl.assign(cast_traits::to_storage_type_cptr(__first),
178 cast_traits::to_storage_type_cptr(__last));
179 }
180 void assign(const_iterator __first, const_iterator __last) {
181 _M_impl.assign(_BaseConstIte(__first._M_node),
182 _BaseConstIte(__last._M_node));
183 }
184 #endif /* _STLP_MEMBER_TEMPLATES */
185
186 iterator before_begin() { return iterator(_M_impl.before_begin()._M_node); }
187 const_iterator before_begin() const { return const_iterator(const_cast<_Node_base*>(_M_impl.before_begin()._M_node)); }
188
189 iterator begin() { return iterator(_M_impl.begin()._M_node); }
190 const_iterator begin() const { return const_iterator(const_cast<_Node_base*>(_M_impl.begin()._M_node));}
191
192 iterator end() { return iterator(_M_impl.end()._M_node); }
193 const_iterator end() const { return iterator(_M_impl.end()._M_node); }
194
195 size_type size() const { return _M_impl.size(); }
196 size_type max_size() const { return _M_impl.max_size(); }
197 bool empty() const { return _M_impl.empty(); }
198
199 void swap(_Self& __x) { _M_impl.swap(__x._M_impl); }
200 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
201 void _M_swap_workaround(_Self& __x) { swap(__x); }
202 #endif
203
204 public:
205 reference front() { return *begin(); }
206 const_reference front() const { return *begin(); }
207 #if !defined(_STLP_DONT_SUP_DFLT_PARAM) && !defined(_STLP_NO_ANACHRONISMS)
208 void push_front(const value_type& __x = _STLP_DEFAULT_CONSTRUCTED(value_type))
209 #else
210 void push_front(const value_type& __x)
211 #endif /*!_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
212 { _M_impl.push_front(cast_traits::to_storage_type_cref(__x)); }
213
214 # if defined(_STLP_DONT_SUP_DFLT_PARAM) && !defined(_STLP_NO_ANACHRONISMS)
215 void push_front() { _M_impl.push_front();}
216 # endif /*_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
217
218 void pop_front() { _M_impl.pop_front(); }
219
220 iterator previous(const_iterator __pos)
221 { return iterator(_M_impl.previous(_BaseConstIte(__pos._M_node))._M_node); }
222 const_iterator previous(const_iterator __pos) const
223 { return const_iterator(const_cast<_Node_base*>(_M_impl.previous(_BaseConstIte(__pos._M_node))._M_node)); }
224
225 #if !defined(_STLP_DONT_SUP_DFLT_PARAM)
226 iterator insert_after(iterator __pos, const value_type& __x = _STLP_DEFAULT_CONSTRUCTED(value_type))
227 #else
228 iterator insert_after(iterator __pos, const value_type& __x)
229 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
230 { return iterator(_M_impl.insert_after(_BaseIte(__pos._M_node),
231 cast_traits::to_storage_type_cref(__x))._M_node); }
232
233 #if defined(_STLP_DONT_SUP_DFLT_PARAM)
234 iterator insert_after(iterator __pos)
235 { return iterator(_M_impl.insert_after(_BaseIte(__pos._M_node))._M_node);}
236 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
237
238 void insert_after(iterator __pos, size_type __n, const value_type& __x)
239 { _M_impl.insert_after(_BaseIte(__pos._M_node), __n, cast_traits::to_storage_type_cref(__x)); }
240
241 #if defined (_STLP_MEMBER_TEMPLATES)
242 # if defined (_STLP_USE_ITERATOR_WRAPPER)
243 private:
244 template <class _Integer>
245 void _M_insert_after_dispatch(iterator __pos, _Integer __n, _Integer __val,
246 const __true_type&) {
247 _M_impl.insert_after(_BaseIte(__pos._M_node), __n, __val);
248 }
249
250 template <class _InputIterator>
251 void _M_insert_after_dispatch(iterator __pos,
252 _InputIterator __first, _InputIterator __last,
253 const __false_type&) {
254 _M_impl.insert_after(_BaseIte(__pos._M_node),
255 _STLP_TYPENAME _STLP_PRIV _IteWrapper<_StorageType, _Tp, _InputIterator>::_Ite(__first),
256 _STLP_TYPENAME _STLP_PRIV _IteWrapper<_StorageType, _Tp, _InputIterator>::_Ite(__last));
257 }
258
259 public:
260 # endif
261
262 template <class _InputIterator>
263 void insert_after(iterator __pos, _InputIterator __first, _InputIterator __last) {
264 # if defined (_STLP_USE_ITERATOR_WRAPPER)
265 // Check whether it's an integral type. If so, it's not an iterator.
266 typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
267 _M_insert_after_dispatch(__pos, __first, __last, _Integral());
268 # else
269 _M_impl.insert_after(_BaseIte(__pos._M_node), __first, __last);
270 # endif
271 }
272
273 #else /* _STLP_MEMBER_TEMPLATES */
274 void insert_after(iterator __pos,
275 const_iterator __first, const_iterator __last)
276 { _M_impl.insert_after(_BaseIte(__pos._M_node),
277 _BaseConstIte(__first._M_node), _BaseConstIte(__last._M_node)); }
278 void insert_after(iterator __pos,
279 const value_type* __first, const value_type* __last) {
280 _M_impl.insert_after(_BaseIte(__pos._M_node),
281 cast_traits::to_storage_type_cptr(__first),
282 cast_traits::to_storage_type_cptr(__last));
283 }
284 #endif /* _STLP_MEMBER_TEMPLATES */
285
286 #if !defined(_STLP_DONT_SUP_DFLT_PARAM)
287 iterator insert(iterator __pos, const value_type& __x = _STLP_DEFAULT_CONSTRUCTED(value_type))
288 #else
289 iterator insert(iterator __pos, const value_type& __x)
290 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
291 { return iterator(_M_impl.insert(_BaseIte(__pos._M_node),
292 cast_traits::to_storage_type_cref(__x))._M_node); }
293
294 #if defined(_STLP_DONT_SUP_DFLT_PARAM)
295 iterator insert(iterator __pos)
296 { return iterator(_M_impl.insert(_BaseIte(__pos._M_node))._M_node); }
297 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
298
299 void insert(iterator __pos, size_type __n, const value_type& __x)
300 { _M_impl.insert(_BaseIte(__pos._M_node), __n, cast_traits::to_storage_type_cref(__x)); }
301
302 #if defined (_STLP_MEMBER_TEMPLATES)
303 # if defined (_STLP_USE_ITERATOR_WRAPPER)
304 private:
305 template <class _Integer>
306 void _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __val,
307 const __true_type&) {
308 _M_impl.insert(_BaseIte(__pos._M_node), __n, __val);
309 }
310
311 template <class _InputIterator>
312 void _M_insert_dispatch(iterator __pos,
313 _InputIterator __first, _InputIterator __last,
314 const __false_type&) {
315 _M_impl.insert(_BaseIte(__pos._M_node), _STLP_TYPENAME _STLP_PRIV _IteWrapper<_StorageType, _Tp, _InputIterator>::_Ite(__first),
316 _STLP_TYPENAME _STLP_PRIV _IteWrapper<_StorageType, _Tp, _InputIterator>::_Ite(__last));
317 }
318
319 public:
320 # endif
321
322 template <class _InputIterator>
323 void insert(iterator __pos, _InputIterator __first, _InputIterator __last) {
324 # if defined (_STLP_USE_ITERATOR_WRAPPER)
325 // Check whether it's an integral type. If so, it's not an iterator.
326 typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
327 _M_insert_dispatch(__pos, __first, __last, _Integral());
328 # else
329 _M_impl.insert(_BaseIte(__pos._M_node), __first, __last);
330 # endif
331 }
332
333 #else /* _STLP_MEMBER_TEMPLATES */
334 void insert(iterator __pos, const_iterator __first, const_iterator __last)
335 { _M_impl.insert(_BaseIte(__pos._M_node), _BaseConstIte(__first._M_node), _BaseConstIte(__last._M_node)); }
336 void insert(iterator __pos, const value_type* __first, const value_type* __last)
337 { _M_impl.insert(_BaseIte(__pos._M_node), cast_traits::to_storage_type_cptr(__first),
338 cast_traits::to_storage_type_cptr(__last)); }
339 #endif /* _STLP_MEMBER_TEMPLATES */
340
341 iterator erase_after(iterator __pos)
342 { return iterator(_M_impl.erase_after(_BaseIte(__pos._M_node))._M_node); }
343 iterator erase_after(iterator __before_first, iterator __last)
344 { return iterator(_M_impl.erase_after(_BaseIte(__before_first._M_node),
345 _BaseIte(__last._M_node))._M_node); }
346
347 iterator erase(iterator __pos)
348 { return iterator(_M_impl.erase(_BaseIte(__pos._M_node))._M_node); }
349 iterator erase(iterator __first, iterator __last)
350 { return iterator(_M_impl.erase(_BaseIte(__first._M_node), _BaseIte(__last._M_node))._M_node); }
351
352 #if !defined(_STLP_DONT_SUP_DFLT_PARAM)
353 void resize(size_type __new_size, const value_type& __x = _STLP_DEFAULT_CONSTRUCTED(value_type))
354 #else
355 void resize(size_type __new_size, const value_type& __x)
356 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
357 { _M_impl.resize(__new_size, cast_traits::to_storage_type_cref(__x));}
358
359 #if defined(_STLP_DONT_SUP_DFLT_PARAM)
360 void resize(size_type __new_size) { _M_impl.resize(__new_size); }
361 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
362
363 void clear() { _M_impl.clear(); }
364
365 void splice_after(iterator __pos, _Self& __x,
366 iterator __before_first, iterator __before_last)
367 { _M_impl.splice_after(_BaseIte(__pos._M_node), __x._M_impl,
368 _BaseIte(__before_first._M_node), _BaseIte(__before_last._M_node)); }
369 void splice_after(iterator __pos, _Self& __x, iterator __prev)
370 { _M_impl.splice_after(_BaseIte(__pos._M_node), __x._M_impl, _BaseIte(__prev._M_node)); }
371 void splice_after(iterator __pos, _Self& __x)
372 { _M_impl.splice_after(_BaseIte(__pos._M_node), __x._M_impl); }
373 void splice(iterator __pos, _Self& __x)
374 { _M_impl.splice(_BaseIte(__pos._M_node), __x._M_impl); }
375 void splice(iterator __pos, _Self& __x, iterator __i)
376 { _M_impl.splice(_BaseIte(__pos._M_node), __x._M_impl, _BaseIte(__i._M_node)); }
377 void splice(iterator __pos, _Self& __x, iterator __first, iterator __last)
378 { _M_impl.splice(_BaseIte(__pos._M_node), __x._M_impl,
379 _BaseIte(__first._M_node), _BaseIte(__last._M_node)); }
380
381 void reverse() { _M_impl.reverse(); }
382
383 void remove(const value_type& __val) { _M_impl.remove(cast_traits::to_storage_type_cref(__val)); }
384 void unique() { _M_impl.unique(); }
385 void merge(_Self& __x) { _M_impl.merge(__x._M_impl); }
386 void sort() {_M_impl.sort(); }
387
388 #ifdef _STLP_MEMBER_TEMPLATES
389 template <class _Predicate>
390 void remove_if(_Predicate __pred)
391 { _M_impl.remove_if(_STLP_PRIV _UnaryPredWrapper<_StorageType, _Tp, _Predicate>(__pred)); }
392
393 template <class _BinaryPredicate>
394 void unique(_BinaryPredicate __pred)
395 { _M_impl.unique(_STLP_PRIV _BinaryPredWrapper<_StorageType, _Tp, _BinaryPredicate>(__pred)); }
396
397 template <class _StrictWeakOrdering>
398 void merge(_Self& __x, _StrictWeakOrdering __comp)
399 { _M_impl.merge(__x._M_impl, _STLP_PRIV _BinaryPredWrapper<_StorageType, _Tp, _StrictWeakOrdering>(__comp)); }
400
401 template <class _StrictWeakOrdering>
402 void sort(_StrictWeakOrdering __comp)
403 { _M_impl.sort(_STLP_PRIV _BinaryPredWrapper<_StorageType, _Tp, _StrictWeakOrdering>(__comp)); }
404 #endif /* _STLP_MEMBER_TEMPLATES */
405
406 private:
407 _Base _M_impl;
408 };
409
410 #if defined (slist)
411 # undef slist
412 _STLP_MOVE_TO_STD_NAMESPACE
413 #endif
414
415 #undef SLIST_IMPL
416
417 #if defined (__BORLANDC__) || defined (__DMC__)
418 # undef typename
419 #endif
420
421 _STLP_END_NAMESPACE
422
423 #endif /* _STLP_SPECIALIZED_SLIST_H */
424
425 // Local Variables:
426 // mode:C++
427 // End: