2 // Boost.Pointer Container
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)
9 // For more information, see http://www.boost.org/libs/ptr_container/
12 #ifndef BOOST_PTR_CONTAINER_DETAIL_VOID_PTR_ITERATOR_HPP
13 #define BOOST_PTR_CONTAINER_DETAIL_VOID_PTR_ITERATOR_HPP
15 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
19 #include <boost/config.hpp>
20 #include <boost/iterator/iterator_traits.hpp>
21 #include <boost/type_traits/remove_const.hpp>
30 class void_ptr_iterator
33 typedef BOOST_DEDUCED_TYPENAME
boost::remove_const
<T
>::type
38 typedef BOOST_DEDUCED_TYPENAME iterator_difference
<VoidIter
>::type
40 typedef BOOST_DEDUCED_TYPENAME iterator_category
<VoidIter
>::type
47 void_ptr_iterator() : iter_()
50 void_ptr_iterator( VoidIter r
) : iter_(r
)
54 // Remark: passing by value breaks vc7.1
56 template< class MutableIterator
, class MutableT
>
57 void_ptr_iterator( const void_ptr_iterator
<MutableIterator
,MutableT
>& r
)
58 #ifdef BOOST_NO_SFINAE
59 : iter_( VoidIter(const_cast<void**>(&*r
.base())) )
68 return *static_cast<T
*>( *iter_
);
73 return static_cast<T
*>( *iter_
);
76 void_ptr_iterator
& operator++()
82 void_ptr_iterator
operator++(int)
84 void_ptr_iterator res
= *this;
89 void_ptr_iterator
& operator--()
95 void_ptr_iterator
operator--(int)
97 void_ptr_iterator res
= *this;
102 void_ptr_iterator
& operator+=( difference_type n
)
108 void_ptr_iterator
& operator-=( difference_type n
)
114 T
& operator[]( difference_type n
) const
116 return *static_cast<T
*>( *(iter_
+ n
) );
119 VoidIter
base() const
124 }; // class 'void_ptr_iterator'
126 template< class VoidIter
, class T
>
127 inline void_ptr_iterator
<VoidIter
,T
>
128 operator+( void_ptr_iterator
<VoidIter
,T
> l
,
129 BOOST_DEDUCED_TYPENAME void_ptr_iterator
<VoidIter
,T
>::difference_type n
)
135 template< class VoidIter
, class T
>
136 inline void_ptr_iterator
<VoidIter
,T
>
137 operator+( BOOST_DEDUCED_TYPENAME void_ptr_iterator
<VoidIter
,T
>::difference_type n
,
138 void_ptr_iterator
<VoidIter
,T
> r
)
145 template< class VoidIter
, class T
>
146 inline void_ptr_iterator
<VoidIter
,T
>
147 operator-( void_ptr_iterator
<VoidIter
,T
> l
,
148 BOOST_DEDUCED_TYPENAME void_ptr_iterator
<VoidIter
,T
>::difference_type n
)
154 template< class VoidIter
, class T
>
155 inline void_ptr_iterator
<VoidIter
,T
>
156 operator-( BOOST_DEDUCED_TYPENAME void_ptr_iterator
<VoidIter
,T
>::difference_type n
,
157 void_ptr_iterator
<VoidIter
,T
> r
)
164 template< class VoidIter
, class T
, class VoidIterU
, class U
>
165 inline BOOST_DEDUCED_TYPENAME void_ptr_iterator
<VoidIter
,T
>::difference_type
166 operator-( void_ptr_iterator
<VoidIter
,T
> l
,
167 void_ptr_iterator
<VoidIterU
,U
> r
)
170 return l
.base() - r
.base();
175 template< class VoidIterT
, class T
, class VoidIterU
, class U
>
176 inline bool operator==( const void_ptr_iterator
<VoidIterT
,T
>& l
,
177 const void_ptr_iterator
<VoidIterU
,U
>& r
)
179 return l
.base() == r
.base();
184 template< class VoidIterT
, class T
, class VoidIterU
, class U
>
185 inline bool operator!=( const void_ptr_iterator
<VoidIterT
,T
>& l
,
186 const void_ptr_iterator
<VoidIterU
,U
>& r
)
188 return l
.base() != r
.base();
193 template< class VoidIterT
, class T
, class VoidIterU
, class U
>
194 inline bool operator<( const void_ptr_iterator
<VoidIterT
,T
>& l
,
195 const void_ptr_iterator
<VoidIterU
,U
>& r
)
197 return l
.base() < r
.base();
202 template< class VoidIterT
, class T
, class VoidIterU
, class U
>
203 inline bool operator<=( const void_ptr_iterator
<VoidIterT
,T
>& l
,
204 const void_ptr_iterator
<VoidIterU
,U
>& r
)
206 return l
.base() <= r
.base();
211 template< class VoidIterT
, class T
, class VoidIterU
, class U
>
212 inline bool operator>( const void_ptr_iterator
<VoidIterT
,T
>& l
,
213 const void_ptr_iterator
<VoidIterU
,U
>& r
)
215 return l
.base() > r
.base();
220 template< class VoidIterT
, class T
, class VoidIterU
, class U
>
221 inline bool operator>=( const void_ptr_iterator
<VoidIterT
,T
>& l
,
222 const void_ptr_iterator
<VoidIterU
,U
>& r
)
224 return l
.base() >= r
.base();