4 * Hewlett-Packard Company
6 * Copyright (c) 1996,1997
7 * Silicon Graphics Computer Systems, Inc.
10 * Moscow Center for SPARC Technology
15 * This material is provided "as is", with absolutely no warranty expressed
16 * or implied. Any use is at your own risk.
18 * Permission to use or copy this software for any purpose is hereby granted
19 * without fee, provided the above notices are retained on all copies.
20 * Permission to modify the code and to distribute modified code is granted,
21 * provided the above notices are retained, and a notice that the code was
22 * modified is included with the above copyright notice.
26 /* NOTE: This is an internal header file, included by other STL headers.
27 * You should not attempt to use it directly.
30 #ifndef _STLP_INTERNAL_DBG_DEQUE_H
31 #define _STLP_INTERNAL_DBG_DEQUE_H
33 #ifndef _STLP_DBG_ITERATOR_H
34 # include <stl/debug/_iterator.h>
37 #define _STLP_NON_DBG_DEQUE _STLP_PRIV _STLP_NON_DBG_NAME(deque) <_Tp,_Alloc>
41 #if defined (_STLP_DEBUG_USE_DISTINCT_VALUE_TYPE_HELPERS)
42 template <class _Tp, class _Alloc>
43 inline _Tp* value_type(const _STLP_PRIV _DBG_iter_base< _STLP_NON_DBG_DEQUE >&)
45 template <class _Tp, class _Alloc>
46 inline random_access_iterator_tag iterator_category(const _STLP_PRIV _DBG_iter_base< _STLP_NON_DBG_DEQUE >&)
47 { return random_access_iterator_tag(); }
50 template <class _Tp, _STLP_DBG_ALLOCATOR_SELECT(_Tp) >
52 #if !defined (__DMC__)
55 _STLP_PRIV __construct_checker<_STLP_NON_DBG_DEQUE >
56 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND)
57 , public __stlport_class<deque<_Tp, _Alloc> >
60 typedef deque<_Tp,_Alloc> _Self;
61 typedef _STLP_NON_DBG_DEQUE _Base;
62 typedef _STLP_PRIV __construct_checker<_STLP_NON_DBG_DEQUE > _ConstructCheck;
66 __IMPORT_CONTAINER_TYPEDEFS(_Base)
69 typedef _STLP_PRIV _DBG_iter<_Base, _STLP_PRIV _DbgTraits<_Nonconst_traits<value_type> > > iterator;
70 typedef _STLP_PRIV _DBG_iter<_Base, _STLP_PRIV _DbgTraits<_Const_traits<value_type> > > const_iterator;
72 _STLP_DECLARE_RANDOM_ACCESS_REVERSE_ITERATORS;
75 _Base _M_non_dbg_impl;
76 _STLP_PRIV __owned_list _M_iter_list;
78 void _Invalidate_iterator(const iterator& __it)
79 { _STLP_PRIV __invalidate_iterator(&_M_iter_list,__it); }
80 void _Invalidate_all()
81 { _M_iter_list._Invalidate_all(); }
85 allocator_type get_allocator() const { return _M_non_dbg_impl.get_allocator(); }
87 iterator begin() { return iterator(&_M_iter_list, _M_non_dbg_impl.begin()); }
88 iterator end() { return iterator(&_M_iter_list, _M_non_dbg_impl.end()); }
89 const_iterator begin() const { return const_iterator(&_M_iter_list, _M_non_dbg_impl.begin()); }
90 const_iterator end() const { return const_iterator(&_M_iter_list, _M_non_dbg_impl.end()); }
92 reverse_iterator rbegin() { return reverse_iterator(end()); }
93 reverse_iterator rend() { return reverse_iterator(begin()); }
94 const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
95 const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
97 reference operator[](size_type __n) {
98 _STLP_VERBOSE_ASSERT(__n < size(), _StlMsg_OUT_OF_BOUNDS)
99 return _M_non_dbg_impl[__n];
101 const_reference operator[](size_type __n) const {
102 _STLP_VERBOSE_ASSERT(__n < size(), _StlMsg_OUT_OF_BOUNDS)
103 return _M_non_dbg_impl[__n];
106 reference at(size_type __n) { return _M_non_dbg_impl.at(__n); }
107 const_reference at(size_type __n) const { return _M_non_dbg_impl.at(__n); }
110 _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
113 const_reference front() const {
114 _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
118 _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
121 const_reference back() const {
122 _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
126 // Constructor, destructor.
127 explicit deque(const allocator_type& __a = allocator_type()) :
128 _M_non_dbg_impl(__a), _M_iter_list(&_M_non_dbg_impl) {}
129 deque(const _Self& __x) :
130 _ConstructCheck(__x), _M_non_dbg_impl(__x._M_non_dbg_impl),
131 _M_iter_list(&_M_non_dbg_impl) {}
133 #if !defined(_STLP_DONT_SUP_DFLT_PARAM)
134 explicit deque(size_type __n, const value_type& __x = _Tp(),
136 deque(size_type __n, param_type __x,
137 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
138 const allocator_type& __a = allocator_type()) :
139 _M_non_dbg_impl(__n, __x, __a), _M_iter_list(&_M_non_dbg_impl) {}
140 #if defined (_STLP_DONT_SUP_DFLT_PARAM)
141 explicit deque(size_type __n) :
142 _M_non_dbg_impl(__n), _M_iter_list(&_M_non_dbg_impl) {}
143 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
145 deque(__move_source<_Self> src)
146 : _M_non_dbg_impl(__move_source<_Base>(src.get()._M_non_dbg_impl)),
147 _M_iter_list(&_M_non_dbg_impl) {
148 #if defined (_STLP_NO_EXTENSIONS) || (_STLP_DEBUG_LEVEL == _STLP_STANDARD_DBG_LEVEL)
149 src.get()._M_iter_list._Invalidate_all();
151 src.get()._M_iter_list._Set_owner(_M_iter_list);
155 #if defined (_STLP_MEMBER_TEMPLATES)
156 template <class _InputIterator>
157 deque(_InputIterator __first, _InputIterator __last,
158 const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
159 : _ConstructCheck(__first, __last),
160 _M_non_dbg_impl(_STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last), __a),
161 _M_iter_list(&_M_non_dbg_impl) {
163 # if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
164 template <class _InputIterator>
165 deque(_InputIterator __first, _InputIterator __last)
166 : _ConstructCheck(__first, __last),
167 _M_non_dbg_impl(_STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last)),
168 _M_iter_list(&_M_non_dbg_impl) {
172 deque(const value_type* __first, const value_type* __last,
173 const allocator_type& __a = allocator_type())
174 : _ConstructCheck(__first, __last),
175 _M_non_dbg_impl(__first, __last, __a),
176 _M_iter_list(&_M_non_dbg_impl) {
179 deque(const_iterator __first, const_iterator __last,
180 const allocator_type& __a = allocator_type())
181 : _ConstructCheck(__first, __last),
182 _M_non_dbg_impl(__first._M_iterator, __last._M_iterator, __a),
183 _M_iter_list(&_M_non_dbg_impl) {
187 _Self& operator=(const _Self& __x) {
190 _M_non_dbg_impl = __x._M_non_dbg_impl;
195 bool empty() const { return _M_non_dbg_impl.empty(); }
196 size_type size() const { return _M_non_dbg_impl.size(); }
197 size_type max_size() const { return _M_non_dbg_impl.max_size(); }
199 void swap(_Self& __x) {
200 _M_iter_list._Swap_owners(__x._M_iter_list);
201 _M_non_dbg_impl.swap(__x._M_non_dbg_impl);
205 void assign(size_type __n, const _Tp& __val) {
207 _M_non_dbg_impl.assign(__n, __val);
210 #if defined (_STLP_MEMBER_TEMPLATES)
211 template <class _InputIterator>
212 void assign(_InputIterator __first, _InputIterator __last) {
213 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
215 _M_non_dbg_impl.assign(_STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last));
218 void assign(const_iterator __first, const_iterator __last) {
219 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
221 _M_non_dbg_impl.assign(__first._M_iterator, __last._M_iterator);
223 void assign(const value_type *__first, const value_type *__last) {
224 _STLP_DEBUG_CHECK(_STLP_PRIV __check_ptr_range(__first, __last))
226 _M_non_dbg_impl.assign(__first, __last);
230 public: // push_* and pop_*
232 #if !defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
233 void push_back(const value_type& __t = _Tp()) {
235 void push_back(const value_type& __t) {
236 #endif /*!_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
238 _M_non_dbg_impl.push_back(__t);
241 #if defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
244 _M_non_dbg_impl.push_back();
246 #endif /*_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
248 #if !defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
249 void push_front(const value_type& __t = _Tp()) {
251 void push_front(const value_type& __t) {
252 #endif /*!_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
254 _M_non_dbg_impl.push_front(__t);
257 #if defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
260 _M_non_dbg_impl.push_front();
262 #endif /*_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
265 _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
266 _Invalidate_iterator(end());
267 _M_non_dbg_impl.pop_back();
271 _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
272 _Invalidate_iterator(begin());
273 _M_non_dbg_impl.pop_front();
278 #if !defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
279 iterator insert(iterator __pos, const value_type& __x = _Tp()) {
281 iterator insert(iterator __pos, const value_type& __x) {
282 #endif /*!_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
283 _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
285 return iterator(&_M_iter_list, _M_non_dbg_impl.insert(__pos._M_iterator, __x));
288 #if defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
289 iterator insert(iterator __pos) {
290 _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
292 return iterator(&_M_iter_list, _M_non_dbg_impl.insert(__pos._M_iterator));
294 #endif /*_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
296 void insert(iterator __pos, size_type __n, const value_type& __x) {
297 _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
298 if (__n != 0) _Invalidate_all();
299 _M_non_dbg_impl.insert(__pos._M_iterator, __n, __x);
302 #if defined (_STLP_MEMBER_TEMPLATES)
303 template <class _InputIterator>
304 void insert(iterator __pos, _InputIterator __first, _InputIterator __last) {
305 typedef typename _AreSameUnCVTypes<_InputIterator, iterator>::_Ret _IsNonConstIterator;
306 typedef typename _AreSameUnCVTypes<_InputIterator, const_iterator>::_Ret _IsConstIterator;
307 typedef typename _Lor2<_IsNonConstIterator, _IsConstIterator>::_Ret _DoCheck;
308 _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
309 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
310 //Sequence requirements 23.1.1 Table 67:
311 _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_not_owner(&_M_iter_list, __first, _DoCheck()));
312 _M_non_dbg_impl.insert(__pos._M_iterator,
313 _STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last));
314 //dums: because of self insertion iterators must be invalidated after insertion.
315 if (__first != __last) _Invalidate_all();
318 void insert(iterator __pos,
319 const value_type* __first, const value_type* __last) {
320 _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
321 _STLP_DEBUG_CHECK(_STLP_PRIV __check_ptr_range(__first, __last))
322 _M_non_dbg_impl.insert(__pos._M_iterator, __first, __last);
323 //dums: because of self insertion iterators must be invalidated after insertion.
324 if (__first != __last) _Invalidate_all();
326 void insert(iterator __pos,
327 const_iterator __first, const_iterator __last) {
328 _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
329 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
330 //Sequence requirements 23.1.1 Table 67:
331 _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_not_owner(&_M_iter_list, __first, __true_type()));
332 _M_non_dbg_impl.insert(__pos._M_iterator, __first._M_iterator, __last._M_iterator);
333 //dums: because of self insertion iterators must be invalidated after insertion.
334 if (__first != __last) _Invalidate_all();
338 #if !defined (_STLP_DONT_SUP_DFLT_PARAM)
339 void resize(size_type __new_size, const value_type& __x = _Tp()) {
341 void resize(size_type __new_size, const value_type& __x) {
342 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
343 if (__new_size != size()) {
344 if ((__new_size > size()) || (__new_size < size() - 1))
347 _Invalidate_iterator(end());
349 _M_non_dbg_impl.resize(__new_size, __x);
352 #if defined (_STLP_DONT_SUP_DFLT_PARAM)
353 void resize(size_type new_size) { resize(new_size, _STLP_DEFAULT_CONSTRUCTED(_Tp)); }
354 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
357 iterator erase(iterator __pos) {
358 _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
359 _STLP_DEBUG_CHECK(_STLP_PRIV _Dereferenceable(__pos))
360 if (__pos == begin())
361 _Invalidate_iterator(__pos);
363 iterator __tmp = --(end());
365 _Invalidate_iterator(__pos);
369 return iterator (&_M_iter_list, _M_non_dbg_impl.erase(__pos._M_iterator));
372 iterator erase(iterator __first, iterator __last) {
373 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last, begin(), end()))
375 if (__last == (++(begin())))
376 _Invalidate_iterator(__last);
378 if (__first == (--(end())))
379 _Invalidate_iterator(__first);
384 return iterator (&_M_iter_list, _M_non_dbg_impl.erase(__first._M_iterator, __last._M_iterator));
389 _M_non_dbg_impl.clear();
395 #undef _STLP_NON_DBG_DEQUE
397 #endif /* _STLP_INTERNAL_DEQUE_H */