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_PTR_SPECIALIZED_LIST_H
21 #define _STLP_PTR_SPECIALIZED_LIST_H
23 #ifndef _STLP_POINTERS_SPEC_TOOLS_H
24 # include <stl/pointers/_tools.h>
29 #define LIST_IMPL _STLP_PTR_IMPL_NAME(list)
31 #if defined (_STLP_USE_TEMPLATE_EXPORT) && !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
33 _STLP_MOVE_TO_PRIV_NAMESPACE
35 _STLP_EXPORT_TEMPLATE_CLASS _List_node<void*>;
37 _STLP_MOVE_TO_STD_NAMESPACE
39 _STLP_EXPORT_TEMPLATE_CLASS allocator<_STLP_PRIV _List_node<void*> >;
41 _STLP_MOVE_TO_PRIV_NAMESPACE
43 _STLP_EXPORT_TEMPLATE_CLASS _STLP_alloc_proxy<_List_node_base, _List_node<void*>, allocator<_List_node<void*> > >;
44 _STLP_EXPORT_TEMPLATE_CLASS _List_base<void*, allocator<void*> >;
45 _STLP_EXPORT_TEMPLATE_CLASS LIST_IMPL<void*, allocator<void*> >;
47 _STLP_MOVE_TO_STD_NAMESPACE
50 #if defined (_STLP_DEBUG)
51 # define list _STLP_NON_DBG_NAME(list)
52 _STLP_MOVE_TO_PRIV_NAMESPACE
55 template <class _Tp, _STLP_DEFAULT_ALLOCATOR_SELECT(_Tp) >
57 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (list)
58 : public __stlport_class<list<_Tp, _Alloc> >
61 typedef typename _STLP_PRIV _StorageType<_Tp>::_Type _StorageType;
62 typedef typename _Alloc_traits<_StorageType, _Alloc>::allocator_type _StorageTypeAlloc;
63 typedef _STLP_PRIV LIST_IMPL<_StorageType, _StorageTypeAlloc> _Base;
64 typedef typename _Base::iterator _BaseIte;
65 typedef typename _Base::const_iterator _BaseConstIte;
66 typedef _STLP_PRIV _CastTraits<_StorageType, _Tp> cast_traits;
67 typedef list<_Tp, _Alloc> _Self;
70 typedef _Tp value_type;
71 typedef value_type* pointer;
72 typedef const value_type* const_pointer;
73 typedef value_type& reference;
74 typedef const value_type& const_reference;
75 typedef size_t size_type;
76 typedef ptrdiff_t difference_type;
77 _STLP_FORCE_ALLOCATORS(value_type, _Alloc)
78 typedef typename _Alloc_traits<value_type, _Alloc>::allocator_type allocator_type;
79 typedef bidirectional_iterator_tag _Iterator_category;
81 typedef _STLP_PRIV _List_iterator<value_type, _Nonconst_traits<value_type> > iterator;
82 typedef _STLP_PRIV _List_iterator<value_type, _Const_traits<value_type> > const_iterator;
84 _STLP_DECLARE_BIDIRECTIONAL_REVERSE_ITERATORS;
86 allocator_type get_allocator() const
87 { return _STLP_CONVERT_ALLOCATOR(_M_impl.get_allocator(), value_type); }
89 # if !(defined(__MRC__)||(defined(__SC__) && !defined(__DMC__)))
92 list(const allocator_type& __a = allocator_type())
93 : _M_impl(_STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
95 #if !defined(_STLP_DONT_SUP_DFLT_PARAM)
96 explicit list(size_type __n, const value_type& __val = _STLP_DEFAULT_CONSTRUCTED(value_type),
98 list(size_type __n, const value_type& __val,
99 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
100 const allocator_type& __a = allocator_type())
101 : _M_impl(__n, cast_traits::to_storage_type_cref(__val),
102 _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
104 #if defined(_STLP_DONT_SUP_DFLT_PARAM)
105 explicit list(size_type __n)
107 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
109 #if defined (_STLP_MEMBER_TEMPLATES)
110 template <class _InputIterator>
111 list(_InputIterator __first, _InputIterator __last,
112 const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
113 # if !defined (_STLP_USE_ITERATOR_WRAPPER)
114 : _M_impl(__first, __last, _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
116 : _M_impl(_STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {
117 insert(begin(), __first, __last);
121 # if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
122 template <class _InputIterator>
123 list(_InputIterator __first, _InputIterator __last)
124 # if !defined (_STLP_USE_WRAPPER_ITERATOR)
125 : _M_impl(__first, __last) {}
127 { insert(begin(), __first, __last); }
131 #else /* _STLP_MEMBER_TEMPLATES */
133 list(const value_type *__first, const value_type *__last,
134 const allocator_type& __a = allocator_type())
135 : _M_impl(cast_traits::to_storage_type_cptr(__first),
136 cast_traits::to_storage_type_cptr(__last),
137 _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
138 list(const_iterator __first, const_iterator __last,
139 const allocator_type& __a = allocator_type())
140 : _M_impl(_BaseConstIte(__first._M_node), _BaseConstIte(__last._M_node),
141 _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
143 #endif /* _STLP_MEMBER_TEMPLATES */
145 list(const _Self& __x) : _M_impl(__x._M_impl) {}
147 list(__move_source<_Self> src)
148 : _M_impl(__move_source<_Base>(src.get()._M_impl)) {}
150 iterator begin() { return iterator(_M_impl.begin()._M_node); }
151 const_iterator begin() const { return const_iterator(_M_impl.begin()._M_node); }
153 iterator end() { return iterator(_M_impl.end()._M_node); }
154 const_iterator end() const { return const_iterator(_M_impl.end()._M_node); }
156 reverse_iterator rbegin() { return reverse_iterator(end()); }
157 const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
159 reverse_iterator rend() { return reverse_iterator(begin()); }
160 const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
162 bool empty() const { return _M_impl.empty(); }
163 size_type size() const { return _M_impl.size(); }
164 size_type max_size() const { return _M_impl.max_size(); }
166 reference front() { return *begin(); }
167 const_reference front() const { return *begin(); }
168 reference back() { return *(--end()); }
169 const_reference back() const { return *(--end()); }
171 void swap(_Self &__x) { _M_impl.swap(__x._M_impl); }
172 void clear() { _M_impl.clear(); }
174 #if !defined(_STLP_DONT_SUP_DFLT_PARAM) && !defined(_STLP_NO_ANACHRONISMS)
175 iterator insert(iterator __pos, const_reference __x = _STLP_DEFAULT_CONSTRUCTED(value_type))
177 iterator insert(iterator __pos, const_reference __x)
178 #endif /*!_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
179 { return iterator(_M_impl.insert(_BaseIte(__pos._M_node),
180 cast_traits::to_storage_type_cref(__x))._M_node); }
182 #if defined (_STLP_MEMBER_TEMPLATES)
183 # if defined (_STLP_USE_ITERATOR_WRAPPER)
185 template <class _Integer>
186 void _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __val,
188 { _M_impl.insert(_BaseIte(__pos._M_node), __n, __val); }
190 template <class _InputIterator>
191 void _M_insert_dispatch(iterator __pos,
192 _InputIterator __first, _InputIterator __last,
193 const __false_type&) {
194 _M_impl.insert(_BaseIte(__pos._M_node),
195 typename _STLP_PRIV _IteWrapper<_StorageType, _Tp, _InputIterator>::_Ite(__first),
196 typename _STLP_PRIV _IteWrapper<_StorageType, _Tp, _InputIterator>::_Ite(__last));
202 template <class _InputIterator>
203 void insert(iterator __pos, _InputIterator __first, _InputIterator __last) {
204 # if defined (_STLP_USE_ITERATOR_WRAPPER)
205 // Check whether it's an integral type. If so, it's not an iterator.
206 typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
207 _M_insert_dispatch(__pos, __first, __last, _Integral());
209 _M_impl.insert(_BaseIte(__pos._M_node), __first, __last);
212 #else /* _STLP_MEMBER_TEMPLATES */
213 void insert(iterator __pos, const value_type *__first, const value_type *__last)
214 { _M_impl.insert(_BaseIte(__pos._M_node), cast_traits::to_storage_type_cptr(__first),
215 cast_traits::to_storage_type_cptr(__last)); }
216 void insert(iterator __pos, const_iterator __first, const_iterator __last)
217 { _M_impl.insert(_BaseIte(__pos._M_node), _BaseConstIte(__first._M_node), _BaseConstIte(__last._M_node)); }
218 #endif /* _STLP_MEMBER_TEMPLATES */
220 void insert(iterator __pos, size_type __n, const value_type& __x)
221 { _M_impl.insert(_BaseIte(__pos._M_node), __n, cast_traits::to_storage_type_cref(__x)); }
223 void push_front(const value_type& __x) { _M_impl.push_front(cast_traits::to_storage_type_cref(__x)); }
224 void push_back(const value_type& __x) { _M_impl.push_back(cast_traits::to_storage_type_cref(__x)); }
226 #if defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
227 iterator insert(iterator __pos) { return iterator(_M_impl.insert(__pos._M_node)._M_node); }
228 void push_front() { _M_impl.push_front();}
229 void push_back() { _M_impl.push_back();}
230 # endif /*_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
232 iterator erase(iterator __pos)
233 { return iterator(_M_impl.erase(_BaseIte(__pos._M_node))._M_node); }
234 iterator erase(iterator __first, iterator __last)
235 { return iterator(_M_impl.erase(_BaseIte(__first._M_node), _BaseIte(__last._M_node))._M_node); }
237 #if !defined(_STLP_DONT_SUP_DFLT_PARAM)
238 void resize(size_type __new_size, const value_type& __x = _STLP_DEFAULT_CONSTRUCTED(value_type))
240 void resize(size_type __new_size) { _M_impl.resize(__new_size); }
241 void resize(size_type __new_size, const value_type& __x)
242 #endif /*!_STLP_DONT_SUP_DFLT_PARAM*/
243 {_M_impl.resize(__new_size, cast_traits::to_storage_type_cref(__x));}
245 void pop_front() { _M_impl.pop_front(); }
246 void pop_back() { _M_impl.pop_back(); }
248 _Self& operator=(const _Self& __x)
249 { _M_impl = __x._M_impl; return *this; }
250 void assign(size_type __n, const value_type& __val)
251 { _M_impl.assign(__n, cast_traits::to_storage_type_cref(__val)); }
253 #if defined (_STLP_MEMBER_TEMPLATES)
254 # if defined (_STLP_USE_ITERATOR_WRAPPER)
256 template <class _Integer>
257 void _M_assign_dispatch(_Integer __n, _Integer __val, const __true_type&)
258 { _M_impl.assign(__n, __val); }
260 template <class _InputIterator>
261 void _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
262 const __false_type&) {
263 _M_impl.assign(typename _STLP_PRIV _IteWrapper<_StorageType, _Tp, _InputIterator>::_Ite(__first),
264 typename _STLP_PRIV _IteWrapper<_StorageType, _Tp, _InputIterator>::_Ite(__last));
270 template <class _InputIterator>
271 void assign(_InputIterator __first, _InputIterator __last) {
272 # if defined (_STLP_USE_ITERATOR_WRAPPER)
273 typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
274 _M_assign_dispatch(__first, __last, _Integral());
276 _M_impl.assign(__first, __last);
280 void assign(const value_type *__first, const value_type *__last) {
281 _M_impl.assign(cast_traits::to_storage_type_cptr(__first),
282 cast_traits::to_storage_type_cptr(__last));
284 void assign(const_iterator __first, const_iterator __last)
285 { _M_impl.assign(_BaseConstIte(__first._M_node), _BaseConstIte(__last._M_node)); }
288 void splice(iterator __pos, _Self& __x)
289 { _M_impl.splice(_BaseIte(__pos._M_node), __x._M_impl); }
290 void splice(iterator __pos, _Self& __x, iterator __i)
291 { _M_impl.splice(_BaseIte(__pos._M_node), __x._M_impl, _BaseIte(__i._M_node)); }
292 void splice(iterator __pos, _Self& __x, iterator __first, iterator __last)
293 { _M_impl.splice(_BaseIte(__pos._M_node), __x._M_impl,
294 _BaseIte(__first._M_node), _BaseIte(__last._M_node)); }
296 void remove(const_reference __val)
297 { _M_impl.remove(cast_traits::to_storage_type_cref(__val)); }
298 void unique() { _M_impl.unique(); }
299 void merge(_Self& __x) { _M_impl.merge(__x._M_impl); }
300 void reverse() { _M_impl.reverse(); }
301 void sort() { _M_impl.sort(); }
303 #if defined (_STLP_MEMBER_TEMPLATES)
304 template <class _Predicate>
305 void remove_if(_Predicate __pred)
306 { _M_impl.remove_if(_STLP_PRIV _UnaryPredWrapper<_StorageType, _Tp, _Predicate>(__pred)); }
307 template <class _BinaryPredicate>
308 void unique(_BinaryPredicate __bin_pred)
309 { _M_impl.unique(_STLP_PRIV _BinaryPredWrapper<_StorageType, _Tp, _BinaryPredicate>(__bin_pred)); }
311 template <class _StrictWeakOrdering>
312 void merge(_Self &__x, _StrictWeakOrdering __comp)
313 { _M_impl.merge(__x._M_impl, _STLP_PRIV _BinaryPredWrapper<_StorageType, _Tp, _StrictWeakOrdering>(__comp)); }
315 template <class _StrictWeakOrdering>
316 void sort(_StrictWeakOrdering __comp)
317 { _M_impl.sort(_STLP_PRIV _BinaryPredWrapper<_StorageType, _Tp, _StrictWeakOrdering>(__comp)); }
318 #endif /* _STLP_MEMBER_TEMPLATES */
326 _STLP_MOVE_TO_STD_NAMESPACE
333 #endif /* _STLP_PTR_SPECIALIZED_LIST_H */