4 * Hewlett-Packard Company
6 * Copyright (c) 1996-1998
7 * Silicon Graphics Computer Systems, Inc.
10 * Moscow Center for SPARC Technology
15 * This material is provided "as is", with absolutely no warranty expressed
16 * or implied. Any use is at your own risk.
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.
26 /* NOTE: This is an internal header file, included by other STL headers.
27 * You should not attempt to use it directly.
30 #ifndef _STLP_INTERNAL_ITERATOR_OLD_H
31 #define _STLP_INTERNAL_ITERATOR_OLD_H
33 #ifndef _STLP_INTERNAL_ITERATOR_BASE_H
34 # include <stl/_iterator_base.h>
39 #ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
41 template <class _Container
>
42 inline output_iterator_tag _STLP_CALL
43 iterator_category(const back_insert_iterator
<_Container
>&) { return output_iterator_tag(); }
44 template <class _Container
>
45 inline output_iterator_tag _STLP_CALL
46 iterator_category(const front_insert_iterator
<_Container
>&) { return output_iterator_tag(); }
47 template <class _Container
>
48 inline output_iterator_tag _STLP_CALL
49 iterator_category(const insert_iterator
<_Container
>&) { return output_iterator_tag(); }
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
*),
60 # define __Reference _Reference
61 # define Reference__ _Reference
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);
69 _BidirectionalIterator current
;
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
;
79 typedef _Reference reference
;
81 reverse_bidirectional_iterator() {}
82 explicit reverse_bidirectional_iterator(_BidirectionalIterator __x
)
84 _BidirectionalIterator
base() const { return current
; }
85 _Reference
operator*() const {
86 _BidirectionalIterator __tmp
= current
;
90 _STLP_DEFINE_ARROW_OPERATOR
96 _Self
operator++(int) {
101 _Self
& operator--() {
105 _Self
operator--(int) {
112 #ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
113 template <class _BidirectionalIterator
, class _Tp
, class __Reference
,
115 inline bidirectional_iterator_tag _STLP_CALL
116 iterator_category(const reverse_bidirectional_iterator
<_BidirectionalIterator
, _Tp
, Reference__
, _Distance
>&)
117 { return bidirectional_iterator_tag(); }
118 template <class _BidirectionalIterator
, class _Tp
, class __Reference
,
120 inline _Tp
* _STLP_CALL
121 value_type(const reverse_bidirectional_iterator
<_BidirectionalIterator
, _Tp
, Reference__
, _Distance
>&)
123 template <class _BidirectionalIterator
, class _Tp
, class __Reference
,
125 inline _Distance
* _STLP_CALL
126 distance_type(const reverse_bidirectional_iterator
<_BidirectionalIterator
, _Tp
, Reference__
, _Distance
>&)
127 { return (_Distance
*) 0; }
130 template <class _BidirectionalIterator
, class _Tp
, class __Reference
,
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(); }
139 #ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
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
); }
149 #if !defined ( _STLP_CLASS_PARTIAL_SPECIALIZATION )
151 // This is the old version of reverse_iterator, as found in the original
152 // HP STL. It does not use partial specialization.
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
*),
159 _STLP_DFL_TYPE_PARAM(_Distance
,ptrdiff_t)>
160 class reverse_iterator
{
161 typedef reverse_iterator
<_RandomAccessIterator
, _Tp
, Reference__
, _Distance
> _Self
;
163 _RandomAccessIterator __current
;
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
;
171 typedef _Tp
* pointer
;
173 typedef _Reference reference
;
175 reverse_iterator() {}
176 reverse_iterator(const _Self
& __x
) : __current(__x
.base()) {}
177 explicit reverse_iterator(_RandomAccessIterator __x
) : __current(__x
) {}
178 _Self
& operator=(const _Self
& __x
) {__current
= __x
.base(); return *this; }
180 _RandomAccessIterator
base() const { return __current
; }
181 _Reference
operator*() const { return *(__current
- (difference_type
)1); }
183 _STLP_DEFINE_ARROW_OPERATOR
185 _Self
& operator++() {
189 _Self
operator++(int) {
194 _Self
& operator--() {
198 _Self
operator--(int) {
203 _Self
operator+(_Distance __n
) const {
204 return _Self(__current
- __n
);
206 _Self
& operator+=(_Distance __n
) {
210 _Self
operator-(_Distance __n
) const {
211 return _Self(__current
+ __n
);
213 _Self
& operator-=(_Distance __n
) {
217 _Reference
operator[](_Distance __n
) const { return *(*this + __n
); }
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
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
>
228 inline _Tp
* _STLP_CALL
value_type(const reverse_iterator
<_RandomAccessIterator
, _Tp
, Reference__
, _Distance
>&)
230 template <class _RandomAccessIterator
, class _Tp
,
231 class __Reference
, class _Distance
>
232 inline _Distance
* _STLP_CALL
233 distance_type(const reverse_iterator
<_RandomAccessIterator
, _Tp
, Reference__
, _Distance
>&)
234 { return (_Distance
*) 0; }
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
)
245 return __x
.base() == __y
.base();
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
)
256 return __y
.base() < __x
.base();
259 # ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE
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
);
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
) {
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
) {
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
) {
301 # endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
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
)
311 return __y
.base() - __x
.base();
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
)
322 return reverse_iterator
<_RandomAccessIterator
, _Tp
,
323 Reference__
, _Distance
>(__x
.base() - __n
);
326 #endif /* ! defined ( _STLP_CLASS_PARTIAL_SPECIALIZATION ) */
330 #endif /* _STLP_INTERNAL_ITERATOR_H */