_list.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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_PTR_SPECIALIZED_LIST_H
  19. #define _STLP_PTR_SPECIALIZED_LIST_H
  20. #ifndef _STLP_POINTERS_SPEC_TOOLS_H
  21. # include <stl/pointers/_tools.h>
  22. #endif
  23. _STLP_BEGIN_NAMESPACE
  24. #define LIST_IMPL _STLP_PTR_IMPL_NAME(list)
  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 _List_node<void*>;
  31. _STLP_MOVE_TO_STD_NAMESPACE
  32. _STLP_EXPORT_TEMPLATE_CLASS allocator<_STLP_PRIV _List_node<void*> >;
  33. _STLP_MOVE_TO_PRIV_NAMESPACE
  34. _STLP_EXPORT_TEMPLATE_CLASS _STLP_alloc_proxy<_List_node_base, _List_node<void*>, allocator<_List_node<void*> > >;
  35. _STLP_EXPORT_TEMPLATE_CLASS _List_base<void*, allocator<void*> >;
  36. _STLP_EXPORT_TEMPLATE_CLASS LIST_IMPL<void*, allocator<void*> >;
  37. _STLP_MOVE_TO_STD_NAMESPACE
  38. #endif
  39. #if defined (_STLP_DEBUG)
  40. # define list _STLP_NON_DBG_NAME(list)
  41. _STLP_MOVE_TO_PRIV_NAMESPACE
  42. #endif
  43. template <class _Tp, _STLP_DFL_TMPL_PARAM(_Alloc, allocator<_Tp>) >
  44. class list
  45. #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (list)
  46. : public __stlport_class<list<_Tp, _Alloc> >
  47. #endif
  48. {
  49. typedef _STLP_TYPENAME _STLP_PRIV _StorageType<_Tp>::_Type _StorageType;
  50. typedef typename _Alloc_traits<_StorageType, _Alloc>::allocator_type _StorageTypeAlloc;
  51. typedef _STLP_PRIV LIST_IMPL<_StorageType, _StorageTypeAlloc> _Base;
  52. typedef typename _Base::iterator _BaseIte;
  53. typedef typename _Base::const_iterator _BaseConstIte;
  54. typedef _STLP_PRIV _CastTraits<_StorageType, _Tp> cast_traits;
  55. typedef list<_Tp, _Alloc> _Self;
  56. public:
  57. typedef _Tp value_type;
  58. typedef value_type* pointer;
  59. typedef const value_type* const_pointer;
  60. typedef value_type& reference;
  61. typedef const value_type& const_reference;
  62. typedef size_t size_type;
  63. typedef ptrdiff_t difference_type;
  64. _STLP_FORCE_ALLOCATORS(value_type, _Alloc)
  65. typedef typename _Alloc_traits<value_type, _Alloc>::allocator_type allocator_type;
  66. typedef bidirectional_iterator_tag _Iterator_category;
  67. typedef _STLP_PRIV _List_iterator<value_type, _Nonconst_traits<value_type> > iterator;
  68. typedef _STLP_PRIV _List_iterator<value_type, _Const_traits<value_type> > const_iterator;
  69. _STLP_DECLARE_BIDIRECTIONAL_REVERSE_ITERATORS;
  70. allocator_type get_allocator() const
  71. { return _STLP_CONVERT_ALLOCATOR(_M_impl.get_allocator(), value_type); }
  72. explicit list(const allocator_type& __a = allocator_type())
  73. : _M_impl(_STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
  74. #if !defined(_STLP_DONT_SUP_DFLT_PARAM)
  75. explicit list(size_type __n, const value_type& __val = _STLP_DEFAULT_CONSTRUCTED(value_type),
  76. #else
  77. list(size_type __n, const value_type& __val,
  78. #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
  79. const allocator_type& __a = allocator_type())
  80. : _M_impl(__n, cast_traits::to_storage_type_cref(__val),
  81. _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
  82. #if defined(_STLP_DONT_SUP_DFLT_PARAM)
  83. explicit list(size_type __n)
  84. : _M_impl(__n) {}
  85. #endif /*_STLP_DONT_SUP_DFLT_PARAM*/
  86. #if defined (_STLP_MEMBER_TEMPLATES)
  87. template <class _InputIterator>
  88. list(_InputIterator __first, _InputIterator __last,
  89. const allocator_type& __a _STLP_ALLOCATOR_TYPE_DFL)
  90. # if !defined (_STLP_USE_ITERATOR_WRAPPER)
  91. : _M_impl(__first, __last, _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
  92. # else
  93. : _M_impl(_STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {
  94. insert(begin(), __first, __last);
  95. }
  96. # endif
  97. # if defined (_STLP_NEEDS_EXTRA_TEMPLATE_CONSTRUCTORS)
  98. template <class _InputIterator>
  99. list(_InputIterator __first, _InputIterator __last)
  100. # if !defined (_STLP_USE_WRAPPER_ITERATOR)
  101. : _M_impl(__first, __last) {}
  102. # else
  103. { insert(begin(), __first, __last); }
  104. # endif
  105. # endif
  106. #else /* _STLP_MEMBER_TEMPLATES */
  107. list(const value_type *__first, const value_type *__last,
  108. const allocator_type& __a = allocator_type())
  109. : _M_impl(cast_traits::to_storage_type_cptr(__first),
  110. cast_traits::to_storage_type_cptr(__last),
  111. _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
  112. list(const_iterator __first, const_iterator __last,
  113. const allocator_type& __a = allocator_type())
  114. : _M_impl(_BaseConstIte(__first._M_node), _BaseConstIte(__last._M_node),
  115. _STLP_CONVERT_ALLOCATOR(__a, _StorageType)) {}
  116. #endif /* _STLP_MEMBER_TEMPLATES */
  117. list(const _Self& __x) : _M_impl(__x._M_impl) {}
  118. #if !defined (_STLP_NO_MOVE_SEMANTIC)
  119. list(__move_source<_Self> src)
  120. : _M_impl(__move_source<_Base>(src.get()._M_impl)) {}
  121. #endif
  122. iterator begin() { return iterator(_M_impl.begin()._M_node); }
  123. const_iterator begin() const { return const_iterator(_M_impl.begin()._M_node); }
  124. iterator end() { return iterator(_M_impl.end()._M_node); }
  125. const_iterator end() const { return const_iterator(_M_impl.end()._M_node); }
  126. reverse_iterator rbegin() { return reverse_iterator(end()); }
  127. const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
  128. reverse_iterator rend() { return reverse_iterator(begin()); }
  129. const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
  130. bool empty() const { return _M_impl.empty(); }
  131. size_type size() const { return _M_impl.size(); }
  132. size_type max_size() const { return _M_impl.max_size(); }
  133. reference front() { return *begin(); }
  134. const_reference front() const { return *begin(); }
  135. reference back() { return *(--end()); }
  136. const_reference back() const { return *(--end()); }
  137. void swap(_Self &__x) { _M_impl.swap(__x._M_impl); }
  138. #if defined (_STLP_USE_PARTIAL_SPEC_WORKAROUND) && !defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
  139. void _M_swap_workaround(_Self& __x) { swap(__x); }
  140. #endif
  141. void clear() { _M_impl.clear(); }
  142. #if !defined(_STLP_DONT_SUP_DFLT_PARAM) && !defined(_STLP_NO_ANACHRONISMS)
  143. iterator insert(iterator __pos, const_reference __x = _STLP_DEFAULT_CONSTRUCTED(value_type))
  144. #else
  145. iterator insert(iterator __pos, const_reference __x)
  146. #endif /*!_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
  147. { return iterator(_M_impl.insert(_BaseIte(__pos._M_node),
  148. cast_traits::to_storage_type_cref(__x))._M_node); }
  149. #if defined (_STLP_MEMBER_TEMPLATES)
  150. # if defined (_STLP_USE_ITERATOR_WRAPPER)
  151. private:
  152. template <class _Integer>
  153. void _M_insert_dispatch(iterator __pos, _Integer __n, _Integer __val,
  154. const __true_type&)
  155. { _M_impl.insert(_BaseIte(__pos._M_node), __n, __val); }
  156. template <class _InputIterator>
  157. void _M_insert_dispatch(iterator __pos,
  158. _InputIterator __first, _InputIterator __last,
  159. const __false_type&) {
  160. _M_impl.insert(_BaseIte(__pos._M_node),
  161. _STLP_TYPENAME _STLP_PRIV _IteWrapper<_StorageType, _Tp, _InputIterator>::_Ite(__first),
  162. _STLP_TYPENAME _STLP_PRIV _IteWrapper<_StorageType, _Tp, _InputIterator>::_Ite(__last));
  163. }
  164. public:
  165. # endif
  166. template <class _InputIterator>
  167. void insert(iterator __pos, _InputIterator __first, _InputIterator __last) {
  168. # if defined (_STLP_USE_ITERATOR_WRAPPER)
  169. // Check whether it's an integral type. If so, it's not an iterator.
  170. typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
  171. _M_insert_dispatch(__pos, __first, __last, _Integral());
  172. # else
  173. _M_impl.insert(_BaseIte(__pos._M_node), __first, __last);
  174. # endif
  175. }
  176. #else /* _STLP_MEMBER_TEMPLATES */
  177. void insert(iterator __pos, const value_type *__first, const value_type *__last)
  178. { _M_impl.insert(_BaseIte(__pos._M_node), cast_traits::to_storage_type_cptr(__first),
  179. cast_traits::to_storage_type_cptr(__last)); }
  180. void insert(iterator __pos, const_iterator __first, const_iterator __last)
  181. { _M_impl.insert(_BaseIte(__pos._M_node), _BaseConstIte(__first._M_node), _BaseConstIte(__last._M_node)); }
  182. #endif /* _STLP_MEMBER_TEMPLATES */
  183. void insert(iterator __pos, size_type __n, const value_type& __x)
  184. { _M_impl.insert(_BaseIte(__pos._M_node), __n, cast_traits::to_storage_type_cref(__x)); }
  185. void push_front(const value_type& __x) { _M_impl.push_front(cast_traits::to_storage_type_cref(__x)); }
  186. void push_back(const value_type& __x) { _M_impl.push_back(cast_traits::to_storage_type_cref(__x)); }
  187. #if defined (_STLP_DONT_SUP_DFLT_PARAM) && !defined (_STLP_NO_ANACHRONISMS)
  188. iterator insert(iterator __pos) { return iterator(_M_impl.insert(__pos._M_node)._M_node); }
  189. void push_front() { _M_impl.push_front();}
  190. void push_back() { _M_impl.push_back();}
  191. # endif /*_STLP_DONT_SUP_DFLT_PARAM && !_STLP_NO_ANACHRONISMS*/
  192. iterator erase(iterator __pos)
  193. { return iterator(_M_impl.erase(_BaseIte(__pos._M_node))._M_node); }
  194. iterator erase(iterator __first, iterator __last)
  195. { return iterator(_M_impl.erase(_BaseIte(__first._M_node), _BaseIte(__last._M_node))._M_node); }
  196. #if !defined(_STLP_DONT_SUP_DFLT_PARAM)
  197. void resize(size_type __new_size, const value_type& __x = _STLP_DEFAULT_CONSTRUCTED(value_type))
  198. #else
  199. void resize(size_type __new_size) { _M_impl.resize(__new_size); }
  200. void resize(size_type __new_size, const value_type& __x)
  201. #endif /*!_STLP_DONT_SUP_DFLT_PARAM*/
  202. {_M_impl.resize(__new_size, cast_traits::to_storage_type_cref(__x));}
  203. void pop_front() { _M_impl.pop_front(); }
  204. void pop_back() { _M_impl.pop_back(); }
  205. _Self& operator=(const _Self& __x)
  206. { _M_impl = __x._M_impl; return *this; }
  207. void assign(size_type __n, const value_type& __val)
  208. { _M_impl.assign(__n, cast_traits::to_storage_type_cref(__val)); }
  209. #if defined (_STLP_MEMBER_TEMPLATES)
  210. # if defined (_STLP_USE_ITERATOR_WRAPPER)
  211. private:
  212. template <class _Integer>
  213. void _M_assign_dispatch(_Integer __n, _Integer __val, const __true_type&)
  214. { _M_impl.assign(__n, __val); }
  215. template <class _InputIterator>
  216. void _M_assign_dispatch(_InputIterator __first, _InputIterator __last,
  217. const __false_type&) {
  218. _M_impl.assign(_STLP_TYPENAME _STLP_PRIV _IteWrapper<_StorageType, _Tp, _InputIterator>::_Ite(__first),
  219. _STLP_TYPENAME _STLP_PRIV _IteWrapper<_StorageType, _Tp, _InputIterator>::_Ite(__last));
  220. }
  221. public:
  222. # endif
  223. template <class _InputIterator>
  224. void assign(_InputIterator __first, _InputIterator __last) {
  225. # if defined (_STLP_USE_ITERATOR_WRAPPER)
  226. typedef typename _IsIntegral<_InputIterator>::_Ret _Integral;
  227. _M_assign_dispatch(__first, __last, _Integral());
  228. # else
  229. _M_impl.assign(__first, __last);
  230. # endif
  231. }
  232. #else
  233. void assign(const value_type *__first, const value_type *__last) {
  234. _M_impl.assign(cast_traits::to_storage_type_cptr(__first),
  235. cast_traits::to_storage_type_cptr(__last));
  236. }
  237. void assign(const_iterator __first, const_iterator __last)
  238. { _M_impl.assign(_BaseConstIte(__first._M_node), _BaseConstIte(__last._M_node)); }
  239. #endif
  240. void splice(iterator __pos, _Self& __x)
  241. { _M_impl.splice(_BaseIte(__pos._M_node), __x._M_impl); }
  242. void splice(iterator __pos, _Self& __x, iterator __i)
  243. { _M_impl.splice(_BaseIte(__pos._M_node), __x._M_impl, _BaseIte(__i._M_node)); }
  244. void splice(iterator __pos, _Self& __x, iterator __first, iterator __last)
  245. { _M_impl.splice(_BaseIte(__pos._M_node), __x._M_impl,
  246. _BaseIte(__first._M_node), _BaseIte(__last._M_node)); }
  247. void remove(const_reference __val)
  248. { _M_impl.remove(cast_traits::to_storage_type_cref(__val)); }
  249. void unique() { _M_impl.unique(); }
  250. void merge(_Self& __x) { _M_impl.merge(__x._M_impl); }
  251. void reverse() { _M_impl.reverse(); }
  252. void sort() { _M_impl.sort(); }
  253. #if defined (_STLP_MEMBER_TEMPLATES)
  254. template <class _Predicate>
  255. void remove_if(_Predicate __pred)
  256. { _M_impl.remove_if(_STLP_PRIV _UnaryPredWrapper<_StorageType, _Tp, _Predicate>(__pred)); }
  257. template <class _BinaryPredicate>
  258. void unique(_BinaryPredicate __bin_pred)
  259. { _M_impl.unique(_STLP_PRIV _BinaryPredWrapper<_StorageType, _Tp, _BinaryPredicate>(__bin_pred)); }
  260. template <class _StrictWeakOrdering>
  261. void merge(_Self &__x, _StrictWeakOrdering __comp)
  262. { _M_impl.merge(__x._M_impl, _STLP_PRIV _BinaryPredWrapper<_StorageType, _Tp, _StrictWeakOrdering>(__comp)); }
  263. template <class _StrictWeakOrdering>
  264. void sort(_StrictWeakOrdering __comp)
  265. { _M_impl.sort(_STLP_PRIV _BinaryPredWrapper<_StorageType, _Tp, _StrictWeakOrdering>(__comp)); }
  266. #endif /* _STLP_MEMBER_TEMPLATES */
  267. private:
  268. _Base _M_impl;
  269. };
  270. #if defined (list)
  271. # undef list
  272. _STLP_MOVE_TO_STD_NAMESPACE
  273. #endif
  274. #undef LIST_IMPL
  275. #if defined (__BORLANDC__) || defined (__DMC__)
  276. # undef typename
  277. #endif
  278. _STLP_END_NAMESPACE
  279. #endif /* _STLP_PTR_SPECIALIZED_LIST_H */
  280. // Local Variables:
  281. // mode:C++
  282. // End: