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