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_DEQUE_H
21 #define _STLP_SPECIALIZED_DEQUE_H
23 #ifndef _STLP_POINTERS_SPEC_TOOLS_H
24 # include <stl/pointers/_tools.h>
28 _STLP_MOVE_TO_PRIV_NAMESPACE
31 * struct helper to cast deque iterators:
33 template <class _StorageT, class _ValueT>
34 struct _DequeIteCast {
35 typedef _Deque_iterator<_ValueT, _Nonconst_traits<_ValueT> > iterator;
36 typedef _Deque_iterator<_ValueT, _Const_traits<_ValueT> > const_iterator;
37 typedef _Deque_iterator<_StorageT, _Nonconst_traits<_StorageT> > storage_iterator;
38 typedef _Deque_iterator<_StorageT, _Const_traits<_StorageT> > const_storage_iterator;
39 typedef _CastTraits<_StorageT, _ValueT> cast_traits;
41 static iterator to_value_type_ite (storage_iterator const& __ite) {
43 tmp._M_cur = cast_traits::to_value_type_ptr(__ite._M_cur);
44 tmp._M_first = cast_traits::to_value_type_ptr(__ite._M_first);
45 tmp._M_last = cast_traits::to_value_type_ptr(__ite._M_last);
46 tmp._M_node = cast_traits::to_value_type_pptr(__ite._M_node);
49 static storage_iterator to_storage_type_ite (iterator const& __ite) {
51 tmp._M_cur = cast_traits::to_storage_type_ptr(__ite._M_cur);
52 tmp._M_first = cast_traits::to_storage_type_ptr(__ite._M_first);
53 tmp._M_last = cast_traits::to_storage_type_ptr(__ite._M_last);
54 tmp._M_node = cast_traits::to_storage_type_pptr(__ite._M_node);
58 static const_iterator to_value_type_cite (const_storage_iterator const& __ite) {
60 tmp._M_cur = cast_traits::to_value_type_ptr(__ite._M_cur);
61 tmp._M_first = cast_traits::to_value_type_ptr(__ite._M_first);
62 tmp._M_last = cast_traits::to_value_type_ptr(__ite._M_last);
63 tmp._M_node = cast_traits::to_value_type_pptr(__ite._M_node);
67 static const_storage_iterator to_storage_type_cite (const_iterator const& __ite) {
68 const_storage_iterator tmp;
69 tmp._M_cur = cast_traits::to_storage_type_ptr(__ite._M_cur);
70 tmp._M_first = cast_traits::to_storage_type_ptr(__ite._M_first);
71 tmp._M_last = cast_traits::to_storage_type_ptr(__ite._M_last);
72 tmp._M_node = cast_traits::to_storage_type_pptr(__ite._M_node);
77 #define DEQUE_IMPL _STLP_PTR_IMPL_NAME(deque)
79 #if defined (_STLP_USE_TEMPLATE_EXPORT) && !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
80 _STLP_EXPORT_TEMPLATE_CLASS _STLP_alloc_proxy<size_t, void*, allocator<void*> >;
81 _STLP_EXPORT_TEMPLATE_CLASS _STLP_alloc_proxy<void***, void**, allocator<void**> >;
82 _STLP_EXPORT template struct _STLP_CLASS_DECLSPEC _Deque_iterator<void*, _Nonconst_traits<void*> >;
83 _STLP_EXPORT_TEMPLATE_CLASS _Deque_base<void*,allocator<void*> >;
84 _STLP_EXPORT_TEMPLATE_CLASS DEQUE_IMPL<void*,allocator<void*> >;
87 #if defined (_STLP_DEBUG)
88 # define deque _STLP_NON_DBG_NAME(deque)
90 _STLP_MOVE_TO_STD_NAMESPACE
93 template <class _Tp, _STLP_DEFAULT_ALLOCATOR_SELECT(_Tp) >
95 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (deque)
96 : public __stlport_class<deque<_Tp, _Alloc> >
99 typedef typename _STLP_PRIV _StorageType<_Tp>::_Type _StorageType;
100 typedef typename _Alloc_traits<_StorageType, _Alloc>::allocator_type _StorageTypeAlloc;
101 typedef _STLP_PRIV DEQUE_IMPL<_StorageType, _StorageTypeAlloc> _Base;
102 typedef deque<_Tp, _Alloc> _Self;
104 typedef _STLP_PRIV _CastTraits<_StorageType, _Tp> cast_traits;
105 typedef _STLP_PRIV _DequeIteCast<_StorageType, _Tp> ite_cast_traits;
108 typedef _Tp value_type;
109 typedef value_type* pointer;
110 typedef const value_type* const_pointer;
111 typedef value_type& reference;
112 typedef const value_type& const_reference;
113 typedef size_t size_type;
114 typedef ptrdiff_t difference_type;
115 typedef random_access_iterator_tag _Iterator_category;
116 _STLP_FORCE_ALLOCATORS(value_type, _Alloc)
117 typedef typename _Alloc_traits<value_type, _Alloc>::allocator_type allocator_type;
118 typedef _STLP_PRIV _Deque_iterator<value_type, _Nonconst_traits<value_type> > iterator;
119 typedef _STLP_PRIV _Deque_iterator<value_type, _Const_traits<value_type> > const_iterator;
121 _STLP_DECLARE_RANDOM_ACCESS_REVERSE_ITERATORS;
123 public: // Basic accessors
124 iterator begin() { return ite_cast_traits::to_value_type_ite(_M_impl.begin()); }
125 iterator end() { return ite_cast_traits::to_value_type_ite(_M_impl.end()); }
126 const_iterator begin() const { return ite_cast_traits::to_value_type_cite(_M_impl.begin()); }
127 const_iterator end() const { return ite_cast_traits::to_value_type_cite(_M_impl.end()); }
129 reverse_iterator rbegin() { return reverse_iterator(end()); }
130 reverse_iterator rend() { return reverse_iterator(begin()); }
131 const_reverse_iterator rbegin() const
132 { return const_reverse_iterator(end()); }
133 const_reverse_iterator rend() const
134 { return const_reverse_iterator(begin()); }
136 reference operator[](size_type __n)
137 { return cast_traits::to_value_type_ref(_M_impl[__n]); }
138 const_reference operator[](size_type __n) const
139 { return cast_traits::to_value_type_cref(_M_impl[__n]); }
141 reference at(size_type __n)
142 { return cast_traits::to_value_type_ref(_M_impl.at(__n)); }
143 const_reference at(size_type __n) const
144 { return cast_traits::to_value_type_cref(_M_impl.at(__n)); }
146 reference front() { return cast_traits::to_value_type_ref(_M_impl.front()); }
147 reference back() { return cast_traits::to_value_type_ref(_M_impl.back()); }
148 const_reference front() const { return cast_traits::to_value_type_cref(_M_impl.front()); }
149 const_reference back() const { return cast_traits::to_value_type_cref(_M_impl.back()); }
151 size_type size() const { return _M_impl.size(); }
152 size_type max_size() const { return _M_impl.max_size(); }
153 bool empty() const { return _M_impl.empty(); }
154 allocator_type get_allocator() const { return _STLP_CONVERT_ALLOCATOR(_M_impl.get_allocator(), value_type); }
156 explicit deque(const allocator_type& __a = allocator_type())
157 : _M_impl(_STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
159 deque(const _Self& __x) : _M_impl(__x._M_impl) {}
161 #if !defined (_STLP_DONT_SUP_DFLT_PARAM)
162 explicit deque(size_type __n, const value_type& __val = _STLP_DEFAULT_CONSTRUCTED(value_type),
164 deque(size_type __n, const value_type& __val,
165 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
166 const allocator_type& __a = allocator_type())
167 : _M_impl(__n, cast_traits::to_storage_type_cref(__val), _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
168 // int,long variants may be needed
169 #if defined (_STLP_DONT_SUP_DFLT_PARAM)
170 explicit deque(size_type __n) : _M_impl(__n) {}
171 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
173 #if defined (_STLP_MEMBER_TEMPLATES)
174 template <class _InputIterator>
175 deque(_InputIterator __first, _InputIterator __last,
176 const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
177 #if !defined (_STLP_USE_ITERATOR_WRAPPER)
178 : _M_impl(__first, __last,
179 _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {
181 : _M_impl(_STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {
183 #if defined (_STLP_USE_ITERATOR_WRAPPER)
184 insert(end(), __first, __last);
188 # if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
189 template <class _InputIterator>
190 deque(_InputIterator __first, _InputIterator __last)
191 # if !defined (_STLP_USE_ITERATOR_WRAPPER)
192 : _M_impl(__first, __last) {}
194 { insert(end(), __first, __last); }
199 deque(const_pointer __first, const_pointer __last,
200 const allocator_type& __a = allocator_type() )
201 : _M_impl(cast_traits::to_storage_type_cptr(__first),
202 cast_traits::to_storage_type_cptr(__last),
203 _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
205 deque(const_iterator __first, const_iterator __last,
206 const allocator_type& __a = allocator_type() )
207 : _M_impl(ite_cast_traits::to_storage_type_cite(__first),
208 ite_cast_traits::to_storage_type_cite(__last),
209 _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
210 #endif /* _STLP_MEMBER_TEMPLATES */
212 deque(__move_source<_Self> src)
213 : _M_impl(__move_source<_Base>(src.get()._M_impl)) {}
215 _Self& operator= (const _Self& __x) { _M_impl = __x._M_impl; return *this; }
217 void swap(_Self& __x) { _M_impl.swap(__x._M_impl); }
219 void assign(size_type __n, const value_type& __val) {
220 _M_impl.assign(__n, cast_traits::to_storage_type_cref(__val));
223 #if defined (_STLP_MEMBER_TEMPLATES)
224 # if defined (_STLP_USE_ITERATOR_WRAPPER)
226 template <class _Integer>
227 void _M_assign_dispatch(_Integer __n, _Integer __val,
229 { _M_impl.assign(__n, __val); }
231 template <class _InputIterator>
232 void _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
233 const __false_type&) {
234 _M_impl.assign(typename _STLP_PRIV _IteWrapper<_StorageType, _Tp, _InputIterator>::_Ite(__first),
235 typename _STLP_PRIV _IteWrapper<_StorageType, _Tp, _InputIterator>::_Ite(__last));
240 template <class _InputIterator>
241 void assign(_InputIterator __first, _InputIterator __last) {
242 # if defined (_STLP_USE_ITERATOR_WRAPPER)
243 typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
244 _M_assign_dispatch(__first, __last, _Integral());
246 _M_impl.assign(__first, __last);
250 void assign(const_pointer __first, const_pointer __last)
251 { _M_impl.assign(cast_traits::to_storage_type_cptr(__first),
252 cast_traits::to_storage_type_cptr(__last)); }
253 void assign(const_iterator __first, const_iterator __last)
254 { _M_impl.assign(ite_cast_traits::to_storage_type_cite(__first),
255 ite_cast_traits::to_storage_type_cite(__last)); }
256 #endif /* _STLP_MEMBER_TEMPLATES */
258 #if !defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
259 void push_back(const value_type& __t = _STLP_DEFAULT_CONSTRUCTED(value_type))
261 void push_back(const value_type& __t)
262 #endif /*!_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
263 { _M_impl.push_back(cast_traits::to_storage_type_cref(__t)); }
265 #if !defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
266 void push_front(const value_type& __t = _STLP_DEFAULT_CONSTRUCTED(value_type))
268 void push_front(const value_type& __t)
269 #endif /*!_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
270 { _M_impl.push_front(cast_traits::to_storage_type_cref(__t)); }
272 # if defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
273 void push_back() { _M_impl.push_back(); }
274 void push_front() { _M_impl.push_front(); }
275 # endif /*_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
277 void pop_back() { _M_impl.pop_back(); }
278 void pop_front() { _M_impl.pop_front(); }
280 #if !defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
281 iterator insert(iterator __pos, const value_type& __x = _STLP_DEFAULT_CONSTRUCTED(value_type))
283 iterator insert(iterator __pos, const value_type& __x)
284 #endif /*!_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
285 { return ite_cast_traits::to_value_type_ite(_M_impl.insert(ite_cast_traits::to_storage_type_ite(__pos),
286 cast_traits::to_storage_type_cref(__x))); }
288 #if defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
289 iterator insert(iterator __pos) { return insert(__pos, _STLP_DEFAULT_CONSTRUCTED(value_type)); }
290 #endif /*_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
292 void insert(iterator __pos, size_type __n, const value_type& __x)
293 { _M_impl.insert(ite_cast_traits::to_storage_type_ite(__pos), __n, cast_traits::to_storage_type_cref(__x)); }
295 #if defined (_STLP_MEMBER_TEMPLATES)
296 # if defined (_STLP_USE_ITERATOR_WRAPPER)
298 template <class _Integer>
299 void _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __val,
300 const __true_type&) {
301 _M_impl.insert(ite_cast_traits::to_storage_type_ite(__pos), __n, __val);
304 template <class _InputIterator>
305 void _M_insert_dispatch(iterator __pos,
306 _InputIterator __first, _InputIterator __last,
307 const __false_type&) {
308 _M_impl.insert(ite_cast_traits::to_storage_type_ite(__pos),
309 typename _STLP_PRIV _IteWrapper<_StorageType, _Tp, _InputIterator>::_Ite(__first),
310 typename _STLP_PRIV _IteWrapper<_StorageType, _Tp, _InputIterator>::_Ite(__last));
316 template <class _InputIterator>
317 void insert(iterator __pos, _InputIterator __first, _InputIterator __last) {
318 # if defined (_STLP_USE_ITERATOR_WRAPPER)
319 // Check whether it's an integral type. If so, it's not an iterator.
320 typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
321 _M_insert_dispatch(__pos, __first, __last, _Integral());
323 _M_impl.insert(ite_cast_traits::to_storage_type_ite(__pos), __first, __last);
327 #else /* _STLP_MEMBER_TEMPLATES */
328 void insert(iterator __pos,
329 const_pointer __first, const_pointer __last) {
330 _M_impl.insert(ite_cast_traits::to_storage_type_ite(__pos),
331 cast_traits::to_storage_type_cptr(__first),
332 cast_traits::to_storage_type_cptr(__last));
334 void insert(iterator __pos,
335 const_iterator __first, const_iterator __last) {
336 _M_impl.insert(ite_cast_traits::to_storage_type_ite(__pos),
337 ite_cast_traits::to_storage_type_cite(__first),
338 ite_cast_traits::to_storage_type_cite(__last));
341 #endif /* _STLP_MEMBER_TEMPLATES */
343 #if !defined (_STLP_DONT_SUP_DFLT_PARAM)
344 void resize(size_type __new_size, const value_type& __x = _STLP_DEFAULT_CONSTRUCTED(value_type))
346 void resize(size_type __new_size, const value_type& __x)
347 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
348 { _M_impl.resize(__new_size, cast_traits::to_storage_type_cref(__x)); }
350 #if defined (_STLP_DONT_SUP_DFLT_PARAM)
351 void resize(size_type __new_size) { _M_impl.resize(__new_size); }
352 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
354 iterator erase(iterator __pos)
355 { return ite_cast_traits::to_value_type_ite(_M_impl.erase(ite_cast_traits::to_storage_type_ite(__pos))); }
357 iterator erase(iterator __first, iterator __last)
358 { return ite_cast_traits::to_value_type_ite(_M_impl.erase(ite_cast_traits::to_storage_type_ite(__first),
359 ite_cast_traits::to_storage_type_ite(__last))); }
360 void clear() { _M_impl.clear(); }
368 _STLP_MOVE_TO_STD_NAMESPACE
375 #endif /* _STLP_SPECIALIZED_DEQUE_H */