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_H
31 #define _STLP_INTERNAL_ITERATOR_H
33 #ifndef _STLP_INTERNAL_ITERATOR_BASE_H
34 # include <stl/_iterator_base.h>
39 #if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
40 // This is the new version of reverse_iterator, as defined in the
41 // draft C++ standard. It relies on the iterator_traits template,
42 // which in turn relies on partial specialization. The class
43 // reverse_bidirectional_iterator is no longer part of the draft
44 // standard, but it is retained for backward compatibility.
46 template <class _Iterator
>
47 class reverse_iterator
:
48 public iterator
<typename iterator_traits
<_Iterator
>::iterator_category
,
49 typename iterator_traits
<_Iterator
>::value_type
,
50 typename iterator_traits
<_Iterator
>::difference_type
,
51 typename iterator_traits
<_Iterator
>::pointer
,
52 typename iterator_traits
<_Iterator
>::reference
> {
55 typedef reverse_iterator
<_Iterator
> _Self
;
57 typedef typename iterator_traits
<_Iterator
>::difference_type difference_type
;
58 // pointer type required for arrow operator hidden behind _STLP_DEFINE_ARROW_OPERATOR:
59 typedef typename iterator_traits
<_Iterator
>::pointer pointer
;
60 typedef typename iterator_traits
<_Iterator
>::reference reference
;
61 typedef _Iterator iterator_type
;
64 explicit reverse_iterator(iterator_type __x
) : current(__x
) {}
65 reverse_iterator(const _Self
& __x
) : current(__x
.current
) {}
66 _Self
& operator = (const _Self
& __x
) { current
= __x
.base(); return *this; }
67 # if defined (_STLP_MEMBER_TEMPLATES)
68 template <class _Iter
>
69 reverse_iterator(const reverse_iterator
<_Iter
>& __x
) : current(__x
.base()) {}
70 template <class _Iter
>
71 _Self
& operator = (const reverse_iterator
<_Iter
>& __x
) { current
= __x
.base(); return *this; }
72 # endif /* _STLP_MEMBER_TEMPLATES */
74 iterator_type
base() const { return current
; }
75 reference
operator*() const {
76 _Iterator __tmp
= current
;
79 _STLP_DEFINE_ARROW_OPERATOR
84 _Self
operator++(int) {
93 _Self
operator--(int) {
99 _Self
operator+(difference_type __n
) const { return _Self(current
- __n
); }
100 _Self
& operator+=(difference_type __n
) {
104 _Self
operator-(difference_type __n
) const { return _Self(current
+ __n
); }
105 _Self
& operator-=(difference_type __n
) {
109 reference
operator[](difference_type __n
) const { return *(*this + __n
); }
112 template <class _Iterator
>
113 inline bool _STLP_CALL
operator==(const reverse_iterator
<_Iterator
>& __x
,
114 const reverse_iterator
<_Iterator
>& __y
)
115 { return __x
.base() == __y
.base(); }
117 template <class _Iterator
>
118 inline bool _STLP_CALL
operator<(const reverse_iterator
<_Iterator
>& __x
,
119 const reverse_iterator
<_Iterator
>& __y
)
120 { return __y
.base() < __x
.base(); }
122 # if defined (_STLP_USE_SEPARATE_RELOPS_NAMESPACE)
123 template <class _Iterator
>
124 inline bool _STLP_CALL
operator!=(const reverse_iterator
<_Iterator
>& __x
,
125 const reverse_iterator
<_Iterator
>& __y
)
126 { return !(__x
== __y
); }
128 template <class _Iterator
>
129 inline bool _STLP_CALL
operator>(const reverse_iterator
<_Iterator
>& __x
,
130 const reverse_iterator
<_Iterator
>& __y
)
131 { return __y
< __x
; }
133 template <class _Iterator
>
134 inline bool _STLP_CALL
operator<=(const reverse_iterator
<_Iterator
>& __x
,
135 const reverse_iterator
<_Iterator
>& __y
)
136 { return !(__y
< __x
); }
138 template <class _Iterator
>
139 inline bool _STLP_CALL
operator>=(const reverse_iterator
<_Iterator
>& __x
,
140 const reverse_iterator
<_Iterator
>& __y
)
141 { return !(__x
< __y
); }
142 # endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */
144 template <class _Iterator
>
145 # if defined (__SUNPRO_CC)
146 inline ptrdiff_t _STLP_CALL
148 inline typename reverse_iterator
<_Iterator
>::difference_type _STLP_CALL
150 operator-(const reverse_iterator
<_Iterator
>& __x
,
151 const reverse_iterator
<_Iterator
>& __y
)
152 { return __y
.base() - __x
.base(); }
154 template <class _Iterator
, class _DifferenceType
>
155 inline reverse_iterator
<_Iterator
> _STLP_CALL
156 operator+(_DifferenceType n
,const reverse_iterator
<_Iterator
>& x
)
157 { return x
.operator+(n
); }
160 template <class _Container
>
161 class back_insert_iterator
162 : public iterator
<output_iterator_tag
, void, void, void, void> {
163 typedef back_insert_iterator
<_Container
> _Self
;
165 //c is a Standard name (24.4.2.1), do no make it STLport naming convention compliant.
166 _Container
*container
;
168 typedef _Container container_type
;
169 typedef output_iterator_tag iterator_category
;
171 explicit back_insert_iterator(_Container
& __x
) : container(&__x
) {}
173 _Self
& operator=(const _Self
& __other
) {
174 container
= __other
.container
;
177 _Self
& operator=(const typename
_Container::value_type
& __val
) {
178 container
->push_back(__val
);
181 _Self
& operator*() { return *this; }
182 _Self
& operator++() { return *this; }
183 _Self
operator++(int) { return *this; }
186 template <class _Container
>
187 inline back_insert_iterator
<_Container
> _STLP_CALL
back_inserter(_Container
& __x
)
188 { return back_insert_iterator
<_Container
>(__x
); }
190 template <class _Container
>
191 class front_insert_iterator
192 : public iterator
<output_iterator_tag
, void, void, void, void> {
193 typedef front_insert_iterator
<_Container
> _Self
;
195 //c is a Standard name (24.4.2.3), do no make it STLport naming convention compliant.
196 _Container
*container
;
198 typedef _Container container_type
;
199 typedef output_iterator_tag iterator_category
;
200 explicit front_insert_iterator(_Container
& __x
) : container(&__x
) {}
202 _Self
& operator=(const _Self
& __other
) {
203 container
= __other
.container
;
206 _Self
& operator=(const typename
_Container::value_type
& __val
) {
207 container
->push_front(__val
);
210 _Self
& operator*() { return *this; }
211 _Self
& operator++() { return *this; }
212 _Self
operator++(int) { return *this; }
215 template <class _Container
>
216 inline front_insert_iterator
<_Container
> _STLP_CALL
front_inserter(_Container
& __x
)
217 { return front_insert_iterator
<_Container
>(__x
); }
219 template <class _Container
>
220 class insert_iterator
221 : public iterator
<output_iterator_tag
, void, void, void, void> {
222 typedef insert_iterator
<_Container
> _Self
;
224 //container is a Standard name (24.4.2.5), do no make it STLport naming convention compliant.
225 _Container
*container
;
226 typename
_Container::iterator _M_iter
;
228 typedef _Container container_type
;
229 typedef output_iterator_tag iterator_category
;
230 insert_iterator(_Container
& __x
, typename
_Container::iterator __i
)
231 : container(&__x
), _M_iter(__i
) {}
233 _Self
& operator=(_Self
const& __other
) {
234 container
= __other
.container
;
235 _M_iter
= __other
._M_iter
;
238 _Self
& operator=(const typename
_Container::value_type
& __val
) {
239 _M_iter
= container
->insert(_M_iter
, __val
);
243 _Self
& operator*() { return *this; }
244 _Self
& operator++() { return *this; }
245 _Self
& operator++(int) { return *this; }
248 template <class _Container
, class _Iterator
>
249 inline insert_iterator
<_Container
> _STLP_CALL
250 inserter(_Container
& __x
, _Iterator __i
) {
251 typedef typename
_Container::iterator __iter
;
252 return insert_iterator
<_Container
>(__x
, __iter(__i
));
257 #if ! defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) || defined (_STLP_USE_OLD_HP_ITERATOR_QUERIES)
258 # include <stl/_iterator_old.h>
261 #endif /* _STLP_INTERNAL_ITERATOR_H */