_list.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. /*
  2. *
  3. * Copyright (c) 1994
  4. * Hewlett-Packard Company
  5. *
  6. * Copyright (c) 1996,1997
  7. * Silicon Graphics Computer Systems, Inc.
  8. *
  9. * Copyright (c) 1997
  10. * Moscow Center for SPARC Technology
  11. *
  12. * Copyright (c) 1999
  13. * Boris Fomitchev
  14. *
  15. * This material is provided "as is", with absolutely no warranty expressed
  16. * or implied. Any use is at your own risk.
  17. *
  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.
  23. *
  24. */
  25. /* NOTE: This is an internal header file, included by other STL headers.
  26. * You should not attempt to use it directly.
  27. */
  28. #ifndef _STLP_INTERNAL_LIST_IMPL_H
  29. #define _STLP_INTERNAL_LIST_IMPL_H
  30. #ifndef _STLP_INTERNAL_ALGOBASE_H
  31. # include <stl/_algobase.h>
  32. #endif
  33. #ifndef _STLP_INTERNAL_ALLOC_H
  34. # include <stl/_alloc.h>
  35. #endif
  36. #ifndef _STLP_INTERNAL_ITERATOR_H
  37. # include <stl/_iterator.h>
  38. #endif
  39. #ifndef _STLP_INTERNAL_CONSTRUCT_H
  40. # include <stl/_construct.h>
  41. #endif
  42. #ifndef _STLP_INTERNAL_FUNCTION_BASE_H
  43. # include <stl/_function_base.h>
  44. #endif
  45. _STLP_BEGIN_NAMESPACE
  46. _STLP_MOVE_TO_PRIV_NAMESPACE
  47. struct _List_node_base {
  48. _List_node_base* _M_next;
  49. _List_node_base* _M_prev;
  50. };
  51. template <class _Dummy>
  52. class _List_global {
  53. public:
  54. typedef _List_node_base _Node_base;
  55. static void _STLP_CALL _Transfer(_Node_base* __pos,
  56. _Node_base* __first, _Node_base* __last);
  57. };
  58. #if defined (_STLP_USE_TEMPLATE_EXPORT)
  59. _STLP_EXPORT_TEMPLATE_CLASS _List_global<bool>;
  60. #endif
  61. typedef _List_global<bool> _List_global_inst;
  62. template <class _Tp>
  63. class _List_node : public _List_node_base {
  64. public:
  65. _Tp _M_data;
  66. __TRIVIAL_STUFF(_List_node)
  67. };
  68. struct _List_iterator_base {
  69. typedef size_t size_type;
  70. typedef ptrdiff_t difference_type;
  71. typedef bidirectional_iterator_tag iterator_category;
  72. _List_node_base* _M_node;
  73. _List_iterator_base(_List_node_base* __x) : _M_node(__x) {}
  74. void _M_incr() { _M_node = _M_node->_M_next; }
  75. void _M_decr() { _M_node = _M_node->_M_prev; }
  76. };
  77. template<class _Tp, class _Traits>
  78. struct _List_iterator : public _List_iterator_base {
  79. typedef _Tp value_type;
  80. typedef typename _Traits::pointer pointer;
  81. typedef typename _Traits::reference reference;
  82. typedef _List_iterator<_Tp, _Traits> _Self;
  83. typedef typename _Traits::_NonConstTraits _NonConstTraits;
  84. typedef _List_iterator<_Tp, _NonConstTraits> iterator;
  85. typedef typename _Traits::_ConstTraits _ConstTraits;
  86. typedef _List_iterator<_Tp, _ConstTraits> const_iterator;
  87. typedef bidirectional_iterator_tag iterator_category;
  88. typedef _List_node<_Tp> _Node;
  89. typedef size_t size_type;
  90. typedef ptrdiff_t difference_type;
  91. explicit _List_iterator(_List_node_base* __x) : _List_iterator_base(__x) {}
  92. _List_iterator() : _List_iterator_base(0) {}
  93. //copy constructor for iterator and constructor from iterator for const_iterator
  94. _List_iterator(const iterator& __x) : _List_iterator_base(__x._M_node) {}
  95. reference operator*() const { return __STATIC_CAST(_Node*, this->_M_node)->_M_data; }
  96. _STLP_DEFINE_ARROW_OPERATOR
  97. _Self& operator++() {
  98. this->_M_incr();
  99. return *this;
  100. }
  101. _Self operator++(int) {
  102. _Self __tmp = *this;
  103. this->_M_incr();
  104. return __tmp;
  105. }
  106. _Self& operator--() {
  107. this->_M_decr();
  108. return *this;
  109. }
  110. _Self operator--(int) {
  111. _Self __tmp = *this;
  112. this->_M_decr();
  113. return __tmp;
  114. }
  115. bool operator==(const_iterator __y ) const {
  116. return this->_M_node == __y._M_node;
  117. }
  118. bool operator!=(const_iterator __y ) const {
  119. return this->_M_node != __y._M_node;
  120. }
  121. };
  122. #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
  123. _STLP_MOVE_TO_STD_NAMESPACE
  124. template <class _Tp, class _Traits>
  125. struct __type_traits<_STLP_PRIV _List_iterator<_Tp, _Traits> > {
  126. typedef __false_type has_trivial_default_constructor;
  127. typedef __true_type has_trivial_copy_constructor;
  128. typedef __true_type has_trivial_assignment_operator;
  129. typedef __true_type has_trivial_destructor;
  130. typedef __false_type is_POD_type;
  131. };
  132. _STLP_MOVE_TO_PRIV_NAMESPACE
  133. #endif
  134. #if defined (_STLP_USE_OLD_HP_ITERATOR_QUERIES)
  135. _STLP_MOVE_TO_STD_NAMESPACE
  136. template <class _Tp, class _Traits>
  137. inline _Tp* value_type(const _STLP_PRIV _List_iterator<_Tp, _Traits>&) { return 0; }
  138. inline bidirectional_iterator_tag iterator_category(const _STLP_PRIV _List_iterator_base&) { return bidirectional_iterator_tag();}
  139. inline ptrdiff_t* distance_type(const _STLP_PRIV _List_iterator_base&) { return 0; }
  140. _STLP_MOVE_TO_PRIV_NAMESPACE
  141. #endif
  142. // Base class that encapsulates details of allocators and helps
  143. // to simplify EH
  144. template <class _Tp, class _Alloc>
  145. class _List_base {
  146. protected:
  147. _STLP_FORCE_ALLOCATORS(_Tp, _Alloc)
  148. typedef _List_node_base _Node_base;
  149. typedef _List_node<_Tp> _Node;
  150. typedef _List_base<_Tp, _Alloc> _Self;
  151. typedef typename _Alloc_traits<_Node, _Alloc>::allocator_type _Node_allocator_type;
  152. public:
  153. typedef _STLP_alloc_proxy<_Node_base, _Node, _Node_allocator_type> _AllocProxy;
  154. typedef _Alloc allocator_type;
  155. allocator_type get_allocator() const
  156. { return _STLP_CONVERT_ALLOCATOR((const _Node_allocator_type&)_M_node, _Tp); }
  157. _List_base(const allocator_type& __a) : _M_node(_STLP_CONVERT_ALLOCATOR(__a, _Node), _Node_base())
  158. { _M_empty_initialize(); }
  159. #if !defined (_STLP_NO_MOVE_SEMANTIC)
  160. _List_base(__move_source<_Self> src) :
  161. _M_node(__move_source<_AllocProxy>(src.get()._M_node)) {
  162. if (src.get().empty())
  163. //We force this to empty.
  164. _M_empty_initialize();
  165. else {
  166. src.get()._M_empty_initialize();
  167. _M_node._M_data._M_prev->_M_next = _M_node._M_data._M_next->_M_prev = &_M_node._M_data;
  168. }
  169. }
  170. #endif
  171. ~_List_base()
  172. { clear(); }
  173. void clear();
  174. bool empty() const { return _M_node._M_data._M_next == &_M_node._M_data; }
  175. void _M_empty_initialize() {
  176. _M_node._M_data._M_next = &_M_node._M_data;
  177. _M_node._M_data._M_prev = _M_node._M_data._M_next;
  178. }
  179. public:
  180. _AllocProxy _M_node;
  181. };
  182. #if defined (_STLP_USE_PTR_SPECIALIZATIONS)
  183. # define list _STLP_PTR_IMPL_NAME(list)
  184. #elif defined (_STLP_DEBUG)
  185. # define list _STLP_NON_DBG_NAME(list)
  186. #else
  187. _STLP_MOVE_TO_STD_NAMESPACE
  188. #endif
  189. template <class _Tp, _STLP_DFL_TMPL_PARAM(_Alloc, allocator<_Tp>) >
  190. class list;
  191. #if !defined (list)
  192. _STLP_MOVE_TO_PRIV_NAMESPACE
  193. #endif
  194. // helper functions to reduce code duplication
  195. template <class _Tp, class _Alloc, class _Predicate>
  196. void _S_remove_if(list<_Tp, _Alloc>& __that, _Predicate __pred);
  197. template <class _Tp, class _Alloc, class _BinaryPredicate>
  198. void _S_unique(list<_Tp, _Alloc>& __that, _BinaryPredicate __binary_pred);
  199. template <class _Tp, class _Alloc, class _StrictWeakOrdering>
  200. void _S_merge(list<_Tp, _Alloc>& __that, list<_Tp, _Alloc>& __x,
  201. _StrictWeakOrdering __comp);
  202. template <class _Tp, class _Alloc, class _StrictWeakOrdering>
  203. void _S_sort(list<_Tp, _Alloc>& __that, _StrictWeakOrdering __comp);
  204. #if !defined (list)
  205. _STLP_MOVE_TO_STD_NAMESPACE
  206. #endif
  207. template <class _Tp, class _Alloc>
  208. class list : public _STLP_PRIV _List_base<_Tp, _Alloc>
  209. #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (list)
  210. , public __stlport_class<list<_Tp, _Alloc> >
  211. #endif
  212. {
  213. typedef _STLP_PRIV _List_base<_Tp, _Alloc> _Base;
  214. typedef list<_Tp, _Alloc> _Self;
  215. typedef _STLP_PRIV _List_node<_Tp> _Node;
  216. typedef _STLP_PRIV _List_node_base _Node_base;
  217. public:
  218. typedef _Tp value_type;
  219. typedef value_type* pointer;
  220. typedef const value_type* const_pointer;
  221. typedef value_type& reference;
  222. typedef const value_type& const_reference;
  223. typedef size_t size_type;
  224. typedef ptrdiff_t difference_type;
  225. _STLP_FORCE_ALLOCATORS(_Tp, _Alloc)
  226. typedef typename _Base::allocator_type allocator_type;
  227. typedef bidirectional_iterator_tag _Iterator_category;
  228. public:
  229. typedef _STLP_PRIV _List_iterator<_Tp, _Nonconst_traits<_Tp> > iterator;
  230. typedef _STLP_PRIV _List_iterator<_Tp, _Const_traits<_Tp> > const_iterator;
  231. _STLP_DECLARE_BIDIRECTIONAL_REVERSE_ITERATORS;
  232. protected:
  233. #if !defined (_STLP_DONT_SUP_DFLT_PARAM)
  234. _Node_base* _M_create_node(const_reference __x = value_type()) {
  235. #else
  236. _Node_base* _M_create_node(const_reference __x) {
  237. #endif
  238. _Node* __p = this->_M_node.allocate(1);
  239. _STLP_TRY {
  240. _Copy_Construct(&__p->_M_data, __x);
  241. }
  242. _STLP_UNWIND(this->_M_node.deallocate(__p, 1))
  243. return __p;
  244. }
  245. #if defined (_STLP_DONT_SUP_DFLT_PARAM)
  246. _Node_base* _M_create_node() {
  247. _Node* __p = this->_M_node.allocate(1);
  248. _STLP_TRY {
  249. _STLP_STD::_Construct(&__p->_M_data);
  250. }
  251. _STLP_UNWIND(this->_M_node.deallocate(__p, 1))
  252. return __p;
  253. }
  254. #endif
  255. public:
  256. #if !defined (_STLP_DONT_SUP_DFLT_PARAM)
  257. explicit list(size_type __n, const_reference __val = _STLP_DEFAULT_CONSTRUCTED(value_type),
  258. const allocator_type& __a = allocator_type())
  259. #else
  260. explicit list(size_type __n)
  261. : _STLP_PRIV _List_base<_Tp, _Alloc>(allocator_type())
  262. { this->insert(begin(), __n, _STLP_DEFAULT_CONSTRUCTED(value_type)); }
  263. list(size_type __n, const_reference __val)
  264. : _STLP_PRIV _List_base<_Tp, _Alloc>(allocator_type())
  265. { this->insert(begin(), __n, __val); }
  266. list(size_type __n, const_reference __val, const allocator_type& __a)
  267. #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
  268. : _STLP_PRIV _List_base<_Tp, _Alloc>(__a)
  269. { this->insert(begin(), __n, __val); }
  270. #if defined (_STLP_MEMBER_TEMPLATES)
  271. // We don't need any dispatching tricks here, because insert does all of
  272. // that anyway.
  273. template <class _InputIterator>
  274. list(_InputIterator __first, _InputIterator __last,
  275. const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
  276. : _STLP_PRIV _List_base<_Tp, _Alloc>(__a)
  277. { _M_insert(begin(), __first, __last); }
  278. # if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
  279. template <class _InputIterator>
  280. list(_InputIterator __first, _InputIterator __last)
  281. : _STLP_PRIV _List_base<_Tp, _Alloc>(allocator_type())
  282. { _M_insert(begin(), __first, __last); }
  283. # endif
  284. #else /* _STLP_MEMBER_TEMPLATES */
  285. list(const value_type* __first, const value_type* __last,
  286. const allocator_type& __a = allocator_type())
  287. : _STLP_PRIV _List_base<_Tp, _Alloc>(__a)
  288. { _M_insert(begin(), __first, __last); }
  289. list(const_iterator __first, const_iterator __last,
  290. const allocator_type& __a = allocator_type())
  291. : _STLP_PRIV _List_base<_Tp, _Alloc>(__a)
  292. { _M_insert(begin(), __first, __last); }
  293. #endif /* _STLP_MEMBER_TEMPLATES */
  294. #if !defined (_STLP_DONT_SUP_DFLT_PARAM)
  295. explicit list(const allocator_type& __a = allocator_type())
  296. #else
  297. list()
  298. : _STLP_PRIV _List_base<_Tp, _Alloc>(allocator_type()) {}
  299. list(const allocator_type& __a)
  300. #endif
  301. : _STLP_PRIV _List_base<_Tp, _Alloc>(__a) {}
  302. list(const _Self& __x) : _STLP_PRIV _List_base<_Tp, _Alloc>(__x.get_allocator())
  303. { _M_insert(begin(), __x.begin(), __x.end()); }
  304. #if !defined (_STLP_NO_MOVE_SEMANTIC)
  305. list(__move_source<_Self> src)
  306. : _STLP_PRIV _List_base<_Tp, _Alloc>(__move_source<_Base>(src.get())) {}
  307. #endif
  308. ~list() {}
  309. _Self& operator = (const _Self& __x);
  310. iterator begin() { return iterator(this->_M_node._M_data._M_next); }
  311. const_iterator begin() const { return const_iterator(this->_M_node._M_data._M_next); }
  312. iterator end() { return iterator(&this->_M_node._M_data); }
  313. const_iterator end() const { return const_iterator(__CONST_CAST(_Node_base*, &this->_M_node._M_data)); }
  314. reverse_iterator rbegin() { return reverse_iterator(end()); }
  315. const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
  316. reverse_iterator rend() { return reverse_iterator(begin()); }
  317. const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
  318. size_type size() const {
  319. size_type __result = _STLP_STD::distance(begin(), end());
  320. return __result;
  321. }
  322. size_type max_size() const { return size_type(-1); }
  323. reference front() { return *begin(); }
  324. const_reference front() const { return *begin(); }
  325. reference back() { return *(--end()); }
  326. const_reference back() const { return *(--end()); }
  327. private:
  328. void _M_swap_aux(_Self& __x) {
  329. __x._M_node._M_swap_alloc(this->_M_node);
  330. __x._M_node._M_data._M_next = this->_M_node._M_data._M_next;
  331. __x._M_node._M_data._M_next->_M_prev = &__x._M_node._M_data;
  332. __x._M_node._M_data._M_prev = this->_M_node._M_data._M_prev;
  333. __x._M_node._M_data._M_prev->_M_next = &__x._M_node._M_data;
  334. this->_M_empty_initialize();
  335. }
  336. public:
  337. void swap(_Self& __x) {
  338. if (__x.empty()) {
  339. if (this->empty()) {
  340. return;
  341. }
  342. this->_M_swap_aux(__x);
  343. } else if (this->empty()) {
  344. __x._M_swap_aux(*this);
  345. } else {
  346. this->_M_node.swap(__x._M_node);
  347. _STLP_STD::swap(this->_M_node._M_data._M_prev->_M_next, __x._M_node._M_data._M_prev->_M_next);
  348. _STLP_STD::swap(this->_M_node._M_data._M_next->_M_prev, __x._M_node._M_data._M_next->_M_prev);
  349. }
  350. }
  351. #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
  352. void _M_swap_workaround(_Self& __x) { swap(__x); }
  353. #endif
  354. #if !defined(_STLP_DONT_SUP_DFLT_PARAM) && !defined(_STLP_NO_ANACHRONISMS)
  355. iterator insert(iterator __pos, const_reference __x = value_type())
  356. #else
  357. iterator insert(iterator __pos, const_reference __x)
  358. #endif /*!_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
  359. {
  360. _Node_base* __tmp = _M_create_node(__x);
  361. _Node_base* __n = __pos._M_node;
  362. _Node_base* __p = __n->_M_prev;
  363. __tmp->_M_next = __n;
  364. __tmp->_M_prev = __p;
  365. __p->_M_next = __tmp;
  366. __n->_M_prev = __tmp;
  367. return iterator(__tmp);
  368. }
  369. private:
  370. #if defined (_STLP_MEMBER_TEMPLATES)
  371. template <class _InputIterator>
  372. void _M_insert(iterator __pos, _InputIterator __first, _InputIterator __last) {
  373. typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
  374. _M_insert_dispatch(__pos, __first, __last, _Integral());
  375. }
  376. // Check whether it's an integral type. If so, it's not an iterator.
  377. template<class _Integer>
  378. void _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __x,
  379. const __true_type& /*_IsIntegral*/) {
  380. _M_fill_insert(__pos, __n, __x);
  381. }
  382. template <class _InputIter>
  383. void _M_insert_dispatch(iterator __pos,
  384. _InputIter __first, _InputIter __last,
  385. const __false_type& /*_IsIntegral*/) {
  386. #else /* _STLP_MEMBER_TEMPLATES */
  387. void _M_insert(iterator __pos, const value_type* __first, const value_type* __last) {
  388. for (; __first != __last; ++__first)
  389. insert(__pos, *__first);
  390. }
  391. void _M_insert(iterator __pos, const_iterator __first, const_iterator __last) {
  392. #endif /* _STLP_MEMBER_TEMPLATES */
  393. //We use a temporary list to avoid the auto reference troubles (infinite loop)
  394. for (; __first != __last; ++__first)
  395. insert(__pos, *__first);
  396. }
  397. public:
  398. #if defined (_STLP_MEMBER_TEMPLATES)
  399. template <class _InputIterator>
  400. void insert(iterator __pos, _InputIterator __first, _InputIterator __last) {
  401. typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
  402. _M_splice_insert_dispatch(__pos, __first, __last, _Integral());
  403. }
  404. private:
  405. // Check whether it's an integral type. If so, it's not an iterator.
  406. template<class _Integer>
  407. void _M_splice_insert_dispatch(iterator __pos, _Integer __n, _Integer __x,
  408. const __true_type& /*_IsIntegral*/) {
  409. _M_fill_insert(__pos, __n, __x);
  410. }
  411. template <class _InputIter>
  412. void _M_splice_insert_dispatch(iterator __pos,
  413. _InputIter __first, _InputIter __last,
  414. const __false_type& /*_IsIntegral*/) {
  415. #else /* _STLP_MEMBER_TEMPLATES */
  416. void insert(iterator __pos, const value_type* __first, const value_type* __last) {
  417. _Self __tmp(__first, __last, this->get_allocator());
  418. _STLP_ASSERT(__tmp.get_allocator() == this->get_allocator())
  419. splice(__pos, __tmp);
  420. }
  421. void insert(iterator __pos, const_iterator __first, const_iterator __last) {
  422. #endif /* _STLP_MEMBER_TEMPLATES */
  423. //We use a temporary list to avoid the auto reference troubles (infinite loop)
  424. _Self __tmp(__first, __last, this->get_allocator());
  425. splice(__pos, __tmp);
  426. }
  427. public:
  428. void insert(iterator __pos, size_type __n, const_reference __x)
  429. { _M_fill_insert(__pos, __n, __x); }
  430. private:
  431. void _M_fill_insert(iterator __pos, size_type __n, const_reference __x) {
  432. for ( ; __n > 0; --__n)
  433. insert(__pos, __x);
  434. }
  435. public:
  436. void push_front(const_reference __x) { insert(begin(), __x); }
  437. void push_back (const_reference __x) { insert(end(), __x); }
  438. #if defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
  439. iterator insert(iterator __pos)
  440. { return insert(__pos, _STLP_DEFAULT_CONSTRUCTED(value_type)); }
  441. void push_front() {insert(begin());}
  442. void push_back() {insert(end());}
  443. # endif /*_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
  444. iterator erase(iterator __pos) {
  445. _Node_base* __next_node = __pos._M_node->_M_next;
  446. _Node_base* __prev_node = __pos._M_node->_M_prev;
  447. _Node* __n = __STATIC_CAST(_Node*, __pos._M_node);
  448. __prev_node->_M_next = __next_node;
  449. __next_node->_M_prev = __prev_node;
  450. _STLP_STD::_Destroy(&__n->_M_data);
  451. this->_M_node.deallocate(__n, 1);
  452. return iterator(__next_node);
  453. }
  454. iterator erase(iterator __first, iterator __last) {
  455. while (__first != __last)
  456. erase(__first++);
  457. return __last;
  458. }
  459. #if !defined (_STLP_DONT_SUP_DFLT_PARAM)
  460. void resize(size_type __new_size, const_reference __x = value_type());
  461. #else
  462. void resize(size_type __new_size, const_reference __x);
  463. void resize(size_type __new_size)
  464. { this->resize(__new_size, _STLP_DEFAULT_CONSTRUCTED(value_type)); }
  465. #endif /*!_STLP_DONT_SUP_DFLT_PARAM*/
  466. void pop_front() { erase(begin()); }
  467. void pop_back() {
  468. iterator __tmp = end();
  469. erase(--__tmp);
  470. }
  471. public:
  472. // assign(), a generalized assignment member function. Two
  473. // versions: one that takes a count, and one that takes a range.
  474. // The range version is a member template, so we dispatch on whether
  475. // or not the type is an integer.
  476. void assign(size_type __n, const_reference __val) { _M_fill_assign(__n, __val); }
  477. void _M_fill_assign(size_type __n, const_reference __val);
  478. #if defined (_STLP_MEMBER_TEMPLATES)
  479. template <class _InputIterator>
  480. void assign(_InputIterator __first, _InputIterator __last) {
  481. typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
  482. _M_assign_dispatch(__first, __last, _Integral());
  483. }
  484. template <class _Integer>
  485. void _M_assign_dispatch(_Integer __n, _Integer __val,
  486. const __true_type& /*_IsIntegral*/) {
  487. _M_fill_assign(__n, __val);
  488. }
  489. template <class _InputIterator>
  490. void _M_assign_dispatch(_InputIterator __first2, _InputIterator __last2,
  491. const __false_type& /*_IsIntegral*/) {
  492. #else
  493. void assign(const value_type *__first2, const value_type *__last2) {
  494. iterator __first1 = begin();
  495. iterator __last1 = end();
  496. for ( ; __first1 != __last1 && __first2 != __last2; ++__first1, ++__first2)
  497. *__first1 = *__first2;
  498. if (__first2 == __last2)
  499. erase(__first1, __last1);
  500. else
  501. insert(__last1, __first2, __last2);
  502. }
  503. void assign(const_iterator __first2, const_iterator __last2) {
  504. #endif /* _STLP_MEMBER_TEMPLATES */
  505. iterator __first1 = begin();
  506. iterator __last1 = end();
  507. for ( ; __first1 != __last1 && __first2 != __last2; ++__first1, ++__first2)
  508. *__first1 = *__first2;
  509. if (__first2 == __last2)
  510. erase(__first1, __last1);
  511. else
  512. insert(__last1, __first2, __last2);
  513. }
  514. public:
  515. void splice(iterator __pos, _Self& __x) {
  516. if (!__x.empty()) {
  517. if (this->get_allocator() == __x.get_allocator()) {
  518. _STLP_PRIV _List_global_inst::_Transfer(__pos._M_node, __x.begin()._M_node, __x.end()._M_node);
  519. }
  520. else {
  521. insert(__pos, __x.begin(), __x.end());
  522. __x.clear();
  523. }
  524. }
  525. }
  526. void splice(iterator __pos, _Self& __x, iterator __i) {
  527. iterator __j = __i;
  528. ++__j;
  529. if (__pos == __i || __pos == __j) return;
  530. if (this->get_allocator() == __x.get_allocator()) {
  531. _STLP_PRIV _List_global_inst::_Transfer(__pos._M_node, __i._M_node, __j._M_node);
  532. }
  533. else {
  534. insert(__pos, *__i);
  535. __x.erase(__i);
  536. }
  537. }
  538. void splice(iterator __pos, _Self& __x, iterator __first, iterator __last) {
  539. if (__first != __last) {
  540. if (this->get_allocator() == __x.get_allocator()) {
  541. _STLP_PRIV _List_global_inst::_Transfer(__pos._M_node, __first._M_node, __last._M_node);
  542. }
  543. else {
  544. insert(__pos, __first, __last);
  545. __x.erase(__first, __last);
  546. }
  547. }
  548. }
  549. void remove(const_reference __val) {
  550. iterator __first = begin();
  551. iterator __last = end();
  552. while (__first != __last) {
  553. iterator __next = __first;
  554. ++__next;
  555. if (__val == *__first) erase(__first);
  556. __first = __next;
  557. }
  558. }
  559. void unique()
  560. { _STLP_PRIV _S_unique(*this, equal_to<value_type>()); }
  561. void merge(_Self& __x)
  562. { _STLP_PRIV _S_merge(*this, __x, less<value_type>()); }
  563. void reverse() {
  564. _Node_base* __p = &this->_M_node._M_data;
  565. _Node_base* __tmp = __p;
  566. do {
  567. _STLP_STD::swap(__tmp->_M_next, __tmp->_M_prev);
  568. __tmp = __tmp->_M_prev; // Old next node is now prev.
  569. } while (__tmp != __p);
  570. }
  571. void sort()
  572. { _STLP_PRIV _S_sort(*this, less<value_type>()); }
  573. #if defined (_STLP_MEMBER_TEMPLATES)
  574. template <class _Predicate>
  575. void remove_if(_Predicate __pred)
  576. { _STLP_PRIV _S_remove_if(*this, __pred); }
  577. template <class _BinaryPredicate>
  578. void unique(_BinaryPredicate __binary_pred)
  579. { _STLP_PRIV _S_unique(*this, __binary_pred); }
  580. template <class _StrictWeakOrdering>
  581. void merge(_Self& __x,
  582. _StrictWeakOrdering __comp) {
  583. _STLP_PRIV _S_merge(*this, __x, __comp);
  584. }
  585. template <class _StrictWeakOrdering>
  586. void sort(_StrictWeakOrdering __comp)
  587. { _STLP_PRIV _S_sort(*this, __comp); }
  588. #endif /* _STLP_MEMBER_TEMPLATES */
  589. };
  590. #if defined (list)
  591. # undef list
  592. _STLP_MOVE_TO_STD_NAMESPACE
  593. #endif
  594. _STLP_END_NAMESPACE
  595. #if !defined (_STLP_LINK_TIME_INSTANTIATION)
  596. # include <stl/_list.c>
  597. #endif
  598. #if defined (_STLP_USE_PTR_SPECIALIZATIONS)
  599. # include <stl/pointers/_list.h>
  600. #endif
  601. #if defined (_STLP_DEBUG)
  602. # include <stl/debug/_list.h>
  603. #endif
  604. _STLP_BEGIN_NAMESPACE
  605. template <class _Tp, class _Alloc>
  606. _STLP_INLINE_LOOP bool _STLP_CALL
  607. operator==(const list<_Tp,_Alloc>& __x, const list<_Tp,_Alloc>& __y) {
  608. typedef typename list<_Tp,_Alloc>::const_iterator const_iterator;
  609. const_iterator __end1 = __x.end();
  610. const_iterator __end2 = __y.end();
  611. const_iterator __i1 = __x.begin();
  612. const_iterator __i2 = __y.begin();
  613. while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2) {
  614. ++__i1;
  615. ++__i2;
  616. }
  617. return __i1 == __end1 && __i2 == __end2;
  618. }
  619. #define _STLP_EQUAL_OPERATOR_SPECIALIZED
  620. #define _STLP_TEMPLATE_HEADER template <class _Tp, class _Alloc>
  621. #define _STLP_TEMPLATE_CONTAINER list<_Tp, _Alloc>
  622. #include <stl/_relops_cont.h>
  623. #undef _STLP_TEMPLATE_CONTAINER
  624. #undef _STLP_TEMPLATE_HEADER
  625. #undef _STLP_EQUAL_OPERATOR_SPECIALIZED
  626. #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) && !defined (_STLP_NO_MOVE_SEMANTIC)
  627. template <class _Tp, class _Alloc>
  628. struct __move_traits<list<_Tp, _Alloc> > {
  629. typedef __true_type implemented;
  630. typedef typename __move_traits<_Alloc>::complete complete;
  631. };
  632. #endif
  633. _STLP_END_NAMESPACE
  634. #endif /* _STLP_INTERNAL_LIST_IMPL_H */
  635. // Local Variables:
  636. // mode:C++
  637. // End: