1 /*
2  *
3  * Copyright (c) 1996,1997
4  * Silicon Graphics Computer Systems, Inc.
5  *
6  * Copyright (c) 1997
7  * Moscow Center for SPARC Technology
8  *
9  * Copyright (c) 1999
10  * Boris Fomitchev
11  *
12  * This material is provided "as is", with absolutely no warranty expressed
13  * or implied. Any use is at your own risk.
14  *
15  * Permission to use or copy this software for any purpose is hereby granted
16  * without fee, provided the above notices are retained on all copies.
17  * Permission to modify the code and to distribute modified code is granted,
18  * provided the above notices are retained, and a notice that the code was
19  * modified is included with the above copyright notice.
20  *
21  */
22 
23 /* NOTE: This is an internal header file, included by other STL headers.
24  *   You should not attempt to use it directly.
25  */
26 
27 #ifndef _STLP_INTERNAL_DBG_SLIST_H
28 #define _STLP_INTERNAL_DBG_SLIST_H
29 
30 #ifndef _STLP_DBG_ITERATOR_H
31 #  include <stl/debug/_iterator.h>
32 #endif
33 
34 #define _STLP_NON_DBG_SLIST _STLP_PRIV _STLP_NON_DBG_NAME(slist) <_Tp, _Alloc>
35 
36 _STLP_BEGIN_NAMESPACE
37 
38 #if defined (_STLP_DEBUG_USE_DISTINCT_VALUE_TYPE_HELPERS)
39 template <class _Tp, class _Alloc>
40 inline _Tp*
value_type(const _STLP_PRIV _DBG_iter_base<_STLP_NON_DBG_SLIST> &)41 value_type(const _STLP_PRIV _DBG_iter_base< _STLP_NON_DBG_SLIST >&)
42 { return (_Tp*)0; }
43 
44 template <class _Tp, class _Alloc>
45 inline forward_iterator_tag
iterator_category(const _STLP_PRIV _DBG_iter_base<_STLP_NON_DBG_SLIST> &)46 iterator_category(const _STLP_PRIV _DBG_iter_base< _STLP_NON_DBG_SLIST >&)
47 { return forward_iterator_tag(); }
48 #endif
49 
50 _STLP_MOVE_TO_PRIV_NAMESPACE
51 
52 /*
53  * slist special debug traits version.
54  */
55 template <class _Traits>
56 struct _SlistDbgTraits : _Traits {
57   typedef _SlistDbgTraits<typename _Traits::_ConstTraits> _ConstTraits;
58   typedef _SlistDbgTraits<typename _Traits::_NonConstTraits> _NonConstTraits;
59 
60   /*
61    * We don't want the before_begin iterator to return false at _Dereferenceable
62    * call to do not break the current debug framework but calling * operator should
63    * fail.
64    */
65   template <class _Iterator>
_Check_SlistDbgTraits66   static bool _Check(const _Iterator& __it)
67   { return !(__it._M_iterator == (__it._Get_container_ptr())->before_begin()); }
68 };
69 
70 _STLP_MOVE_TO_STD_NAMESPACE
71 
72 template <class _Tp, _STLP_DFL_TMPL_PARAM(_Alloc, allocator<_Tp>) >
73 class slist :
74 #if !defined (__DMC__)
75              private
76 #endif
77                      _STLP_PRIV __construct_checker<_STLP_NON_DBG_SLIST >
78 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND)
79             , public __stlport_class<slist<_Tp, _Alloc> >
80 #endif
81 {
82 private:
83   typedef _STLP_NON_DBG_SLIST _Base;
84   typedef slist<_Tp,_Alloc> _Self;
85   typedef _STLP_PRIV __construct_checker<_STLP_NON_DBG_SLIST > _ConstructCheck;
86 
87 public:
88 
89   __IMPORT_CONTAINER_TYPEDEFS(_Base)
90 
91   typedef _STLP_PRIV _DBG_iter<_Base, _STLP_PRIV _SlistDbgTraits<_Nonconst_traits<value_type> > > iterator;
92   typedef _STLP_PRIV _DBG_iter<_Base, _STLP_PRIV _SlistDbgTraits<_Const_traits<value_type> > >    const_iterator;
93 
get_allocator()94   allocator_type get_allocator() const { return _M_non_dbg_impl.get_allocator(); }
95 private:
96   _Base _M_non_dbg_impl;
97   _STLP_PRIV __owned_list _M_iter_list;
98 
_Invalidate_iterator(const iterator & __it)99   void _Invalidate_iterator(const iterator& __it)
100   { _STLP_PRIV __invalidate_iterator(&_M_iter_list, __it); }
_Invalidate_iterators(const iterator & __first,const iterator & __last)101   void _Invalidate_iterators(const iterator& __first, const iterator& __last)
102   { _STLP_PRIV __invalidate_range(&_M_iter_list, __first, __last); }
103 
104   typedef typename _Base::iterator _Base_iterator;
105 
106 public:
107   explicit slist(const allocator_type& __a = allocator_type())
_M_non_dbg_impl(__a)108     : _M_non_dbg_impl(__a) , _M_iter_list(&_M_non_dbg_impl) {}
109 
110 #if !defined(_STLP_DONT_SUP_DFLT_PARAM)
111   explicit slist(size_type __n, const value_type& __x = _Tp(),
112 #else
113   slist(size_type __n, const value_type& __x,
114 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
115         const allocator_type& __a =  allocator_type())
_M_non_dbg_impl(__n,__x,__a)116     : _M_non_dbg_impl(__n, __x, __a), _M_iter_list(&_M_non_dbg_impl) {}
117 
118 #if defined(_STLP_DONT_SUP_DFLT_PARAM)
slist(size_type __n)119   explicit slist(size_type __n) : _M_non_dbg_impl(__n) , _M_iter_list(&_M_non_dbg_impl) {}
120 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
121 
122 #if !defined (_STLP_NO_MOVE_SEMANTIC)
slist(__move_source<_Self> src)123   slist(__move_source<_Self> src)
124     : _M_non_dbg_impl(__move_source<_Base>(src.get()._M_non_dbg_impl)),
125       _M_iter_list(&_M_non_dbg_impl) {
126 #  if defined (_STLP_NO_EXTENSIONS) || (_STLP_DEBUG_LEVEL == _STLP_STANDARD_DBG_LEVEL)
127     src.get()._M_iter_list._Invalidate_all();
128 #  else
129     src.get()._M_iter_list._Set_owner(_M_iter_list);
130 #  endif
131   }
132 #endif
133 
134 #if defined (_STLP_MEMBER_TEMPLATES)
135   // We don't need any dispatching tricks here, because _M_insert_after_range
136   // already does them.
137   template <class _InputIterator>
slist(_InputIterator __first,_InputIterator __last,const allocator_type & __a _STLP_ALLOCATOR_TYPE_DFL)138   slist(_InputIterator __first, _InputIterator __last,
139         const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
140     : _ConstructCheck(__first, __last),
141       _M_non_dbg_impl(_STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last), __a),
142       _M_iter_list(&_M_non_dbg_impl) {}
143 #  if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
144   template <class _InputIterator>
slist(_InputIterator __first,_InputIterator __last)145   slist(_InputIterator __first, _InputIterator __last)
146     : _ConstructCheck(__first, __last),
147       _M_non_dbg_impl(_STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last)),
148       _M_iter_list(&_M_non_dbg_impl) {}
149 #  endif
150 #else
151 
152   slist(const value_type* __first, const value_type* __last,
153         const allocator_type& __a =  allocator_type())
_ConstructCheck(__first,__last)154     : _ConstructCheck(__first, __last),
155       _M_non_dbg_impl(__first, __last, __a),
156       _M_iter_list(&_M_non_dbg_impl) {}
157 
158   slist(const_iterator __first, const_iterator __last,
159         const allocator_type& __a = allocator_type() )
_ConstructCheck(__first,__last)160     : _ConstructCheck(__first, __last),
161       _M_non_dbg_impl(__first._M_iterator, __last._M_iterator, __a),
162       _M_iter_list(&_M_non_dbg_impl) {}
163 #endif
164 
slist(const _Self & __x)165   slist(const _Self& __x) :
166     _ConstructCheck(__x),
167     _M_non_dbg_impl(__x._M_non_dbg_impl), _M_iter_list(&_M_non_dbg_impl) {}
168 
169   _Self& operator= (const _Self& __x) {
170     if (this != &__x) {
171       _Invalidate_iterators(begin(), end());
172       _M_non_dbg_impl = __x._M_non_dbg_impl;
173     }
174     return *this;
175   }
176 
~slist()177   ~slist() {}
178 
assign(size_type __n,const value_type & __val)179   void assign(size_type __n, const value_type& __val) {
180     _Invalidate_iterators(begin(), end());
181     _M_non_dbg_impl.assign(__n, __val);
182   }
183 
before_begin()184   iterator before_begin()
185   { return iterator(&_M_iter_list, _M_non_dbg_impl.before_begin()); }
before_begin()186   const_iterator before_begin() const
187   { return const_iterator(&_M_iter_list, _M_non_dbg_impl.before_begin()); }
188 
begin()189   iterator begin()
190   { return iterator(&_M_iter_list, _M_non_dbg_impl.begin()); }
begin()191   const_iterator begin() const
192   { return const_iterator(&_M_iter_list, _M_non_dbg_impl.begin());}
193 
end()194   iterator end()
195   { return iterator(&_M_iter_list, _M_non_dbg_impl.end()); }
end()196   const_iterator end() const
197   { return const_iterator(&_M_iter_list, _M_non_dbg_impl.end()); }
198 
empty()199   bool empty() const { return _M_non_dbg_impl.empty(); }
size()200   size_type size() const { return _M_non_dbg_impl.size(); }
max_size()201   size_type max_size() const { return _M_non_dbg_impl.max_size(); }
202 
swap(_Self & __x)203   void swap(_Self& __x) {
204     _M_iter_list._Swap_owners(__x._M_iter_list);
205     _M_non_dbg_impl.swap(__x._M_non_dbg_impl);
206   }
207 #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
_M_swap_workaround(_Self & __x)208   void _M_swap_workaround(_Self& __x) { swap(__x); }
209 #endif
210 
front()211   reference front() {
212     _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
213     return _M_non_dbg_impl.front();
214   }
front()215   const_reference front() const {
216     _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
217     return _M_non_dbg_impl.front();
218   }
push_front(const_reference __x)219   void push_front(const_reference __x) { _M_non_dbg_impl.push_front(__x); }
pop_front()220   void pop_front() {
221     _STLP_VERBOSE_ASSERT(!empty(), _StlMsg_EMPTY_CONTAINER)
222     _M_non_dbg_impl.pop_front();
223   }
previous(const_iterator __pos)224   iterator previous(const_iterator __pos) {
225     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
226     _STLP_VERBOSE_ASSERT(!(__pos._M_iterator == _M_non_dbg_impl.before_begin()), _StlMsg_INVALID_ARGUMENT)
227     return iterator(&_M_iter_list, _M_non_dbg_impl.previous(__pos._M_iterator));
228   }
previous(const_iterator __pos)229   const_iterator previous(const_iterator __pos) const {
230     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
231     _STLP_VERBOSE_ASSERT(!(__pos._M_iterator == _M_non_dbg_impl.before_begin()), _StlMsg_INVALID_ARGUMENT)
232     return const_iterator(&_M_iter_list, _M_non_dbg_impl.previous(__pos._M_iterator));
233   }
234 
235 public:
236 
237 #if !defined (_STLP_DONT_SUP_DFLT_PARAM)
238   iterator insert_after(iterator __pos, const value_type& __x = _Tp()) {
239 #else
240   iterator insert_after(iterator __pos, const value_type& __x) {
241 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
242     _STLP_DEBUG_CHECK(_STLP_PRIV _Dereferenceable(__pos))
243     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
244     return iterator(&_M_iter_list,_M_non_dbg_impl.insert_after(__pos._M_iterator, __x));
245   }
246 
247 #if defined (_STLP_DONT_SUP_DFLT_PARAM)
insert_after(iterator __pos)248   iterator insert_after(iterator __pos) {
249     return insert_after(__pos, _STLP_DEFAULT_CONSTRUCTED(_Tp));
250   }
251 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
252 
insert_after(iterator __pos,size_type __n,const value_type & __x)253   void insert_after(iterator __pos, size_type __n, const value_type& __x) {
254     _STLP_DEBUG_CHECK(_STLP_PRIV _Dereferenceable(__pos))
255     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
256     _M_non_dbg_impl.insert_after(__pos._M_iterator, __n, __x);
257   }
258 
259 #if defined (_STLP_MEMBER_TEMPLATES)
260   template <class _InputIterator>
assign(_InputIterator __first,_InputIterator __last)261   void assign(_InputIterator __first, _InputIterator __last) {
262     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
263     _Invalidate_iterators(begin(), end());
264     _M_non_dbg_impl.assign(_STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last));
265   }
266 #else
assign(const_iterator __first,const_iterator __last)267   void assign(const_iterator __first, const_iterator __last) {
268     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
269     _Invalidate_iterators(begin(), end());
270     _M_non_dbg_impl.assign(__first._M_iterator, __last._M_iterator);
271   }
assign(const value_type * __first,const value_type * __last)272   void assign(const value_type *__first, const value_type *__last) {
273     _STLP_DEBUG_CHECK(_STLP_PRIV __check_ptr_range(__first, __last))
274     _Invalidate_iterators(begin(), end());
275     _M_non_dbg_impl.assign(__first, __last);
276   }
277 #endif
278 
279 #if defined (_STLP_MEMBER_TEMPLATES)
280   template <class _InIter>
insert_after(iterator __pos,_InIter __first,_InIter __last)281   void insert_after(iterator __pos, _InIter __first, _InIter __last) {
282     _STLP_DEBUG_CHECK(_STLP_PRIV _Dereferenceable(__pos))
283     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
284     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
285     _M_non_dbg_impl.insert_after(__pos._M_iterator,
286                                  _STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last));
287   }
288 
289   template <class _InIter>
insert(iterator __pos,_InIter __first,_InIter __last)290   void insert(iterator __pos, _InIter __first, _InIter __last) {
291     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
292     _STLP_VERBOSE_ASSERT(!(__pos._M_iterator == _M_non_dbg_impl.before_begin()), _StlMsg_INVALID_ARGUMENT)
293     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
294     _M_non_dbg_impl.insert(__pos._M_iterator,
295                            _STLP_PRIV _Non_Dbg_iter(__first), _STLP_PRIV _Non_Dbg_iter(__last));
296   }
297 #else
insert_after(iterator __pos,const_iterator __first,const_iterator __last)298   void insert_after(iterator __pos,
299                     const_iterator __first, const_iterator __last) {
300     _STLP_DEBUG_CHECK(_STLP_PRIV _Dereferenceable(__pos))
301     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
302     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
303     _M_non_dbg_impl.insert_after(__pos._M_iterator, __first._M_iterator, __last._M_iterator);
304   }
insert_after(iterator __pos,const value_type * __first,const value_type * __last)305   void insert_after(iterator __pos,
306                     const value_type* __first, const value_type* __last) {
307     _STLP_DEBUG_CHECK(_STLP_PRIV _Dereferenceable(__pos))
308     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
309     _STLP_DEBUG_CHECK(_STLP_PRIV __check_ptr_range(__first, __last))
310     _M_non_dbg_impl.insert_after(__pos._M_iterator, __first, __last);
311   }
312 
insert(iterator __pos,const_iterator __first,const_iterator __last)313   void insert(iterator __pos, const_iterator __first, const_iterator __last) {
314     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
315     _STLP_VERBOSE_ASSERT(!(__pos._M_iterator == _M_non_dbg_impl.before_begin()), _StlMsg_INVALID_ARGUMENT)
316     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last))
317     _M_non_dbg_impl.insert(__pos._M_iterator, __first._M_iterator, __last._M_iterator);
318   }
insert(iterator __pos,const value_type * __first,const value_type * __last)319   void insert(iterator __pos, const value_type* __first,
320                               const value_type* __last) {
321     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list,__pos))
322     _STLP_VERBOSE_ASSERT(!(__pos._M_iterator == _M_non_dbg_impl.before_begin()), _StlMsg_INVALID_ARGUMENT)
323     _STLP_DEBUG_CHECK(_STLP_PRIV __check_ptr_range(__first, __last))
324     _M_non_dbg_impl.insert(__pos._M_iterator, __first, __last);
325   }
326 #endif
327 
328 #if !defined (_STLP_DONT_SUP_DFLT_PARAM)
329   iterator insert(iterator __pos, const value_type& __x = _Tp()) {
330 #else
331   iterator insert(iterator __pos, const value_type& __x) {
332 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
333     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
334     _STLP_VERBOSE_ASSERT(!(__pos._M_iterator == _M_non_dbg_impl.before_begin()), _StlMsg_INVALID_ARGUMENT)
335     return iterator(&_M_iter_list, _M_non_dbg_impl.insert(__pos._M_iterator, __x));
336   }
337 
338 #if defined (_STLP_DONT_SUP_DFLT_PARAM)
insert(iterator __pos)339   iterator insert(iterator __pos) {
340     return insert(__pos, _STLP_DEFAULT_CONSTRUCTED(_Tp));
341   }
342 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
343 
insert(iterator __pos,size_type __n,const value_type & __x)344   void insert(iterator __pos, size_type __n, const value_type& __x) {
345     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
346     _STLP_VERBOSE_ASSERT(!(__pos._M_iterator == _M_non_dbg_impl.before_begin()), _StlMsg_INVALID_ARGUMENT)
347     _M_non_dbg_impl.insert(__pos._M_iterator, __n, __x);
348   }
349 
350 public:
erase_after(iterator __pos)351   iterator erase_after(iterator __pos) {
352     _STLP_DEBUG_CHECK(_STLP_PRIV _Dereferenceable(__pos))
353     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list,__pos))
354     iterator __tmp = __pos; ++__tmp;
355     _STLP_DEBUG_CHECK(_STLP_PRIV _Dereferenceable(__tmp))
356     _Invalidate_iterator(__tmp);
357     return iterator(&_M_iter_list, _M_non_dbg_impl.erase_after(__pos._M_iterator));
358   }
erase_after(iterator __before_first,iterator __last)359   iterator erase_after(iterator __before_first, iterator __last) {
360     _STLP_DEBUG_CHECK(_STLP_PRIV _Dereferenceable(__before_first))
361     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__before_first, __last, begin(), end()))
362     iterator __tmp = __before_first; ++__tmp;
363     _STLP_DEBUG_CHECK(_STLP_PRIV _Dereferenceable(__tmp))
364     _Invalidate_iterators(__tmp, __last);
365     return iterator(&_M_iter_list, _M_non_dbg_impl.erase_after(__before_first._M_iterator, __last._M_iterator));
366   }
367 
erase(iterator __pos)368   iterator erase(iterator __pos) {
369     _STLP_DEBUG_CHECK(_STLP_PRIV _Dereferenceable(__pos))
370     _STLP_VERBOSE_ASSERT(__pos._M_iterator != _M_non_dbg_impl.before_begin(), _StlMsg_INVALID_ARGUMENT)
371     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
372     _Invalidate_iterator(__pos);
373     return iterator(&_M_iter_list, _M_non_dbg_impl.erase(__pos._M_iterator));
374   }
erase(iterator __first,iterator __last)375   iterator erase(iterator __first, iterator __last) {
376     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last, begin(), end()))
377     _Invalidate_iterators(__first, __last);
378     return iterator(&_M_iter_list, _M_non_dbg_impl.erase(__first._M_iterator, __last._M_iterator));
379   }
380 
381 #if !defined(_STLP_DONT_SUP_DFLT_PARAM)
382   void resize(size_type __new_size, const value_type& __x = _Tp()) {
383 #else
384   void resize(size_type __new_size, const value_type& __x) {
385 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
386     _M_non_dbg_impl.resize(__new_size, __x);
387   }
388 
389 #if defined(_STLP_DONT_SUP_DFLT_PARAM)
resize(size_type __new_size)390   void resize(size_type __new_size) { resize(__new_size, _STLP_DEFAULT_CONSTRUCTED(_Tp)); }
391 #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
392 
clear()393   void clear() {
394     _Invalidate_iterators(begin(), end());
395     _M_non_dbg_impl.clear();
396   }
397 
398 public:
399   // Removes all of the elements from the list __x to *this, inserting
400   // them immediately after __pos.  __x must not be *this.  Complexity:
401   // linear in __x.size().
splice_after(iterator __pos,_Self & __x)402   void splice_after(iterator __pos, _Self& __x) {
403     _STLP_DEBUG_CHECK(_STLP_PRIV _Dereferenceable(__pos))
404     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list,__pos))
405     _STLP_VERBOSE_ASSERT(!(&__x == this), _StlMsg_INVALID_ARGUMENT)
406     _M_non_dbg_impl.splice_after(__pos._M_iterator, __x._M_non_dbg_impl);
407     if (get_allocator() == __x.get_allocator()) {
408       __x._M_iter_list._Set_owner(_M_iter_list);
409     }
410     else {
411       __x._Invalidate_iterators(__x.begin(), __x.end());
412     }
413   }
414 
415   // Moves the element that follows __prev to *this, inserting it immediately
416   //  after __pos.  This is constant time.
splice_after(iterator __pos,_Self & __x,iterator __prev)417   void splice_after(iterator __pos, _Self& __x, iterator __prev) {
418     _STLP_DEBUG_CHECK(_STLP_PRIV _Dereferenceable(__pos))
419     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list, __pos))
420     _STLP_DEBUG_CHECK(_STLP_PRIV _Dereferenceable(__prev))
421     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&__x._M_iter_list, __prev))
422     iterator __elem = __prev; ++__elem;
423     _M_non_dbg_impl.splice_after(__pos._M_iterator, __x._M_non_dbg_impl, __prev._M_iterator);
424     if (get_allocator() == __x.get_allocator()) {
425       _STLP_PRIV __change_ite_owner(__elem, &_M_iter_list);
426     }
427     else {
428       __x._Invalidate_iterator(__elem);
429     }
430   }
431 
432   // Moves the range [__before_first + 1, __before_last + 1) to *this,
433   //  inserting it immediately after __pos.  This is constant time.
splice_after(iterator __pos,_Self & __x,iterator __before_first,iterator __before_last)434   void splice_after(iterator __pos, _Self& __x,
435                     iterator __before_first, iterator __before_last) {
436     _STLP_DEBUG_CHECK(_STLP_PRIV _Dereferenceable(__pos))
437     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list,__pos))
438     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__before_first, __before_last))
439     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&__x._M_iter_list, __before_first))
440     _STLP_DEBUG_CHECK(_STLP_PRIV _Dereferenceable(__before_first))
441     _STLP_DEBUG_CHECK(_STLP_PRIV _Dereferenceable(__before_last))
442     iterator __first = __before_first; ++__first;
443     iterator __last = __before_last; ++__last;
444     if (get_allocator() == __x.get_allocator()) {
445       _STLP_PRIV __change_range_owner(__first, __last, &_M_iter_list);
446     }
447     else {
448       __x._Invalidate_iterators(__first, __last);
449     }
450     _M_non_dbg_impl.splice_after(__pos._M_iterator, __x._M_non_dbg_impl,
451                                  __before_first._M_iterator, __before_last._M_iterator);
452   }
453 
splice(iterator __pos,_Self & __x)454   void splice(iterator __pos, _Self& __x) {
455     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list,__pos))
456     _STLP_VERBOSE_ASSERT(!(__pos._M_iterator == _M_non_dbg_impl.before_begin()), _StlMsg_INVALID_ARGUMENT)
457     _STLP_VERBOSE_ASSERT(!(&__x == this), _StlMsg_INVALID_ARGUMENT)
458     _M_non_dbg_impl.splice(__pos._M_iterator, __x._M_non_dbg_impl);
459     if (get_allocator() == __x.get_allocator()) {
460       __x._M_iter_list._Set_owner(_M_iter_list);
461     }
462     else {
463       __x._Invalidate_iterators(__x.begin(), __x.end());
464     }
465   }
466 
splice(iterator __pos,_Self & __x,iterator __i)467   void splice(iterator __pos, _Self& __x, iterator __i) {
468     //__pos should be owned by *this and not be the before_begin iterator
469     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list,__pos))
470     _STLP_VERBOSE_ASSERT(!(__pos._M_iterator == _M_non_dbg_impl.before_begin()), _StlMsg_INVALID_ARGUMENT)
471     //__i should be dereferenceable, not before_begin and be owned by __x
472     _STLP_DEBUG_CHECK(_STLP_PRIV _Dereferenceable(__i))
473     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&__x._M_iter_list ,__i))
474     _STLP_VERBOSE_ASSERT(!(__i == __x.before_begin()), _StlMsg_INVALID_ARGUMENT)
475     if (get_allocator() == __x.get_allocator()) {
476       _STLP_PRIV __change_ite_owner(__i, &_M_iter_list);
477     }
478     else {
479       __x._Invalidate_iterator(__i);
480     }
481     _M_non_dbg_impl.splice(__pos._M_iterator, __x._M_non_dbg_impl, __i._M_iterator);
482   }
483 
splice(iterator __pos,_Self & __x,iterator __first,iterator __last)484   void splice(iterator __pos, _Self& __x, iterator __first, iterator __last) {
485     _STLP_DEBUG_CHECK(_STLP_PRIV __check_if_owner(&_M_iter_list,__pos))
486     _STLP_VERBOSE_ASSERT(!(__pos._M_iterator == _M_non_dbg_impl.before_begin()), _StlMsg_INVALID_ARGUMENT)
487     //_STLP_VERBOSE_ASSERT(&__x != this, _StlMsg_INVALID_ARGUMENT)
488     _STLP_DEBUG_CHECK(_STLP_PRIV __check_range(__first, __last, __x.begin(), __x.end()))
489     if (get_allocator() == __x.get_allocator()) {
490       _STLP_PRIV __change_range_owner(__first, __last, &_M_iter_list);
491     }
492     else {
493       __x._Invalidate_iterators(__first, __last);
494     }
495     _M_non_dbg_impl.splice(__pos._M_iterator, __x._M_non_dbg_impl,
496                            __first._M_iterator, __last._M_iterator);
497   }
498 
reverse()499   void reverse()
500   { _M_non_dbg_impl.reverse(); }
501 
remove(const value_type & __val)502   void remove(const value_type& __val) {
503     _Base_iterator __first = _M_non_dbg_impl.begin(), __last = _M_non_dbg_impl.end();
504     while (__first != __last) {
505       _Base_iterator __next = __first;
506       ++__next;
507       if (__val == *__first) {
508         _Invalidate_iterator(iterator(&_M_iter_list, __first));
509         _M_non_dbg_impl.erase(__first);
510       }
511       __first = __next;
512     }
513   }
unique()514   void unique() {
515     _Base_iterator __first = _M_non_dbg_impl.begin(), __last = _M_non_dbg_impl.end();
516     if (__first == __last) return;
517     _Base_iterator __next = __first;
518     while (++__next != __last) {
519       if (*__first == *__next) {
520         _Invalidate_iterator(iterator(&_M_iter_list, __next));
521         _M_non_dbg_impl.erase(__next);
522       }
523       else
524         __first = __next;
525       __next = __first;
526     }
527   }
merge(_Self & __x)528   void merge(_Self& __x) {
529     _STLP_VERBOSE_ASSERT(&__x != this, _StlMsg_INVALID_ARGUMENT)
530 #if !defined (_STLP_NO_EXTENSIONS)
531     /* comments below due to bug in GCC compilers: ones eat all memory  and die if see
532      * something like namespace_name::func_name() - ptr
533      */
534     _STLP_DEBUG_CHECK( /* _STLP_STD:: */ is_sorted(_M_non_dbg_impl.begin(), _M_non_dbg_impl.end()))
535     _STLP_DEBUG_CHECK( /* _STLP_STD:: */ is_sorted(__x.begin()._M_iterator, __x.end()._M_iterator))
536 #endif
537     _M_non_dbg_impl.merge(__x._M_non_dbg_impl);
538     if (get_allocator() == __x.get_allocator()) {
539       __x._M_iter_list._Set_owner(_M_iter_list);
540     }
541     else {
542       __x._Invalidate_iterators(__x.begin(), __x.end());
543     }
544   }
sort()545   void sort() {
546     _M_non_dbg_impl.sort();
547   }
548 
549 #if defined (_STLP_MEMBER_TEMPLATES)
550   template <class _Predicate>
remove_if(_Predicate __pred)551   void remove_if(_Predicate __pred) {
552     _Base_iterator __first = _M_non_dbg_impl.begin(), __last = _M_non_dbg_impl.end();
553     while (__first != __last) {
554       _Base_iterator __next = __first;
555       ++__next;
556       if (__pred(*__first)) {
557         _Invalidate_iterator(iterator(&_M_iter_list, __first));
558         _M_non_dbg_impl.erase(__first);
559       }
560       __first = __next;
561     }
562   }
563 
564   template <class _BinaryPredicate>
unique(_BinaryPredicate __pred)565   void unique(_BinaryPredicate __pred) {
566     _Base_iterator __first = _M_non_dbg_impl.begin(), __last = _M_non_dbg_impl.end();
567     if (__first == __last) return;
568     _Base_iterator __next = __first;
569     while (++__next != __last) {
570       if (__binary_pred(*__first, *__next)) {
571         _Invalidate_iterator(iterator(&_M_iter_list, __next));
572         _M_non_dbg_impl.erase(__next);
573       }
574       else
575         __first = __next;
576       __next = __first;
577     }
578   }
579 
580   template <class _StrictWeakOrdering>
merge(_Self & __x,_StrictWeakOrdering __ord)581   void merge(_Self& __x, _StrictWeakOrdering __ord) {
582     _STLP_VERBOSE_ASSERT(&__x != this, _StlMsg_INVALID_ARGUMENT)
583 #if !defined (_STLP_NO_EXTENSIONS)
584     /* comments below due to bug in GCC compilers: ones eat all memory  and die if see
585      * something like namespace_name::func_name() - ptr
586      */
587     _STLP_DEBUG_CHECK( /* _STLP_STD:: */ is_sorted(_M_non_dbg_impl.begin(), _M_non_dbg_impl.end(), __ord))
588     _STLP_DEBUG_CHECK( /* _STLP_STD:: */ is_sorted(__x.begin()._M_iterator, __x.end()._M_iterator, __ord))
589 #endif
590     _M_non_dbg_impl.merge(__x._M_non_dbg_impl, __ord);
591     if (get_allocator() == __x.get_allocator()) {
592       __x._M_iter_list._Set_owner(_M_iter_list);
593     }
594     else {
595       __x._Invalidate_iterators(__x.begin(), __x.end());
596     }
597   }
598 
599   template <class _StrictWeakOrdering>
sort(_StrictWeakOrdering __comp)600   void sort(_StrictWeakOrdering __comp)
601   { _M_non_dbg_impl.sort(__comp); }
602 #endif
603 };
604 
605 _STLP_END_NAMESPACE
606 
607 #undef _STLP_NON_DBG_SLIST
608 
609 #endif /* _STLP_INTERNAL_DBG_SLIST_H */
610 
611 // Local Variables:
612 // mode:C++
613 // End:
614