5 * This material is provided "as is", with absolutely no warranty expressed
6 * or implied. Any use is at your own risk.
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.
16 /* NOTE: This is an internal header file, included by other STL headers.
17 * You should not attempt to use it directly.
20 #ifndef _STLP_SPECIALIZED_SLIST_H
21 #define _STLP_SPECIALIZED_SLIST_H
23 #ifndef _STLP_POINTERS_SPEC_TOOLS_H
24 # include <stl/pointers/_tools.h>
29 #define SLIST_IMPL _STLP_PTR_IMPL_NAME(slist)
31 #if defined (__BORLANDC__) || defined (__DMC__)
35 #if defined (_STLP_USE_TEMPLATE_EXPORT) && !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
36 _STLP_MOVE_TO_PRIV_NAMESPACE
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*> >;
44 _STLP_MOVE_TO_STD_NAMESPACE
47 #if defined (_STLP_DEBUG)
48 # define slist _STLP_NON_DBG_NAME(slist)
49 _STLP_MOVE_TO_PRIV_NAMESPACE
52 template <class _Tp
, _STLP_DFL_TMPL_PARAM(_Alloc
, allocator
<_Tp
>) >
54 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (slist)
55 : public __stlport_class
<slist
<_Tp
, _Alloc
> >
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
;
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
;
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
;
80 _STLP_FORCE_ALLOCATORS(value_type
, _Alloc
)
81 typedef typename _Alloc_traits
<value_type
, _Alloc
>::allocator_type allocator_type
;
84 allocator_type
get_allocator() const
85 { return _STLP_CONVERT_ALLOCATOR(_M_impl
.get_allocator(), value_type
); }
87 explicit slist(const allocator_type
& __a
= allocator_type())
88 : _M_impl(_STLP_CONVERT_ALLOCATOR(__a
, _StorageType
)) {}
90 #if !defined(_STLP_DONT_SUP_DFLT_PARAM)
91 explicit slist(size_type __n
, const value_type
& __x
= _STLP_DEFAULT_CONSTRUCTED(value_type
),
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
)) {}
98 #if defined(_STLP_DONT_SUP_DFLT_PARAM)
99 explicit slist(size_type __n
) : _M_impl(__n
) {}
100 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
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
)) {}
111 : _M_impl(_STLP_CONVERT_ALLOCATOR(__a
, _StorageType
)) {
112 insert_after(before_begin(), __first
, __last
);
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
) {}
122 { insert_after(before_begin(), __first
, __last
); }
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 */
136 slist(const _Self
& __x
) : _M_impl(__x
._M_impl
) {}
138 #if !defined (_STLP_NO_MOVE_SEMANTIC)
139 slist(__move_source
<_Self
> src
)
140 : _M_impl(__move_source
<_Base
>(src
.get()._M_impl
)) {}
143 _Self
& operator= (const _Self
& __x
) { _M_impl
= __x
._M_impl
; return *this; }
145 void assign(size_type __n
, const value_type
& __val
)
146 { _M_impl
.assign(__n
, cast_traits::to_storage_type_cref(__val
)); }
148 #if defined (_STLP_MEMBER_TEMPLATES)
149 # if defined (_STLP_USE_ITERATOR_WRAPPER)
151 template <class _Integer
>
152 void _M_assign_dispatch(_Integer __n
, _Integer __val
,
154 { _M_impl
.assign(__n
, __val
); }
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
));
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());
172 _M_impl
.assign(__first
, __last
);
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
));
180 void assign(const_iterator __first
, const_iterator __last
) {
181 _M_impl
.assign(_BaseConstIte(__first
._M_node
),
182 _BaseConstIte(__last
._M_node
));
184 #endif /* _STLP_MEMBER_TEMPLATES */
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
)); }
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
));}
192 iterator
end() { return iterator(_M_impl
.end()._M_node
); }
193 const_iterator
end() const { return iterator(_M_impl
.end()._M_node
); }
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(); }
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
); }
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
))
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
)); }
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*/
218 void pop_front() { _M_impl
.pop_front(); }
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
)); }
225 #if !defined(_STLP_DONT_SUP_DFLT_PARAM)
226 iterator
insert_after(iterator __pos
, const value_type
& __x
= _STLP_DEFAULT_CONSTRUCTED(value_type
))
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
); }
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*/
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
)); }
241 #if defined (_STLP_MEMBER_TEMPLATES)
242 # if defined (_STLP_USE_ITERATOR_WRAPPER)
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
);
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
));
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());
269 _M_impl
.insert_after(_BaseIte(__pos
._M_node
), __first
, __last
);
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
));
284 #endif /* _STLP_MEMBER_TEMPLATES */
286 #if !defined(_STLP_DONT_SUP_DFLT_PARAM)
287 iterator
insert(iterator __pos
, const value_type
& __x
= _STLP_DEFAULT_CONSTRUCTED(value_type
))
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
); }
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*/
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
)); }
302 #if defined (_STLP_MEMBER_TEMPLATES)
303 # if defined (_STLP_USE_ITERATOR_WRAPPER)
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
);
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
));
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());
329 _M_impl
.insert(_BaseIte(__pos
._M_node
), __first
, __last
);
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 */
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
); }
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
); }
352 #if !defined(_STLP_DONT_SUP_DFLT_PARAM)
353 void resize(size_type __new_size
, const value_type
& __x
= _STLP_DEFAULT_CONSTRUCTED(value_type
))
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
));}
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*/
363 void clear() { _M_impl
.clear(); }
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
)); }
381 void reverse() { _M_impl
.reverse(); }
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(); }
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
)); }
393 template <class _BinaryPredicate
>
394 void unique(_BinaryPredicate __pred
)
395 { _M_impl
.unique(_STLP_PRIV _BinaryPredWrapper
<_StorageType
, _Tp
, _BinaryPredicate
>(__pred
)); }
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
)); }
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 */
412 _STLP_MOVE_TO_STD_NAMESPACE
417 #if defined (__BORLANDC__) || defined (__DMC__)
423 #endif /* _STLP_SPECIALIZED_SLIST_H */