1 | // |
---|
2 | // Boost.Pointer Container |
---|
3 | // |
---|
4 | // Copyright Thorsten Ottosen 2003-2005. Use, modification and |
---|
5 | // distribution is subject to the Boost Software License, Version |
---|
6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
---|
7 | // http://www.boost.org/LICENSE_1_0.txt) |
---|
8 | // |
---|
9 | // For more information, see http://www.boost.org/libs/ptr_container/ |
---|
10 | // |
---|
11 | |
---|
12 | #ifndef BOOST_PTR_CONTAINER_DETAIL_VOID_PTR_ITERATOR_HPP |
---|
13 | #define BOOST_PTR_CONTAINER_DETAIL_VOID_PTR_ITERATOR_HPP |
---|
14 | |
---|
15 | #if defined(_MSC_VER) && (_MSC_VER >= 1200) |
---|
16 | # pragma once |
---|
17 | #endif |
---|
18 | |
---|
19 | #include <boost/config.hpp> |
---|
20 | #include <boost/iterator/iterator_traits.hpp> |
---|
21 | |
---|
22 | namespace boost |
---|
23 | { |
---|
24 | template |
---|
25 | < |
---|
26 | class VoidIter, |
---|
27 | class T |
---|
28 | > |
---|
29 | class void_ptr_iterator |
---|
30 | { |
---|
31 | public: |
---|
32 | typedef T value_type; |
---|
33 | typedef T& reference; |
---|
34 | typedef T* pointer; |
---|
35 | |
---|
36 | typedef BOOST_DEDUCED_TYPENAME iterator_difference<VoidIter>::type |
---|
37 | difference_type; |
---|
38 | typedef BOOST_DEDUCED_TYPENAME iterator_category<VoidIter>::type |
---|
39 | iterator_category; |
---|
40 | private: |
---|
41 | |
---|
42 | VoidIter iter_; |
---|
43 | |
---|
44 | public: |
---|
45 | void_ptr_iterator() : iter_() |
---|
46 | { } |
---|
47 | |
---|
48 | void_ptr_iterator( VoidIter r ) : iter_(r) |
---|
49 | { } |
---|
50 | |
---|
51 | // |
---|
52 | // Remark: passing by value breaks vc7.1 |
---|
53 | // |
---|
54 | template< class MutableIterator, class MutableT > |
---|
55 | void_ptr_iterator( const void_ptr_iterator<MutableIterator,MutableT>& r ) |
---|
56 | #ifdef BOOST_NO_SFINAE |
---|
57 | : iter_( VoidIter(const_cast<void**>(&*r.base())) ) |
---|
58 | #else |
---|
59 | |
---|
60 | : iter_(r.base()) |
---|
61 | #endif |
---|
62 | { } |
---|
63 | |
---|
64 | T& operator*() const |
---|
65 | { |
---|
66 | return *static_cast<T*>( *iter_ ); |
---|
67 | } |
---|
68 | |
---|
69 | T* operator->() const |
---|
70 | { |
---|
71 | return static_cast<T*>( *iter_ ); |
---|
72 | } |
---|
73 | |
---|
74 | void_ptr_iterator& operator++() |
---|
75 | { |
---|
76 | ++iter_; |
---|
77 | return *this; |
---|
78 | } |
---|
79 | |
---|
80 | void_ptr_iterator operator++(int) |
---|
81 | { |
---|
82 | void_ptr_iterator res = *this; |
---|
83 | ++iter_; |
---|
84 | return res; |
---|
85 | } |
---|
86 | |
---|
87 | void_ptr_iterator& operator--() |
---|
88 | { |
---|
89 | --iter_; |
---|
90 | return *this; |
---|
91 | } |
---|
92 | |
---|
93 | void_ptr_iterator operator--(int) |
---|
94 | { |
---|
95 | void_ptr_iterator res = *this; |
---|
96 | --iter_; |
---|
97 | return res; |
---|
98 | } |
---|
99 | |
---|
100 | void_ptr_iterator& operator+=( difference_type n ) |
---|
101 | { |
---|
102 | iter_ += n; |
---|
103 | return *this; |
---|
104 | } |
---|
105 | |
---|
106 | void_ptr_iterator& operator-=( difference_type n ) |
---|
107 | { |
---|
108 | iter_ -= n; |
---|
109 | return *this; |
---|
110 | } |
---|
111 | |
---|
112 | T& operator[]( difference_type n ) const |
---|
113 | { |
---|
114 | return *static_cast<T*>( *(iter_ + n) ); |
---|
115 | } |
---|
116 | |
---|
117 | VoidIter base() const |
---|
118 | { |
---|
119 | return iter_; |
---|
120 | } |
---|
121 | |
---|
122 | }; // class 'void_ptr_iterator' |
---|
123 | |
---|
124 | template< class VoidIter, class T > |
---|
125 | inline void_ptr_iterator<VoidIter,T> |
---|
126 | operator+( void_ptr_iterator<VoidIter,T> l, |
---|
127 | BOOST_DEDUCED_TYPENAME void_ptr_iterator<VoidIter,T>::difference_type n ) |
---|
128 | { |
---|
129 | l += n; |
---|
130 | return l; |
---|
131 | } |
---|
132 | |
---|
133 | template< class VoidIter, class T > |
---|
134 | inline void_ptr_iterator<VoidIter,T> |
---|
135 | operator+( BOOST_DEDUCED_TYPENAME void_ptr_iterator<VoidIter,T>::difference_type n, |
---|
136 | void_ptr_iterator<VoidIter,T> r ) |
---|
137 | |
---|
138 | { |
---|
139 | r += n; |
---|
140 | return r; |
---|
141 | } |
---|
142 | |
---|
143 | template< class VoidIter, class T > |
---|
144 | inline void_ptr_iterator<VoidIter,T> |
---|
145 | operator-( void_ptr_iterator<VoidIter,T> l, |
---|
146 | BOOST_DEDUCED_TYPENAME void_ptr_iterator<VoidIter,T>::difference_type n ) |
---|
147 | { |
---|
148 | l -= n; |
---|
149 | return l; |
---|
150 | } |
---|
151 | |
---|
152 | template< class VoidIter, class T > |
---|
153 | inline void_ptr_iterator<VoidIter,T> |
---|
154 | operator-( BOOST_DEDUCED_TYPENAME void_ptr_iterator<VoidIter,T>::difference_type n, |
---|
155 | void_ptr_iterator<VoidIter,T> r ) |
---|
156 | |
---|
157 | { |
---|
158 | r -= n; |
---|
159 | return r; |
---|
160 | } |
---|
161 | |
---|
162 | template< class VoidIter, class T, class VoidIterU, class U > |
---|
163 | inline BOOST_DEDUCED_TYPENAME void_ptr_iterator<VoidIter,T>::difference_type |
---|
164 | operator-( void_ptr_iterator<VoidIter,T> l, |
---|
165 | void_ptr_iterator<VoidIterU,U> r ) |
---|
166 | |
---|
167 | { |
---|
168 | return l.base() - r.base(); |
---|
169 | } |
---|
170 | |
---|
171 | |
---|
172 | |
---|
173 | template< class VoidIterT, class T, class VoidIterU, class U > |
---|
174 | inline bool operator==( const void_ptr_iterator<VoidIterT,T>& l, |
---|
175 | const void_ptr_iterator<VoidIterU,U>& r ) |
---|
176 | { |
---|
177 | return l.base() == r.base(); |
---|
178 | } |
---|
179 | |
---|
180 | |
---|
181 | |
---|
182 | template< class VoidIterT, class T, class VoidIterU, class U > |
---|
183 | inline bool operator!=( const void_ptr_iterator<VoidIterT,T>& l, |
---|
184 | const void_ptr_iterator<VoidIterU,U>& r ) |
---|
185 | { |
---|
186 | return l.base() != r.base(); |
---|
187 | } |
---|
188 | |
---|
189 | |
---|
190 | |
---|
191 | template< class VoidIterT, class T, class VoidIterU, class U > |
---|
192 | inline bool operator<( const void_ptr_iterator<VoidIterT,T>& l, |
---|
193 | const void_ptr_iterator<VoidIterU,U>& r ) |
---|
194 | { |
---|
195 | return l.base() < r.base(); |
---|
196 | } |
---|
197 | |
---|
198 | |
---|
199 | |
---|
200 | template< class VoidIterT, class T, class VoidIterU, class U > |
---|
201 | inline bool operator<=( const void_ptr_iterator<VoidIterT,T>& l, |
---|
202 | const void_ptr_iterator<VoidIterU,U>& r ) |
---|
203 | { |
---|
204 | return l.base() <= r.base(); |
---|
205 | } |
---|
206 | |
---|
207 | |
---|
208 | |
---|
209 | template< class VoidIterT, class T, class VoidIterU, class U > |
---|
210 | inline bool operator>( const void_ptr_iterator<VoidIterT,T>& l, |
---|
211 | const void_ptr_iterator<VoidIterU,U>& r ) |
---|
212 | { |
---|
213 | return l.base() > r.base(); |
---|
214 | } |
---|
215 | |
---|
216 | |
---|
217 | |
---|
218 | template< class VoidIterT, class T, class VoidIterU, class U > |
---|
219 | inline bool operator>=( const void_ptr_iterator<VoidIterT,T>& l, |
---|
220 | const void_ptr_iterator<VoidIterU,U>& r ) |
---|
221 | { |
---|
222 | return l.base() >= r.base(); |
---|
223 | } |
---|
224 | |
---|
225 | } |
---|
226 | |
---|
227 | #endif |
---|