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_all()
79 { _M_iter_list._Invalidate_all(); }
80 void _Invalidate_iterator(const iterator& __it)
81 { _STLP_PRIV __invalidate_iterator(&_M_iter_list,__it); }
82 void _Invalidate_iterators(const iterator& __first, const iterator& __last)
83 { _STLP_PRIV __invalidate_range(&_M_iter_list, __first, __last); }
87 allocator_type get_allocator() const { return _M_non_dbg_impl.get_allocator(); }
89 iterator begin() { return iterator(&_M_iter_list, _M_non_dbg_impl.begin()); }
90 iterator end() { return iterator(&_M_iter_list, _M_non_dbg_impl.end()); }
91 const_iterator begin() const { return const_iterator(&_M_iter_list, _M_non_dbg_impl.begin()); }
92 const_iterator end() const { return const_iterator(&_M_iter_list, _M_non_dbg_impl.end()); }
94 reverse_iterator rbegin() { return reverse_iterator(end()); }
95 reverse_iterator rend() { return reverse_iterator(begin()); }
96 const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
97 const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
99 reference operator[](size_type __n) {
100 _STLP_VERBOSE_ASSERT(__n < size(), _StlMsg_OUT_OF_BOUNDS)
101 return _M_non_dbg_impl[__n];
103 const_reference operator[](size_type __n) const {
104 _STLP_VERBOSE_ASSERT(__n < size(), _StlMsg_OUT_OF_BOUNDS)
105 return _M_non_dbg_impl[__n];
108 reference at(size_type __n) { return _M_non_dbg_impl.at(__n); }
109 const_reference at(size_type __n) const { return _M_non_dbg_impl.at(__n); }
112 _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
115 const_reference front() const {
116 _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
120 _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
123 const_reference back() const {
124 _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
128 // Constructor, destructor.
129 explicit deque(const allocator_type& __a = allocator_type()) :
130 _M_non_dbg_impl(__a), _M_iter_list(&_M_non_dbg_impl) {}
131 deque(const _Self& __x) :
132 _ConstructCheck(__x), _M_non_dbg_impl(__x._M_non_dbg_impl),
133 _M_iter_list(&_M_non_dbg_impl) {}
135 #if !defined(_STLP_DONT_SUP_DFLT_PARAM)
136 explicit deque(size_type __n, const value_type& __x = _Tp(),
138 deque(size_type __n, param_type __x,
139 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
140 const allocator_type& __a = allocator_type()) :
141 _M_non_dbg_impl(__n, __x, __a), _M_iter_list(&_M_non_dbg_impl) {}
142 #if defined (_STLP_DONT_SUP_DFLT_PARAM)
143 explicit deque(size_type __n) :
144 _M_non_dbg_impl(__n), _M_iter_list(&_M_non_dbg_impl) {}
145 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
147 deque(__move_source<_Self> src)
148 : _M_non_dbg_impl(__move_source<_Base>(src.get()._M_non_dbg_impl)),
149 _M_iter_list(&_M_non_dbg_impl) {
150 #if defined (_STLP_NO_EXTENSIONS) || (_STLP_DEBUG_LEVEL == _STLP_STANDARD_DBG_LEVEL)
151 src.get()._M_iter_list._Invalidate_all();
153 src.get()._M_iter_list._Set_owner(_M_iter_list);
157 #if defined (_STLP_MEMBER_TEMPLATES)
158 template <class _InputIterator>
159 deque(_InputIterator __first, _InputIterator __last,
160 const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
161 : _ConstructCheck(__first, __last),
162 _M_non_dbg_impl(_STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last), __a),
163 _M_iter_list(&_M_non_dbg_impl) {
165 # if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
166 template <class _InputIterator>
167 deque(_InputIterator __first, _InputIterator __last)
168 : _ConstructCheck(__first, __last),
169 _M_non_dbg_impl(_STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last)),
170 _M_iter_list(&_M_non_dbg_impl) {
174 deque(const value_type* __first, const value_type* __last,
175 const allocator_type& __a = allocator_type())
176 : _ConstructCheck(__first, __last),
177 _M_non_dbg_impl(__first, __last, __a),
178 _M_iter_list(&_M_non_dbg_impl) {
181 deque(const_iterator __first, const_iterator __last,
182 const allocator_type& __a = allocator_type())
183 : _ConstructCheck(__first, __last),
184 _M_non_dbg_impl(__first._M_iterator, __last._M_iterator, __a),
185 _M_iter_list(&_M_non_dbg_impl) {
189 _Self& operator=(const _Self& __x) {
192 _M_non_dbg_impl = __x._M_non_dbg_impl;
197 bool empty() const { return _M_non_dbg_impl.empty(); }
198 size_type size() const { return _M_non_dbg_impl.size(); }
199 size_type max_size() const { return _M_non_dbg_impl.max_size(); }
201 void swap(_Self& __x) {
202 _M_iter_list._Swap_owners(__x._M_iter_list);
203 _M_non_dbg_impl.swap(__x._M_non_dbg_impl);
207 void assign(size_type __n, const _Tp& __val) {
209 _M_non_dbg_impl.assign(__n, __val);
212 #if defined (_STLP_MEMBER_TEMPLATES)
213 template <class _InputIterator>
214 void assign(_InputIterator __first, _InputIterator __last) {
215 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
217 _M_non_dbg_impl.assign(_STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last));
220 void assign(const_iterator __first, const_iterator __last) {
221 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
223 _M_non_dbg_impl.assign(__first._M_iterator, __last._M_iterator);
225 void assign(const value_type *__first, const value_type *__last) {
226 _STLP_DEBUG_CHECK(_STLP_PRIV __check_ptr_range(__first, __last))
228 _M_non_dbg_impl.assign(__first, __last);
232 public: // push_* and pop_*
234 #if !defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
235 void push_back(const value_type& __t = _Tp()) {
237 void push_back(const value_type& __t) {
238 #endif /*!_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
240 _M_non_dbg_impl.push_back(__t);
243 #if defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
246 _M_non_dbg_impl.push_back();
248 #endif /*_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
250 #if !defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
251 void push_front(const value_type& __t = _Tp()) {
253 void push_front(const value_type& __t) {
254 #endif /*!_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
256 _M_non_dbg_impl.push_front(__t);
259 #if defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
262 _M_non_dbg_impl.push_front();
264 #endif /*_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
267 _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
268 _Invalidate_iterator(end());
269 _M_non_dbg_impl.pop_back();
273 _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
274 _Invalidate_iterator(begin());
275 _M_non_dbg_impl.pop_front();
280 #if !defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
281 iterator insert(iterator __pos, const value_type& __x = _Tp()) {
283 iterator insert(iterator __pos, const value_type& __x) {
284 #endif /*!_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
285 _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
287 return iterator(&_M_iter_list, _M_non_dbg_impl.insert(__pos._M_iterator, __x));
290 #if defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
291 iterator insert(iterator __pos) {
292 _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
294 return iterator(&_M_iter_list, _M_non_dbg_impl.insert(__pos._M_iterator));
296 #endif /*_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
298 void insert(iterator __pos, size_type __n, const value_type& __x) {
299 _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
300 if (__n != 0) _Invalidate_all();
301 _M_non_dbg_impl.insert(__pos._M_iterator, __n, __x);
304 #if defined (_STLP_MEMBER_TEMPLATES)
305 template <class _InputIterator>
306 void insert(iterator __pos, _InputIterator __first, _InputIterator __last) {
307 typedef typename _AreSameUnCVTypes<_InputIterator, iterator>::_Ret _IsNonConstIterator;
308 typedef typename _AreSameUnCVTypes<_InputIterator, const_iterator>::_Ret _IsConstIterator;
309 typedef typename _Lor2<_IsNonConstIterator, _IsConstIterator>::_Ret _DoCheck;
310 _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
311 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
312 //Sequence requirements 23.1.1 Table 67:
313 _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_not_owner(&_M_iter_list, __first, _DoCheck()));
314 _M_non_dbg_impl.insert(__pos._M_iterator,
315 _STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last));
316 //dums: because of self insertion iterators must be invalidated after insertion.
317 if (__first != __last) _Invalidate_all();
320 void insert(iterator __pos,
321 const value_type* __first, const value_type* __last) {
322 _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
323 _STLP_DEBUG_CHECK(_STLP_PRIV __check_ptr_range(__first, __last))
324 _M_non_dbg_impl.insert(__pos._M_iterator, __first, __last);
325 //dums: because of self insertion iterators must be invalidated after insertion.
326 if (__first != __last) _Invalidate_all();
328 void insert(iterator __pos,
329 const_iterator __first, const_iterator __last) {
330 _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
331 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
332 //Sequence requirements 23.1.1 Table 67:
333 _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_not_owner(&_M_iter_list, __first, __true_type()));
334 _M_non_dbg_impl.insert(__pos._M_iterator, __first._M_iterator, __last._M_iterator);
335 //dums: because of self insertion iterators must be invalidated after insertion.
336 if (__first != __last) _Invalidate_all();
340 #if !defined (_STLP_DONT_SUP_DFLT_PARAM)
341 void resize(size_type __new_size, const value_type& __x = _Tp()) {
343 void resize(size_type __new_size, const value_type& __x) {
344 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
345 if (__new_size != size()) {
346 if ((__new_size > size()) || (__new_size < size() - 1))
349 _Invalidate_iterator(end());
351 _M_non_dbg_impl.resize(__new_size, __x);
354 #if defined (_STLP_DONT_SUP_DFLT_PARAM)
355 void resize(size_type new_size) { resize(new_size, _STLP_DEFAULT_CONSTRUCTED(_Tp)); }
356 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
359 iterator erase(iterator __pos) {
360 _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
361 _STLP_DEBUG_CHECK(_STLP_PRIV _Dereferenceable(__pos))
362 if (__pos._M_iterator == _M_non_dbg_impl.begin())
363 _Invalidate_iterator(__pos);
365 typename _Base::iterator __tmp = --(_M_non_dbg_impl.end());
366 if (__pos._M_iterator == __tmp)
367 _Invalidate_iterator(__pos);
371 return iterator (&_M_iter_list, _M_non_dbg_impl.erase(__pos._M_iterator));
374 iterator erase(iterator __first, iterator __last) {
375 _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last, begin(), end()))
377 if (__first._M_iterator == _M_non_dbg_impl.begin() ||
378 __last._M_iterator == _M_non_dbg_impl.end())
379 _Invalidate_iterators(__first, __last);
383 return iterator (&_M_iter_list, _M_non_dbg_impl.erase(__first._M_iterator, __last._M_iterator));
388 _M_non_dbg_impl.clear();
394 #undef _STLP_NON_DBG_DEQUE
396 #endif /* _STLP_INTERNAL_DEQUE_H */