34 #ifndef __INDEX_BASED_ITERATOR__ 35 #define __INDEX_BASED_ITERATOR__ 37 #include <boost/iterator/iterator_facade.hpp> 38 #include <boost/type_traits.hpp> 40 # ifndef BOOST_NO_SFINAE 41 # include <boost/type_traits/is_convertible.hpp> 42 # include <boost/utility/enable_if.hpp> 54 template<
class T,
typename R>
56 public boost::iterator_facade<
57 index_based_iterator<T, R>,
59 boost::random_access_traversal_tag>
62 struct conversion_enabler {};
65 typedef typename T::difference_type difference_type;
68 : fContainer(nil), fPos(0)
72 : fContainer(&storage), fPos(pos)
77 template<
typename OtherValue>
79 typename boost::enable_if<boost::is_convertible<OtherValue*, R*>, conversion_enabler>::type = conversion_enabler() )
80 : fContainer(other.fContainer), fPos(other.fPos)
91 return fContainer && fPos >=0 && fPos <= (difference_type)fContainer->size();
95 T
const* get_container()
const 103 difference_type fPos;
108 friend class boost::iterator_core_access;
127 void advance(difference_type n)
136 template<
typename OtherValue>
139 ASSERT(fContainer == rhs.fContainer);
140 return rhs.fPos - fPos;
143 template<
typename OtherValue>
146 ASSERT(fContainer == rhs.fContainer);
147 return fPos == rhs.fPos;
150 template <
bool>
class Selector {};
153 R& dereference()
const 155 ASSERT(fContainer && fPos >=0 && fPos < (difference_type)fContainer->size());
156 return dereference_impl(Selector<boost::is_const<R>::value>());
160 R& dereference_impl(Selector<false>)
const 162 return const_cast<T&
>(*fContainer).get_ref(fPos);
166 R& dereference_impl(Selector<true>)
const 168 return fContainer->get_const_ref(fPos);
172 #endif // __INDEX_BASED_ITERATOR__