fix doc example typo
[boost.git] / boost / ptr_container / detail / void_ptr_iterator.hpp
blob937ffb4aa21e19da85e09cb3708d58ed87680215
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/
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)
16 # pragma once
17 #endif
19 #include <boost/config.hpp>
20 #include <boost/iterator/iterator_traits.hpp>
21 #include <boost/type_traits/remove_const.hpp>
23 namespace boost
25 template
27 class VoidIter,
28 class T
30 class void_ptr_iterator
32 public:
33 typedef BOOST_DEDUCED_TYPENAME boost::remove_const<T>::type
34 value_type;
35 typedef T& reference;
36 typedef T* pointer;
38 typedef BOOST_DEDUCED_TYPENAME iterator_difference<VoidIter>::type
39 difference_type;
40 typedef BOOST_DEDUCED_TYPENAME iterator_category<VoidIter>::type
41 iterator_category;
42 private:
44 VoidIter iter_;
46 public:
47 void_ptr_iterator() : iter_()
48 { }
50 void_ptr_iterator( VoidIter r ) : iter_(r)
51 { }
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())) )
60 #else
62 : iter_(r.base())
63 #endif
64 { }
66 T& operator*() const
68 return *static_cast<T*>( *iter_ );
71 T* operator->() const
73 return static_cast<T*>( *iter_ );
76 void_ptr_iterator& operator++()
78 ++iter_;
79 return *this;
82 void_ptr_iterator operator++(int)
84 void_ptr_iterator res = *this;
85 ++iter_;
86 return res;
89 void_ptr_iterator& operator--()
91 --iter_;
92 return *this;
95 void_ptr_iterator operator--(int)
97 void_ptr_iterator res = *this;
98 --iter_;
99 return res;
102 void_ptr_iterator& operator+=( difference_type n )
104 iter_ += n;
105 return *this;
108 void_ptr_iterator& operator-=( difference_type n )
110 iter_ -= n;
111 return *this;
114 T& operator[]( difference_type n ) const
116 return *static_cast<T*>( *(iter_ + n) );
119 VoidIter base() const
121 return iter_;
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 )
131 l += n;
132 return l;
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 )
141 r += n;
142 return 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 )
150 l -= n;
151 return l;
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 )
160 r -= n;
161 return 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();
229 #endif