ReactOS  0.4.14-dev-52-g6116262
_iterator.h
Go to the documentation of this file.
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_H
31 #define _STLP_INTERNAL_ITERATOR_H
32 
33 #ifndef _STLP_INTERNAL_ITERATOR_BASE_H
34 # include <stl/_iterator_base.h>
35 #endif
36 
38 
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.
45 
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> {
53 protected:
54  _Iterator current;
56 public:
58  // pointer type required for arrow operator hidden behind _STLP_DEFINE_ARROW_OPERATOR:
61  typedef _Iterator iterator_type;
62 public:
63  reverse_iterator() {}
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>
70  template <class _Iter>
71  _Self& operator = (const reverse_iterator<_Iter>& __x) { current = __x.base(); return *this; }
72 # endif /* _STLP_MEMBER_TEMPLATES */
73 
74  iterator_type base() const { return current; }
75  reference operator*() const {
76  _Iterator __tmp = current;
77  return *--__tmp;
78  }
80  _Self& operator++() {
81  --current;
82  return *this;
83  }
84  _Self operator++(int) {
85  _Self __tmp = *this;
86  --current;
87  return __tmp;
88  }
89  _Self& operator--() {
90  ++current;
91  return *this;
92  }
93  _Self operator--(int) {
94  _Self __tmp = *this;
95  ++current;
96  return __tmp;
97  }
98 
99  _Self operator+(difference_type __n) const { return _Self(current - __n); }
101  current -= __n;
102  return *this;
103  }
104  _Self operator-(difference_type __n) const { return _Self(current + __n); }
106  current += __n;
107  return *this;
108  }
109  reference operator[](difference_type __n) const { return *(*this + __n); }
110 };
111 
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(); }
116 
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(); }
121 
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); }
127 
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; }
132 
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); }
137 
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 */
143 
144 template <class _Iterator>
145 # if defined (__SUNPRO_CC)
146 inline ptrdiff_t _STLP_CALL
147 # else
149 # endif
151  const reverse_iterator<_Iterator>& __y)
152 { return __y.base() - __x.base(); }
153 
154 template <class _Iterator, class _DifferenceType>
156 operator+(_DifferenceType n,const reverse_iterator<_Iterator>& x)
157 { return x.operator+(n); }
158 #endif
159 
160 template <class _Container>
162  : public iterator<output_iterator_tag, void, void, void, void> {
164 protected:
165  //c is a Standard name (24.4.2.1), do no make it STLport naming convention compliant.
166  _Container *container;
167 public:
168  typedef _Container container_type;
170 
171  explicit back_insert_iterator(_Container& __x) : container(&__x) {}
172 
173  _Self& operator=(const _Self& __other) {
174  container = __other.container;
175  return *this;
176  }
177  _Self& operator=(const typename _Container::value_type& __val) {
178  container->push_back(__val);
179  return *this;
180  }
181  _Self& operator*() { return *this; }
182  _Self& operator++() { return *this; }
183  _Self operator++(int) { return *this; }
184 };
185 
186 template <class _Container>
188 { return back_insert_iterator<_Container>(__x); }
189 
190 template <class _Container>
192  : public iterator<output_iterator_tag, void, void, void, void> {
194 protected:
195  //c is a Standard name (24.4.2.3), do no make it STLport naming convention compliant.
196  _Container *container;
197 public:
198  typedef _Container container_type;
200  explicit front_insert_iterator(_Container& __x) : container(&__x) {}
201 
202  _Self& operator=(const _Self& __other) {
203  container = __other.container;
204  return *this;
205  }
206  _Self& operator=(const typename _Container::value_type& __val) {
207  container->push_front(__val);
208  return *this;
209  }
210  _Self& operator*() { return *this; }
211  _Self& operator++() { return *this; }
212  _Self operator++(int) { return *this; }
213 };
214 
215 template <class _Container>
217 { return front_insert_iterator<_Container>(__x); }
218 
219 template <class _Container>
221  : public iterator<output_iterator_tag, void, void, void, void> {
223 protected:
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;
227 public:
228  typedef _Container container_type;
230  insert_iterator(_Container& __x, typename _Container::iterator __i)
231  : container(&__x), _M_iter(__i) {}
232 
233  _Self& operator=(_Self const& __other) {
234  container = __other.container;
235  _M_iter = __other._M_iter;
236  return *this;
237  }
238  _Self& operator=(const typename _Container::value_type& __val) {
239  _M_iter = container->insert(_M_iter, __val);
240  ++_M_iter;
241  return *this;
242  }
243  _Self& operator*() { return *this; }
244  _Self& operator++() { return *this; }
245  _Self& operator++(int) { return *this; }
246 };
247 
248 template <class _Container, class _Iterator>
250 inserter(_Container& __x, _Iterator __i) {
251  typedef typename _Container::iterator __iter;
252  return insert_iterator<_Container>(__x, __iter(__i));
253 }
254 
256 
257 #if ! defined (_STLP_CLASS_PARTIAL_SPECIALIZATION) || defined (_STLP_USE_OLD_HP_ITERATOR_QUERIES)
258 # include <stl/_iterator_old.h>
259 #endif
260 
261 #endif /* _STLP_INTERNAL_ITERATOR_H */
262 
263 // Local Variables:
264 // mode:C++
265 // End:
bool operator==(const _DBG_iter_base< _Container > &__x, const _DBG_iter_base< _Container > &__y)
Definition: _iterator.h:306
_Self & operator *()
Definition: _iterator.h:181
_Container container_type
Definition: _iterator.h:228
_Self & operator++()
Definition: _iterator.h:182
_Iterator::difference_type difference_type
_Self & operator *()
Definition: _iterator.h:243
return __n
Definition: _algo.h:75
_Self & operator++()
Definition: _iterator.h:211
_Self & operator=(const typename _Container::value_type &__val)
Definition: _iterator.h:238
bool operator!=(const _DBG_iter_base< _Container > &__x, const _DBG_iter_base< _Container > &__y)
Definition: _iterator.h:345
_Reference operator[](_Distance __n) const
GLdouble n
Definition: glext.h:7729
_Self & operator=(const _Self &__other)
Definition: _iterator.h:173
_Self & operator--()
_Self & operator=(const _Self &__x)
bool operator>=(const _DBG_iter_base< _Container > &__x, const _DBG_iter_base< _Container > &__y)
Definition: _iterator.h:329
_Container * container
Definition: _iterator.h:196
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
output_iterator_tag iterator_category
Definition: _iterator.h:169
ptrdiff_t operator-(const _DBG_iter_base< _Container > &__x, const _DBG_iter_base< _Container > &__y)
Definition: _iterator.h:175
_Container container_type
Definition: _iterator.h:198
insert_iterator< _Container > _Self
Definition: _iterator.h:222
_Iterator::pointer pointer
_Self & operator+=(_Distance __n)
_Distance difference_type
_Self & operator++(int)
Definition: _iterator.h:245
_DBG_iter< _Container, _Traits > operator+(ptrdiff_t __n, const _DBG_iter< _Container, _Traits > &__it)
Definition: _iterator.h:355
back_insert_iterator< _Container > _STLP_CALL back_inserter(_Container &__x)
Definition: _iterator.h:187
_RandomAccessIterator base() const
front_insert_iterator(_Container &__x)
Definition: _iterator.h:200
_Container * container
Definition: _iterator.h:166
front_insert_iterator< _Container > _Self
Definition: _iterator.h:193
_Container::iterator _M_iter
Definition: _iterator.h:226
output_iterator_tag iterator_category
Definition: _iterator.h:229
_Iterator::reference reference
bool operator<(const _DBG_iter_base< _Container > &__x, const _DBG_iter_base< _Container > &__y)
Definition: _iterator.h:313
back_insert_iterator(_Container &__x)
Definition: _iterator.h:171
_Self operator-(_Distance __n) const
reverse_iterator< _RandomAccessIterator, _Tp, Reference__, _Distance > _Self
_STLP_INLINE_LOOP _InputIter const _Tp & __val
Definition: _algobase.h:656
insert_iterator< _Container > _STLP_CALL inserter(_Container &__x, _Iterator __i)
Definition: _iterator.h:250
_Self operator++(int)
Definition: _iterator.h:212
_Reference reference
front_insert_iterator< _Container > _STLP_CALL front_inserter(_Container &__x)
Definition: _iterator.h:216
_Self operator+(_Distance __n) const
GLint reference
Definition: glext.h:11729
back_insert_iterator< _Container > _Self
Definition: _iterator.h:163
_Self & operator=(const typename _Container::value_type &__val)
Definition: _iterator.h:177
_Self & operator *()
Definition: _iterator.h:210
_Reference operator *() const
_Self & operator-=(_Distance __n)
bool operator>(const _DBG_iter_base< _Container > &__x, const _DBG_iter_base< _Container > &__y)
Definition: _iterator.h:321
_Container * container
Definition: _iterator.h:225
_Self & operator=(const _Self &__other)
Definition: _iterator.h:202
_Container container_type
Definition: _iterator.h:168
#define _STLP_END_NAMESPACE
Definition: features.h:503
output_iterator_tag iterator_category
Definition: _iterator.h:199
__kernel_ptrdiff_t ptrdiff_t
Definition: linux.h:247
_STLP_DEFINE_ARROW_OPERATOR _Self & operator++()
#define _STLP_DEFINE_ARROW_OPERATOR
_Self & operator=(const typename _Container::value_type &__val)
Definition: _iterator.h:206
_Self & operator++()
Definition: _iterator.h:244
#define _STLP_BEGIN_NAMESPACE
Definition: features.h:501
bool operator<=(const _DBG_iter_base< _Container > &__x, const _DBG_iter_base< _Container > &__y)
Definition: _iterator.h:337
insert_iterator(_Container &__x, typename _Container::iterator __i)
Definition: _iterator.h:230
#define _STLP_CALL
Definition: _bc.h:131
_Self operator++(int)
Definition: _iterator.h:183
struct task_struct * current
Definition: linux.c:32
_Self & operator=(_Self const &__other)
Definition: _iterator.h:233