1 #ifndef _theplu_yat_utility_weighted_iterator_
2 #define _theplu_yat_utility_weighted_iterator_
25 #include "DataWeight.h"
26 #include "DataWeightProxy.h"
28 #include <boost/iterator/is_readable_iterator.hpp>
29 #include <boost/iterator/iterator_facade.hpp>
30 #include <boost/mpl/and.hpp>
31 #include <boost/mpl/bool.hpp>
32 #include <boost/mpl/eval_if.hpp>
33 #include <boost/type_traits/is_convertible.hpp>
34 #include <boost/utility/enable_if.hpp>
43 namespace weighted_iterator {
51 template<
typename DataIterator,
typename WeightIterator>
54 typedef typename boost::iterator_traversal<DataIterator>::type T1;
55 typedef typename boost::iterator_traversal<WeightIterator>::type T2;
59 typedef typename boost::mpl::if_<
93 template<
typename DataIterator,
typename WeightIterator>
95 :
public boost::iterator_facade<
96 WeightedIterator<DataIterator, WeightIterator>,
99 detail::weighted_iterator::Traversal<DataIterator, WeightIterator>::type,
100 DataWeightProxy<DataIterator, WeightIterator> >
128 : d_iter_(d), w_iter_(w)
159 template<
typename D2,
typename W2>
161 typename boost::enable_if_convertible<D2,DataIterator>::type* = 0,
162 typename boost::enable_if_convertible<W2,WeightIterator>::type* = 0)
167 friend class boost::iterator_core_access;
172 void advance(
size_t n)
173 { std::advance(d_iter_, n); std::advance(w_iter_, n); }
175 void decrement(
void) { --d_iter_; --w_iter_; }
177 typename std::iterator_traits<DataIterator>::difference_type
179 {
return std::distance(d_iter_, other.d_iter_); }
181 utility::DataWeightProxy<DataIterator, WeightIterator>
182 dereference(
void)
const
183 {
return DataWeightProxy<DataIterator, WeightIterator>(d_iter_,
188 {
return d_iter_==other.d_iter_ && w_iter_==other.w_iter_; }
190 void increment(
void) { ++d_iter_; ++w_iter_; }
201 template<
typename DataIterator,
typename WeightIterator>
202 WeightedIterator<DataIterator, WeightIterator>
DataIterator data_iterator
DataIterator.
Definition: WeightedIterator.h:107
WeightedIterator.
Definition: WeightedIterator.h:94
DataWeightProxy< DataIterator, WeightIterator > operator[](int n) const
element operator
Definition: WeightedIterator.h:144
WeightedIterator< DataIterator, WeightIterator > weighted_iterator(DataIterator data, WeightIterator weight)
convenient function to create WeightedIterator
Definition: WeightedIterator.h:203
Definition: WeightedIterator.h:52
Proxy class for DataWeight.
Definition: DataWeightProxy.h:54
const DataIterator & data_base(void) const
Definition: WeightedIterator.h:134
DataIterator.
Definition: DataIterator.h:63
boost::mpl::if_< boost::is_convertible< T1, T2 >, T2, T1 >::type type
Definition: WeightedIterator.h:60
WeightedIterator(DataIterator d, WeightIterator w)
Constructor.
Definition: WeightedIterator.h:127
WeightIterator weight_iterator
DataIterator.
Definition: WeightedIterator.h:112
WeightIterator.
Definition: WeightIterator.h:64
const WeightIterator & weight_base(void) const
Definition: WeightedIterator.h:139
WeightedIterator(void)
Default Constructor.
Definition: WeightedIterator.h:121
WeightedIterator(WeightedIterator< D2, W2 > other, typename boost::enable_if_convertible< D2, DataIterator >::type *=0, typename boost::enable_if_convertible< W2, WeightIterator >::type *=0)
Conversion constructor.
Definition: WeightedIterator.h:160