_slist.h 23 KB

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