_iterator_old.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. /*
  2. *
  3. * Copyright (c) 1994
  4. * Hewlett-Packard Company
  5. *
  6. * Copyright (c) 1996-1998
  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_ITERATOR_OLD_H
  29. #define _STLP_INTERNAL_ITERATOR_OLD_H
  30. #ifndef _STLP_INTERNAL_ITERATOR_BASE_H
  31. # include <stl/_iterator_base.h>
  32. #endif
  33. _STLP_BEGIN_NAMESPACE
  34. #ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
  35. template <class _Container>
  36. inline output_iterator_tag _STLP_CALL
  37. iterator_category(const back_insert_iterator<_Container>&) { return output_iterator_tag(); }
  38. template <class _Container>
  39. inline output_iterator_tag _STLP_CALL
  40. iterator_category(const front_insert_iterator<_Container>&) { return output_iterator_tag(); }
  41. template <class _Container>
  42. inline output_iterator_tag _STLP_CALL
  43. iterator_category(const insert_iterator<_Container>&) { return output_iterator_tag(); }
  44. #endif
  45. template <class _BidirectionalIterator, class _Tp,
  46. _STLP_DFL_TMPL_PARAM(_Reference, _Tp& ),
  47. #if defined (_STLP_MSVC50_COMPATIBILITY)
  48. # define __Reference _Reference, class _Pointer
  49. # define Reference__ _Reference, _Pointer
  50. _STLP_DFL_TMPL_PARAM(_Pointer, _Tp*),
  51. #else
  52. # define __Reference _Reference
  53. # define Reference__ _Reference
  54. #endif
  55. _STLP_DFL_TYPE_PARAM(_Distance, ptrdiff_t)>
  56. class reverse_bidirectional_iterator {
  57. typedef reverse_bidirectional_iterator<_BidirectionalIterator, _Tp,
  58. Reference__, _Distance> _Self;
  59. // friend inline bool operator== _STLP_NULL_TMPL_ARGS (const _Self& x, const _Self& y);
  60. protected:
  61. _BidirectionalIterator current;
  62. public:
  63. typedef bidirectional_iterator_tag iterator_category;
  64. typedef _Tp value_type;
  65. typedef _Distance difference_type;
  66. # if defined (_STLP_MSVC50_COMPATIBILITY)
  67. typedef _Pointer pointer;
  68. # else
  69. typedef _Tp* pointer;
  70. # endif
  71. typedef _Reference reference;
  72. reverse_bidirectional_iterator() {}
  73. explicit reverse_bidirectional_iterator(_BidirectionalIterator __x)
  74. : current(__x) {}
  75. _BidirectionalIterator base() const { return current; }
  76. _Reference operator*() const {
  77. _BidirectionalIterator __tmp = current;
  78. return *(--__tmp);
  79. }
  80. _STLP_DEFINE_ARROW_OPERATOR
  81. _Self& operator++() {
  82. --current;
  83. return *this;
  84. }
  85. _Self operator++(int) {
  86. _Self __tmp = *this;
  87. --current;
  88. return __tmp;
  89. }
  90. _Self& operator--() {
  91. ++current;
  92. return *this;
  93. }
  94. _Self operator--(int) {
  95. _Self __tmp = *this;
  96. ++current;
  97. return __tmp;
  98. }
  99. };
  100. #ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
  101. template <class _BidirectionalIterator, class _Tp, class __Reference,
  102. class _Distance>
  103. inline bidirectional_iterator_tag _STLP_CALL
  104. iterator_category(const reverse_bidirectional_iterator<_BidirectionalIterator, _Tp, Reference__, _Distance>&)
  105. { return bidirectional_iterator_tag(); }
  106. template <class _BidirectionalIterator, class _Tp, class __Reference,
  107. class _Distance>
  108. inline _Tp* _STLP_CALL
  109. value_type(const reverse_bidirectional_iterator<_BidirectionalIterator, _Tp, Reference__, _Distance>&)
  110. { return (_Tp*) 0; }
  111. template <class _BidirectionalIterator, class _Tp, class __Reference,
  112. class _Distance>
  113. inline _Distance* _STLP_CALL
  114. distance_type(const reverse_bidirectional_iterator<_BidirectionalIterator, _Tp, Reference__, _Distance>&)
  115. { return (_Distance*) 0; }
  116. #endif
  117. template <class _BidirectionalIterator, class _Tp, class __Reference,
  118. class _Distance>
  119. inline bool _STLP_CALL operator==(
  120. const reverse_bidirectional_iterator<_BidirectionalIterator, _Tp,
  121. Reference__, _Distance>& __x,
  122. const reverse_bidirectional_iterator<_BidirectionalIterator, _Tp,
  123. Reference__, _Distance>& __y)
  124. { return __x.base() == __y.base(); }
  125. #ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
  126. template <class _BiIter, class _Tp, class __Reference, class _Distance>
  127. inline bool _STLP_CALL operator!=(
  128. const reverse_bidirectional_iterator<_BiIter, _Tp, Reference__, _Distance>& __x,
  129. const reverse_bidirectional_iterator<_BiIter, _Tp, Reference__, _Distance>& __y)
  130. { return !(__x == __y); }
  131. #endif
  132. #if !defined ( _STLP_CLASS_PARTIAL_SPECIALIZATION )
  133. // This is the old version of reverse_iterator, as found in the original
  134. // HP STL. It does not use partial specialization.
  135. template <class _RandomAccessIterator, class _Tp,
  136. _STLP_DFL_TMPL_PARAM(_Reference,_Tp&),
  137. # if defined (_STLP_MSVC50_COMPATIBILITY)
  138. _STLP_DFL_TMPL_PARAM(_Pointer, _Tp*),
  139. # endif
  140. _STLP_DFL_TYPE_PARAM(_Distance,ptrdiff_t)>
  141. class reverse_iterator {
  142. typedef reverse_iterator<_RandomAccessIterator, _Tp, Reference__, _Distance> _Self;
  143. protected:
  144. _RandomAccessIterator __current;
  145. public:
  146. typedef random_access_iterator_tag iterator_category;
  147. typedef _Tp value_type;
  148. typedef _Distance difference_type;
  149. # if defined (_STLP_MSVC50_COMPATIBILITY)
  150. typedef _Pointer pointer;
  151. # else
  152. typedef _Tp* pointer;
  153. # endif
  154. typedef _Reference reference;
  155. reverse_iterator() {}
  156. reverse_iterator(const _Self& __x) : __current(__x.base()) {}
  157. explicit reverse_iterator(_RandomAccessIterator __x) : __current(__x) {}
  158. _Self& operator=(const _Self& __x) {__current = __x.base(); return *this; }
  159. _RandomAccessIterator base() const { return __current; }
  160. _Reference operator*() const { return *(__current - (difference_type)1); }
  161. _STLP_DEFINE_ARROW_OPERATOR
  162. _Self& operator++() {
  163. --__current;
  164. return *this;
  165. }
  166. _Self operator++(int) {
  167. _Self __tmp = *this;
  168. --__current;
  169. return __tmp;
  170. }
  171. _Self& operator--() {
  172. ++__current;
  173. return *this;
  174. }
  175. _Self operator--(int) {
  176. _Self __tmp = *this;
  177. ++__current;
  178. return __tmp;
  179. }
  180. _Self operator+(_Distance __n) const {
  181. return _Self(__current - __n);
  182. }
  183. _Self& operator+=(_Distance __n) {
  184. __current -= __n;
  185. return *this;
  186. }
  187. _Self operator-(_Distance __n) const {
  188. return _Self(__current + __n);
  189. }
  190. _Self& operator-=(_Distance __n) {
  191. __current += __n;
  192. return *this;
  193. }
  194. _Reference operator[](_Distance __n) const { return *(*this + __n); }
  195. };
  196. # ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
  197. template <class _RandomAccessIterator, class _Tp,
  198. class __Reference, class _Distance>
  199. inline random_access_iterator_tag _STLP_CALL
  200. iterator_category(const reverse_iterator<_RandomAccessIterator, _Tp, Reference__, _Distance>&)
  201. { return random_access_iterator_tag(); }
  202. template <class _RandomAccessIterator, class _Tp,
  203. class __Reference, class _Distance>
  204. inline _Tp* _STLP_CALL value_type(const reverse_iterator<_RandomAccessIterator, _Tp, Reference__, _Distance>&)
  205. { return (_Tp*) 0; }
  206. template <class _RandomAccessIterator, class _Tp,
  207. class __Reference, class _Distance>
  208. inline _Distance* _STLP_CALL
  209. distance_type(const reverse_iterator<_RandomAccessIterator, _Tp, Reference__, _Distance>&)
  210. { return (_Distance*) 0; }
  211. # endif
  212. template <class _RandomAccessIterator, class _Tp,
  213. class __Reference, class _Distance>
  214. inline bool _STLP_CALL
  215. operator==(const reverse_iterator<_RandomAccessIterator, _Tp,
  216. Reference__, _Distance>& __x,
  217. const reverse_iterator<_RandomAccessIterator, _Tp,
  218. Reference__, _Distance>& __y)
  219. {
  220. return __x.base() == __y.base();
  221. }
  222. template <class _RandomAccessIterator, class _Tp,
  223. class __Reference, class _Distance>
  224. inline bool _STLP_CALL
  225. operator<(const reverse_iterator<_RandomAccessIterator, _Tp,
  226. Reference__, _Distance>& __x,
  227. const reverse_iterator<_RandomAccessIterator, _Tp,
  228. Reference__, _Distance>& __y)
  229. {
  230. return __y.base() < __x.base();
  231. }
  232. # ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
  233. template <class _RandomAccessIterator, class _Tp,
  234. class __Reference, class _Distance>
  235. inline bool _STLP_CALL
  236. operator!=(const reverse_iterator<_RandomAccessIterator, _Tp,
  237. Reference__, _Distance>& __x,
  238. const reverse_iterator<_RandomAccessIterator, _Tp,
  239. Reference__, _Distance>& __y) {
  240. return !(__x == __y);
  241. }
  242. template <class _RandomAccessIterator, class _Tp,
  243. class __Reference, class _Distance>
  244. inline bool _STLP_CALL
  245. operator>(const reverse_iterator<_RandomAccessIterator, _Tp,
  246. Reference__, _Distance>& __x,
  247. const reverse_iterator<_RandomAccessIterator, _Tp,
  248. Reference__, _Distance>& __y) {
  249. return __y < __x;
  250. }
  251. template <class _RandomAccessIterator, class _Tp,
  252. class __Reference, class _Distance>
  253. inline bool _STLP_CALL
  254. operator<=(const reverse_iterator<_RandomAccessIterator, _Tp,
  255. Reference__, _Distance>& __x,
  256. const reverse_iterator<_RandomAccessIterator, _Tp,
  257. Reference__, _Distance>& __y) {
  258. return !(__y < __x);
  259. }
  260. template <class _RandomAccessIterator, class _Tp,
  261. class __Reference, class _Distance>
  262. inline bool _STLP_CALL
  263. operator>=(const reverse_iterator<_RandomAccessIterator, _Tp,
  264. Reference__, _Distance>& __x,
  265. const reverse_iterator<_RandomAccessIterator, _Tp,
  266. Reference__, _Distance>& __y) {
  267. return !(__x < __y);
  268. }
  269. # endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
  270. template <class _RandomAccessIterator, class _Tp,
  271. class __Reference, class _Distance>
  272. inline _Distance _STLP_CALL
  273. operator-(const reverse_iterator<_RandomAccessIterator, _Tp,
  274. Reference__, _Distance>& __x,
  275. const reverse_iterator<_RandomAccessIterator, _Tp,
  276. Reference__, _Distance>& __y)
  277. {
  278. return __y.base() - __x.base();
  279. }
  280. template <class _RandomAccessIterator, class _Tp,
  281. class __Reference, class _Distance>
  282. inline reverse_iterator<_RandomAccessIterator, _Tp,
  283. Reference__, _Distance> _STLP_CALL
  284. operator+(_Distance __n,
  285. const reverse_iterator<_RandomAccessIterator, _Tp,
  286. Reference__, _Distance>& __x)
  287. {
  288. return reverse_iterator<_RandomAccessIterator, _Tp,
  289. Reference__, _Distance>(__x.base() - __n);
  290. }
  291. #endif /* ! defined ( _STLP_CLASS_PARTIAL_SPECIALIZATION ) */
  292. _STLP_END_NAMESPACE
  293. #endif /* _STLP_INTERNAL_ITERATOR_H */
  294. // Local Variables:
  295. // mode:C++
  296. // End: