_slist.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. /*
  2. * Copyright (c) 2003
  3. * Francois Dumont
  4. *
  5. * This material is provided "as is", with absolutely no warranty expressed
  6. * or implied. Any use is at your own risk.
  7. *
  8. * Permission to use or copy this software for any purpose is hereby granted
  9. * without fee, provided the above notices are retained on all copies.
  10. * Permission to modify the code and to distribute modified code is granted,
  11. * provided the above notices are retained, and a notice that the code was
  12. * modified is included with the above copyright notice.
  13. *
  14. */
  15. /* NOTE: This is an internal header file, included by other STL headers.
  16. * You should not attempt to use it directly.
  17. */
  18. #ifndef _STLP_SPECIALIZED_SLIST_H
  19. #define _STLP_SPECIALIZED_SLIST_H
  20. #ifndef _STLP_POINTERS_SPEC_TOOLS_H
  21. # include <stl/pointers/_tools.h>
  22. #endif
  23. _STLP_BEGIN_NAMESPACE
  24. #define SLIST_IMPL _STLP_PTR_IMPL_NAME(slist)
  25. #if defined (__BORLANDC__) || defined (__DMC__)
  26. # define typename
  27. #endif
  28. #if defined (_STLP_USE_TEMPLATE_EXPORT) && !defined (_STLP_USE_MSVC6_MEM_T_BUG_WORKAROUND)
  29. _STLP_MOVE_TO_PRIV_NAMESPACE
  30. _STLP_EXPORT_TEMPLATE_CLASS _Slist_node<void*>;
  31. typedef _Slist_node<void*> _VoidPtrSNode;
  32. _STLP_EXPORT_TEMPLATE_CLASS _STLP_alloc_proxy<_Slist_node_base, _VoidPtrSNode, allocator<_VoidPtrSNode> >;
  33. _STLP_EXPORT_TEMPLATE_CLASS _Slist_base<void*, allocator<void*> >;
  34. _STLP_EXPORT_TEMPLATE_CLASS SLIST_IMPL<void*, allocator<void*> >;
  35. _STLP_MOVE_TO_STD_NAMESPACE
  36. #endif
  37. #if defined (_STLP_DEBUG)
  38. # define slist _STLP_NON_DBG_NAME(slist)
  39. _STLP_MOVE_TO_PRIV_NAMESPACE
  40. #endif
  41. template <class _Tp, _STLP_DFL_TMPL_PARAM(_Alloc, allocator<_Tp>) >
  42. class slist
  43. #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (slist)
  44. : public __stlport_class<slist<_Tp, _Alloc> >
  45. #endif
  46. {
  47. typedef _STLP_TYPENAME _STLP_PRIV _StorageType<_Tp>::_Type _StorageType;
  48. typedef typename _Alloc_traits<_StorageType, _Alloc>::allocator_type _StorageTypeAlloc;
  49. typedef _STLP_PRIV SLIST_IMPL<_StorageType, _StorageTypeAlloc> _Base;
  50. typedef typename _Base::iterator _BaseIte;
  51. typedef typename _Base::const_iterator _BaseConstIte;
  52. typedef slist<_Tp, _Alloc> _Self;
  53. typedef _STLP_PRIV _CastTraits<_StorageType, _Tp> cast_traits;
  54. typedef _STLP_PRIV _Slist_node_base _Node_base;
  55. public:
  56. typedef _Tp value_type;
  57. typedef value_type* pointer;
  58. typedef const value_type* const_pointer;
  59. typedef value_type& reference;
  60. typedef const value_type& const_reference;
  61. typedef size_t size_type;
  62. typedef ptrdiff_t difference_type;
  63. typedef forward_iterator_tag _Iterator_category;
  64. typedef _STLP_PRIV _Slist_iterator<value_type, _Nonconst_traits<value_type> > iterator;
  65. typedef _STLP_PRIV _Slist_iterator<value_type, _Const_traits<value_type> > const_iterator;
  66. _STLP_FORCE_ALLOCATORS(value_type, _Alloc)
  67. typedef typename _Alloc_traits<value_type, _Alloc>::allocator_type allocator_type;
  68. public:
  69. allocator_type get_allocator() const
  70. { return _STLP_CONVERT_ALLOCATOR(_M_impl.get_allocator(), value_type); }
  71. explicit slist(const allocator_type& __a = allocator_type())
  72. : _M_impl(_STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
  73. #if !defined(_STLP_DONT_SUP_DFLT_PARAM)
  74. explicit slist(size_type __n, const value_type& __x = _STLP_DEFAULT_CONSTRUCTED(value_type),
  75. #else
  76. slist(size_type __n, const value_type& __x,
  77. #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
  78. const allocator_type& __a = allocator_type())
  79. : _M_impl(__n, cast_traits::to_storage_type_cref(__x), _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
  80. #if defined(_STLP_DONT_SUP_DFLT_PARAM)
  81. explicit slist(size_type __n) : _M_impl(__n) {}
  82. #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
  83. #if defined (_STLP_MEMBER_TEMPLATES)
  84. // We don't need any dispatching tricks here, because _M_insert_after_range
  85. // already does them.
  86. template <class _InputIterator>
  87. slist(_InputIterator __first, _InputIterator __last,
  88. const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
  89. # if !defined (_STLP_USE_ITERATOR_WRAPPER)
  90. : _M_impl(__first, __last, _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
  91. # else
  92. : _M_impl(_STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {
  93. insert_after(before_begin(), __first, __last);
  94. }
  95. # endif
  96. # if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
  97. // VC++ needs this crazyness
  98. template <class _InputIterator>
  99. slist(_InputIterator __first, _InputIterator __last)
  100. # if !defined (_STLP_USE_WRAPPER_ITERATOR)
  101. : _M_impl(__first, __last) {}
  102. # else
  103. { insert_after(before_begin(), __first, __last); }
  104. # endif
  105. # endif
  106. #else /* _STLP_MEMBER_TEMPLATES */
  107. slist(const_iterator __first, const_iterator __last,
  108. const allocator_type& __a = allocator_type() )
  109. : _M_impl(_BaseConstIte(__first._M_node), _BaseConstIte(__last._M_node),
  110. _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
  111. slist(const value_type* __first, const value_type* __last,
  112. const allocator_type& __a = allocator_type())
  113. : _M_impl(cast_traits::to_storage_type_cptr(__first), cast_traits::to_storage_type_cptr(__last),
  114. _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
  115. #endif /* _STLP_MEMBER_TEMPLATES */
  116. slist(const _Self& __x) : _M_impl(__x._M_impl) {}
  117. #if !defined (_STLP_NO_MOVE_SEMANTIC)
  118. slist(__move_source<_Self> src)
  119. : _M_impl(__move_source<_Base>(src.get()._M_impl)) {}
  120. #endif
  121. _Self& operator= (const _Self& __x) { _M_impl = __x._M_impl; return *this; }
  122. void assign(size_type __n, const value_type& __val)
  123. { _M_impl.assign(__n, cast_traits::to_storage_type_cref(__val)); }
  124. #if defined (_STLP_MEMBER_TEMPLATES)
  125. # if defined (_STLP_USE_ITERATOR_WRAPPER)
  126. private:
  127. template <class _Integer>
  128. void _M_assign_dispatch(_Integer __n, _Integer __val,
  129. const __true_type&)
  130. { _M_impl.assign(__n, __val); }
  131. template <class _InputIterator>
  132. void _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
  133. const __false_type&) {
  134. _M_impl.assign(_STLP_TYPENAME _STLP_PRIV _IteWrapper<_StorageType, _Tp, _InputIterator>::_Ite(__first),
  135. _STLP_TYPENAME _STLP_PRIV _IteWrapper<_StorageType, _Tp, _InputIterator>::_Ite(__last));
  136. }
  137. public:
  138. # endif
  139. template <class _InputIterator>
  140. void assign(_InputIterator __first, _InputIterator __last) {
  141. # if defined (_STLP_USE_ITERATOR_WRAPPER)
  142. typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
  143. _M_assign_dispatch(__first, __last, _Integral());
  144. # else
  145. _M_impl.assign(__first, __last);
  146. # endif
  147. }
  148. #else
  149. void assign(const value_type *__first, const value_type *__last) {
  150. _M_impl.assign(cast_traits::to_storage_type_cptr(__first),
  151. cast_traits::to_storage_type_cptr(__last));
  152. }
  153. void assign(const_iterator __first, const_iterator __last) {
  154. _M_impl.assign(_BaseConstIte(__first._M_node),
  155. _BaseConstIte(__last._M_node));
  156. }
  157. #endif /* _STLP_MEMBER_TEMPLATES */
  158. iterator before_begin() { return iterator(_M_impl.before_begin()._M_node); }
  159. const_iterator before_begin() const { return const_iterator(const_cast<_Node_base*>(_M_impl.before_begin()._M_node)); }
  160. iterator begin() { return iterator(_M_impl.begin()._M_node); }
  161. const_iterator begin() const { return const_iterator(const_cast<_Node_base*>(_M_impl.begin()._M_node));}
  162. iterator end() { return iterator(_M_impl.end()._M_node); }
  163. const_iterator end() const { return iterator(_M_impl.end()._M_node); }
  164. size_type size() const { return _M_impl.size(); }
  165. size_type max_size() const { return _M_impl.max_size(); }
  166. bool empty() const { return _M_impl.empty(); }
  167. void swap(_Self& __x) { _M_impl.swap(__x._M_impl); }
  168. #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
  169. void _M_swap_workaround(_Self& __x) { swap(__x); }
  170. #endif
  171. public:
  172. reference front() { return *begin(); }
  173. const_reference front() const { return *begin(); }
  174. #if !defined(_STLP_DONT_SUP_DFLT_PARAM) && !defined(_STLP_NO_ANACHRONISMS)
  175. void push_front(const value_type& __x = _STLP_DEFAULT_CONSTRUCTED(value_type))
  176. #else
  177. void push_front(const value_type& __x)
  178. #endif /*!_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
  179. { _M_impl.push_front(cast_traits::to_storage_type_cref(__x)); }
  180. # if defined(_STLP_DONT_SUP_DFLT_PARAM) && !defined(_STLP_NO_ANACHRONISMS)
  181. void push_front() { _M_impl.push_front();}
  182. # endif /*_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
  183. void pop_front() { _M_impl.pop_front(); }
  184. iterator previous(const_iterator __pos)
  185. { return iterator(_M_impl.previous(_BaseConstIte(__pos._M_node))._M_node); }
  186. const_iterator previous(const_iterator __pos) const
  187. { return const_iterator(const_cast<_Node_base*>(_M_impl.previous(_BaseConstIte(__pos._M_node))._M_node)); }
  188. #if !defined(_STLP_DONT_SUP_DFLT_PARAM)
  189. iterator insert_after(iterator __pos, const value_type& __x = _STLP_DEFAULT_CONSTRUCTED(value_type))
  190. #else
  191. iterator insert_after(iterator __pos, const value_type& __x)
  192. #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
  193. { return iterator(_M_impl.insert_after(_BaseIte(__pos._M_node),
  194. cast_traits::to_storage_type_cref(__x))._M_node); }
  195. #if defined(_STLP_DONT_SUP_DFLT_PARAM)
  196. iterator insert_after(iterator __pos)
  197. { return iterator(_M_impl.insert_after(_BaseIte(__pos._M_node))._M_node);}
  198. #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
  199. void insert_after(iterator __pos, size_type __n, const value_type& __x)
  200. { _M_impl.insert_after(_BaseIte(__pos._M_node), __n, cast_traits::to_storage_type_cref(__x)); }
  201. #if defined (_STLP_MEMBER_TEMPLATES)
  202. # if defined (_STLP_USE_ITERATOR_WRAPPER)
  203. private:
  204. template <class _Integer>
  205. void _M_insert_after_dispatch(iterator __pos, _Integer __n, _Integer __val,
  206. const __true_type&) {
  207. _M_impl.insert_after(_BaseIte(__pos._M_node), __n, __val);
  208. }
  209. template <class _InputIterator>
  210. void _M_insert_after_dispatch(iterator __pos,
  211. _InputIterator __first, _InputIterator __last,
  212. const __false_type&) {
  213. _M_impl.insert_after(_BaseIte(__pos._M_node),
  214. _STLP_TYPENAME _STLP_PRIV _IteWrapper<_StorageType, _Tp, _InputIterator>::_Ite(__first),
  215. _STLP_TYPENAME _STLP_PRIV _IteWrapper<_StorageType, _Tp, _InputIterator>::_Ite(__last));
  216. }
  217. public:
  218. # endif
  219. template <class _InputIterator>
  220. void insert_after(iterator __pos, _InputIterator __first, _InputIterator __last) {
  221. # if defined (_STLP_USE_ITERATOR_WRAPPER)
  222. // Check whether it's an integral type. If so, it's not an iterator.
  223. typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
  224. _M_insert_after_dispatch(__pos, __first, __last, _Integral());
  225. # else
  226. _M_impl.insert_after(_BaseIte(__pos._M_node), __first, __last);
  227. # endif
  228. }
  229. #else /* _STLP_MEMBER_TEMPLATES */
  230. void insert_after(iterator __pos,
  231. const_iterator __first, const_iterator __last)
  232. { _M_impl.insert_after(_BaseIte(__pos._M_node),
  233. _BaseConstIte(__first._M_node), _BaseConstIte(__last._M_node)); }
  234. void insert_after(iterator __pos,
  235. const value_type* __first, const value_type* __last) {
  236. _M_impl.insert_after(_BaseIte(__pos._M_node),
  237. cast_traits::to_storage_type_cptr(__first),
  238. cast_traits::to_storage_type_cptr(__last));
  239. }
  240. #endif /* _STLP_MEMBER_TEMPLATES */
  241. #if !defined(_STLP_DONT_SUP_DFLT_PARAM)
  242. iterator insert(iterator __pos, const value_type& __x = _STLP_DEFAULT_CONSTRUCTED(value_type))
  243. #else
  244. iterator insert(iterator __pos, const value_type& __x)
  245. #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
  246. { return iterator(_M_impl.insert(_BaseIte(__pos._M_node),
  247. cast_traits::to_storage_type_cref(__x))._M_node); }
  248. #if defined(_STLP_DONT_SUP_DFLT_PARAM)
  249. iterator insert(iterator __pos)
  250. { return iterator(_M_impl.insert(_BaseIte(__pos._M_node))._M_node); }
  251. #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
  252. void insert(iterator __pos, size_type __n, const value_type& __x)
  253. { _M_impl.insert(_BaseIte(__pos._M_node), __n, cast_traits::to_storage_type_cref(__x)); }
  254. #if defined (_STLP_MEMBER_TEMPLATES)
  255. # if defined (_STLP_USE_ITERATOR_WRAPPER)
  256. private:
  257. template <class _Integer>
  258. void _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __val,
  259. const __true_type&) {
  260. _M_impl.insert(_BaseIte(__pos._M_node), __n, __val);
  261. }
  262. template <class _InputIterator>
  263. void _M_insert_dispatch(iterator __pos,
  264. _InputIterator __first, _InputIterator __last,
  265. const __false_type&) {
  266. _M_impl.insert(_BaseIte(__pos._M_node), _STLP_TYPENAME _STLP_PRIV _IteWrapper<_StorageType, _Tp, _InputIterator>::_Ite(__first),
  267. _STLP_TYPENAME _STLP_PRIV _IteWrapper<_StorageType, _Tp, _InputIterator>::_Ite(__last));
  268. }
  269. public:
  270. # endif
  271. template <class _InputIterator>
  272. void insert(iterator __pos, _InputIterator __first, _InputIterator __last) {
  273. # if defined (_STLP_USE_ITERATOR_WRAPPER)
  274. // Check whether it's an integral type. If so, it's not an iterator.
  275. typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
  276. _M_insert_dispatch(__pos, __first, __last, _Integral());
  277. # else
  278. _M_impl.insert(_BaseIte(__pos._M_node), __first, __last);
  279. # endif
  280. }
  281. #else /* _STLP_MEMBER_TEMPLATES */
  282. void insert(iterator __pos, const_iterator __first, const_iterator __last)
  283. { _M_impl.insert(_BaseIte(__pos._M_node), _BaseConstIte(__first._M_node), _BaseConstIte(__last._M_node)); }
  284. void insert(iterator __pos, const value_type* __first, const value_type* __last)
  285. { _M_impl.insert(_BaseIte(__pos._M_node), cast_traits::to_storage_type_cptr(__first),
  286. cast_traits::to_storage_type_cptr(__last)); }
  287. #endif /* _STLP_MEMBER_TEMPLATES */
  288. iterator erase_after(iterator __pos)
  289. { return iterator(_M_impl.erase_after(_BaseIte(__pos._M_node))._M_node); }
  290. iterator erase_after(iterator __before_first, iterator __last)
  291. { return iterator(_M_impl.erase_after(_BaseIte(__before_first._M_node),
  292. _BaseIte(__last._M_node))._M_node); }
  293. iterator erase(iterator __pos)
  294. { return iterator(_M_impl.erase(_BaseIte(__pos._M_node))._M_node); }
  295. iterator erase(iterator __first, iterator __last)
  296. { return iterator(_M_impl.erase(_BaseIte(__first._M_node), _BaseIte(__last._M_node))._M_node); }
  297. #if !defined(_STLP_DONT_SUP_DFLT_PARAM)
  298. void resize(size_type __new_size, const value_type& __x = _STLP_DEFAULT_CONSTRUCTED(value_type))
  299. #else
  300. void resize(size_type __new_size, const value_type& __x)
  301. #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
  302. { _M_impl.resize(__new_size, cast_traits::to_storage_type_cref(__x));}
  303. #if defined(_STLP_DONT_SUP_DFLT_PARAM)
  304. void resize(size_type __new_size) { _M_impl.resize(__new_size); }
  305. #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
  306. void clear() { _M_impl.clear(); }
  307. void splice_after(iterator __pos, _Self& __x,
  308. iterator __before_first, iterator __before_last)
  309. { _M_impl.splice_after(_BaseIte(__pos._M_node), __x._M_impl,
  310. _BaseIte(__before_first._M_node), _BaseIte(__before_last._M_node)); }
  311. void splice_after(iterator __pos, _Self& __x, iterator __prev)
  312. { _M_impl.splice_after(_BaseIte(__pos._M_node), __x._M_impl, _BaseIte(__prev._M_node)); }
  313. void splice_after(iterator __pos, _Self& __x)
  314. { _M_impl.splice_after(_BaseIte(__pos._M_node), __x._M_impl); }
  315. void splice(iterator __pos, _Self& __x)
  316. { _M_impl.splice(_BaseIte(__pos._M_node), __x._M_impl); }
  317. void splice(iterator __pos, _Self& __x, iterator __i)
  318. { _M_impl.splice(_BaseIte(__pos._M_node), __x._M_impl, _BaseIte(__i._M_node)); }
  319. void splice(iterator __pos, _Self& __x, iterator __first, iterator __last)
  320. { _M_impl.splice(_BaseIte(__pos._M_node), __x._M_impl,
  321. _BaseIte(__first._M_node), _BaseIte(__last._M_node)); }
  322. void reverse() { _M_impl.reverse(); }
  323. void remove(const value_type& __val) { _M_impl.remove(cast_traits::to_storage_type_cref(__val)); }
  324. void unique() { _M_impl.unique(); }
  325. void merge(_Self& __x) { _M_impl.merge(__x._M_impl); }
  326. void sort() {_M_impl.sort(); }
  327. #ifdef _STLP_MEMBER_TEMPLATES
  328. template <class _Predicate>
  329. void remove_if(_Predicate __pred)
  330. { _M_impl.remove_if(_STLP_PRIV _UnaryPredWrapper<_StorageType, _Tp, _Predicate>(__pred)); }
  331. template <class _BinaryPredicate>
  332. void unique(_BinaryPredicate __pred)
  333. { _M_impl.unique(_STLP_PRIV _BinaryPredWrapper<_StorageType, _Tp, _BinaryPredicate>(__pred)); }
  334. template <class _StrictWeakOrdering>
  335. void merge(_Self& __x, _StrictWeakOrdering __comp)
  336. { _M_impl.merge(__x._M_impl, _STLP_PRIV _BinaryPredWrapper<_StorageType, _Tp, _StrictWeakOrdering>(__comp)); }
  337. template <class _StrictWeakOrdering>
  338. void sort(_StrictWeakOrdering __comp)
  339. { _M_impl.sort(_STLP_PRIV _BinaryPredWrapper<_StorageType, _Tp, _StrictWeakOrdering>(__comp)); }
  340. #endif /* _STLP_MEMBER_TEMPLATES */
  341. private:
  342. _Base _M_impl;
  343. };
  344. #if defined (slist)
  345. # undef slist
  346. _STLP_MOVE_TO_STD_NAMESPACE
  347. #endif
  348. #undef SLIST_IMPL
  349. #if defined (__BORLANDC__) || defined (__DMC__)
  350. # undef typename
  351. #endif
  352. _STLP_END_NAMESPACE
  353. #endif /* _STLP_SPECIALIZED_SLIST_H */
  354. // Local Variables:
  355. // mode:C++
  356. // End: