aboutsummaryrefslogtreecommitdiff
path: root/stlport/stl/_iterator_old.h
blob: 144b9ab388df0be29bac05722ae4be4abff09f43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
/*
 *
 * Copyright (c) 1994
 * Hewlett-Packard Company
 *
 * Copyright (c) 1996-1998
 * Silicon Graphics Computer Systems, Inc.
 *
 * Copyright (c) 1997
 * Moscow Center for SPARC Technology
 *
 * Copyright (c) 1999
 * Boris Fomitchev
 *
 * This material is provided "as is", with absolutely no warranty expressed
 * or implied. Any use is at your own risk.
 *
 * Permission to use or copy this software for any purpose is hereby granted
 * without fee, provided the above notices are retained on all copies.
 * Permission to modify the code and to distribute modified code is granted,
 * provided the above notices are retained, and a notice that the code was
 * modified is included with the above copyright notice.
 *
 */

/* NOTE: This is an internal header file, included by other STL headers.
 *   You should not attempt to use it directly.
 */

#ifndef _STLP_INTERNAL_ITERATOR_OLD_H
#define _STLP_INTERNAL_ITERATOR_OLD_H

#ifndef _STLP_INTERNAL_ITERATOR_BASE_H
#  include <stl/_iterator_base.h>
#endif

_STLP_BEGIN_NAMESPACE

#ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES

template <class _Container>
inline output_iterator_tag _STLP_CALL
iterator_category(const back_insert_iterator<_Container>&) { return output_iterator_tag(); }
template <class _Container>
inline output_iterator_tag _STLP_CALL
iterator_category(const front_insert_iterator<_Container>&) { return output_iterator_tag(); }
template <class _Container>
inline output_iterator_tag _STLP_CALL
iterator_category(const insert_iterator<_Container>&) { return output_iterator_tag(); }

#endif

template <class _BidirectionalIterator, class _Tp,
          _STLP_DFL_TMPL_PARAM(_Reference, _Tp& ),
#if defined (_STLP_MSVC50_COMPATIBILITY)
#  define __Reference _Reference, class _Pointer
#  define Reference__ _Reference, _Pointer
          _STLP_DFL_TMPL_PARAM(_Pointer, _Tp*),
#else
#  define __Reference _Reference
#  define Reference__ _Reference
#endif
          _STLP_DFL_TYPE_PARAM(_Distance, ptrdiff_t)>
class reverse_bidirectional_iterator {
  typedef reverse_bidirectional_iterator<_BidirectionalIterator, _Tp,
                                         Reference__, _Distance> _Self;
  //  friend inline bool operator== _STLP_NULL_TMPL_ARGS (const _Self& x, const _Self& y);
protected:
  _BidirectionalIterator current;
public:
  typedef bidirectional_iterator_tag iterator_category;
  typedef _Tp                        value_type;
  typedef _Distance                  difference_type;
#  if defined (_STLP_MSVC50_COMPATIBILITY)
  typedef _Pointer                   pointer;
#  else
  typedef _Tp*                       pointer;
#  endif
  typedef _Reference                 reference;

  reverse_bidirectional_iterator() {}
  explicit reverse_bidirectional_iterator(_BidirectionalIterator __x)
    : current(__x) {}
  _BidirectionalIterator base() const { return current; }
  _Reference operator*() const {
    _BidirectionalIterator __tmp = current;
    return *(--__tmp);
  }

  _STLP_DEFINE_ARROW_OPERATOR

  _Self& operator++() {
    --current;
    return *this;
  }
  _Self operator++(int) {
    _Self __tmp = *this;
    --current;
    return __tmp;
  }
  _Self& operator--() {
    ++current;
    return *this;
  }
  _Self operator--(int) {
    _Self __tmp = *this;
    ++current;
    return __tmp;
  }
};

#ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
template <class _BidirectionalIterator, class _Tp, class __Reference,
          class _Distance>
inline bidirectional_iterator_tag _STLP_CALL
iterator_category(const reverse_bidirectional_iterator<_BidirectionalIterator, _Tp, Reference__, _Distance>&)
{ return bidirectional_iterator_tag(); }
template <class _BidirectionalIterator, class _Tp, class __Reference,
  class _Distance>
inline _Tp* _STLP_CALL
value_type(const reverse_bidirectional_iterator<_BidirectionalIterator, _Tp, Reference__, _Distance>&)
{ return (_Tp*) 0; }
template <class _BidirectionalIterator, class _Tp, class __Reference,
          class _Distance>
inline _Distance* _STLP_CALL
distance_type(const reverse_bidirectional_iterator<_BidirectionalIterator, _Tp, Reference__, _Distance>&)
{ return (_Distance*) 0; }
#endif

template <class _BidirectionalIterator, class _Tp, class __Reference,
          class _Distance>
inline bool  _STLP_CALL operator==(
    const reverse_bidirectional_iterator<_BidirectionalIterator, _Tp,
                                               Reference__, _Distance>& __x,
    const reverse_bidirectional_iterator<_BidirectionalIterator, _Tp,
                                               Reference__, _Distance>& __y)
{ return __x.base() == __y.base(); }

#ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE

template <class _BiIter, class _Tp, class __Reference, class _Distance>
inline bool  _STLP_CALL operator!=(
    const reverse_bidirectional_iterator<_BiIter, _Tp, Reference__, _Distance>& __x,
    const reverse_bidirectional_iterator<_BiIter, _Tp, Reference__, _Distance>& __y)
{ return !(__x == __y); }

#endif

#if !defined ( _STLP_CLASS_PARTIAL_SPECIALIZATION )

// This is the old version of reverse_iterator, as found in the original
//  HP STL.  It does not use partial specialization.

template <class _RandomAccessIterator, class _Tp,
          _STLP_DFL_TMPL_PARAM(_Reference,_Tp&),
#  if defined (_STLP_MSVC50_COMPATIBILITY)
          _STLP_DFL_TMPL_PARAM(_Pointer, _Tp*),
#  endif
          _STLP_DFL_TYPE_PARAM(_Distance,ptrdiff_t)>
class reverse_iterator {
  typedef reverse_iterator<_RandomAccessIterator, _Tp, Reference__, _Distance> _Self;
protected:
  _RandomAccessIterator __current;
public:
  typedef random_access_iterator_tag iterator_category;
  typedef _Tp                        value_type;
  typedef _Distance                  difference_type;
#  if defined (_STLP_MSVC50_COMPATIBILITY)
  typedef _Pointer                   pointer;
#  else
  typedef _Tp*                       pointer;
#  endif
  typedef _Reference                 reference;

  reverse_iterator() {}
  reverse_iterator(const _Self& __x) : __current(__x.base()) {}
  explicit reverse_iterator(_RandomAccessIterator __x) : __current(__x) {}
  _Self& operator=(const _Self& __x) {__current = __x.base(); return *this; }

  _RandomAccessIterator base() const { return __current; }
  _Reference operator*() const { return *(__current - (difference_type)1); }

  _STLP_DEFINE_ARROW_OPERATOR

  _Self& operator++() {
    --__current;
    return *this;
  }
  _Self operator++(int) {
    _Self __tmp = *this;
    --__current;
    return __tmp;
  }
  _Self& operator--() {
    ++__current;
    return *this;
  }
  _Self operator--(int) {
    _Self __tmp = *this;
    ++__current;
    return __tmp;
  }
  _Self operator+(_Distance __n) const {
    return _Self(__current - __n);
  }
  _Self& operator+=(_Distance __n) {
    __current -= __n;
    return *this;
  }
  _Self operator-(_Distance __n) const {
    return _Self(__current + __n);
  }
  _Self& operator-=(_Distance __n) {
    __current += __n;
    return *this;
  }
  _Reference operator[](_Distance __n) const { return *(*this + __n); }
};

#  ifdef _STLP_USE_OLD_HP_ITERATOR_QUERIES
template <class _RandomAccessIterator, class _Tp,
          class __Reference, class _Distance>
inline random_access_iterator_tag _STLP_CALL
iterator_category(const reverse_iterator<_RandomAccessIterator, _Tp, Reference__, _Distance>&)
{ return random_access_iterator_tag(); }
template <class _RandomAccessIterator, class _Tp,
  class __Reference, class _Distance>
inline _Tp*  _STLP_CALL value_type(const reverse_iterator<_RandomAccessIterator, _Tp, Reference__, _Distance>&)
{ return (_Tp*) 0; }
template <class _RandomAccessIterator, class _Tp,
          class __Reference, class _Distance>
inline _Distance*  _STLP_CALL
distance_type(const reverse_iterator<_RandomAccessIterator, _Tp, Reference__, _Distance>&)
{ return (_Distance*) 0; }
#  endif

template <class _RandomAccessIterator, class _Tp,
          class __Reference, class _Distance>
inline bool  _STLP_CALL
operator==(const reverse_iterator<_RandomAccessIterator, _Tp,
                                  Reference__, _Distance>& __x,
           const reverse_iterator<_RandomAccessIterator, _Tp,
                                  Reference__, _Distance>& __y)
{
  return __x.base() == __y.base();
}

template <class _RandomAccessIterator, class _Tp,
          class __Reference, class _Distance>
inline bool _STLP_CALL
operator<(const reverse_iterator<_RandomAccessIterator, _Tp,
                                 Reference__, _Distance>& __x,
          const reverse_iterator<_RandomAccessIterator, _Tp,
                                 Reference__, _Distance>& __y)
{
  return __y.base() < __x.base();
}

#  ifdef _STLP_USE_SEPARATE_RELOPS_NAMESPACE

template <class _RandomAccessIterator, class _Tp,
          class __Reference, class _Distance>
inline bool _STLP_CALL
operator!=(const reverse_iterator<_RandomAccessIterator, _Tp,
                                  Reference__, _Distance>& __x,
           const reverse_iterator<_RandomAccessIterator, _Tp,
                                  Reference__, _Distance>& __y) {
  return !(__x == __y);
}

template <class _RandomAccessIterator, class _Tp,
          class __Reference, class _Distance>
inline bool _STLP_CALL
operator>(const reverse_iterator<_RandomAccessIterator, _Tp,
                                 Reference__, _Distance>& __x,
          const reverse_iterator<_RandomAccessIterator, _Tp,
                                 Reference__, _Distance>& __y) {
  return __y < __x;
}

template <class _RandomAccessIterator, class _Tp,
          class __Reference, class _Distance>
inline bool _STLP_CALL
operator<=(const reverse_iterator<_RandomAccessIterator, _Tp,
                                  Reference__, _Distance>& __x,
           const reverse_iterator<_RandomAccessIterator, _Tp,
                                  Reference__, _Distance>& __y) {
  return !(__y < __x);
}

template <class _RandomAccessIterator, class _Tp,
          class __Reference, class _Distance>
inline bool _STLP_CALL
operator>=(const reverse_iterator<_RandomAccessIterator, _Tp,
                                  Reference__, _Distance>& __x,
           const reverse_iterator<_RandomAccessIterator, _Tp,
                                  Reference__, _Distance>& __y) {
  return !(__x < __y);
}

#  endif /* _STLP_USE_SEPARATE_RELOPS_NAMESPACE */

template <class _RandomAccessIterator, class _Tp,
          class __Reference, class _Distance>
inline _Distance  _STLP_CALL
operator-(const reverse_iterator<_RandomAccessIterator, _Tp,
                                 Reference__, _Distance>& __x,
          const reverse_iterator<_RandomAccessIterator, _Tp,
                                 Reference__, _Distance>& __y)
{
  return __y.base() - __x.base();
}

template <class _RandomAccessIterator, class _Tp,
          class __Reference, class _Distance>
inline reverse_iterator<_RandomAccessIterator, _Tp,
                        Reference__, _Distance>  _STLP_CALL
operator+(_Distance __n,
          const reverse_iterator<_RandomAccessIterator, _Tp,
                                 Reference__, _Distance>& __x)
{
  return reverse_iterator<_RandomAccessIterator, _Tp,
                          Reference__, _Distance>(__x.base() - __n);
}

#endif /* ! defined ( _STLP_CLASS_PARTIAL_SPECIALIZATION ) */

_STLP_END_NAMESPACE

#endif /* _STLP_INTERNAL_ITERATOR_H */

// Local Variables:
// mode:C++
// End: