1 #ifndef _theplu_yat_utility_iterator_traits_
2 #define _theplu_yat_utility_iterator_traits_
27 #include "DataWeight.h"
29 #include <boost/iterator/iterator_traits.hpp>
30 #include <boost/mpl/logical.hpp>
31 #include <boost/type_traits/is_const.hpp>
32 #include <boost/type_traits/is_convertible.hpp>
33 #include <boost/type_traits/is_same.hpp>
34 #include <boost/type_traits/remove_reference.hpp>
35 #include <boost/utility/enable_if.hpp>
66 template <
typename T,
typename Enable =
void>
67 struct weighted_iterator_traits_detail {
80 struct weighted_iterator_traits_detail<T, typename boost::enable_if<typename boost::is_convertible<T, DataWeight> >::type > {
84 typedef weighted_iterator_tag type;
104 template <
class Iterator>
108 typedef typename boost::iterator_value<Iterator>::type value;
114 typedef typename detail::weighted_iterator_traits_detail<value>::type
type;
127 template <
class T1,
class T2>
128 struct unweighted_type_and {
142 struct unweighted_type_and<unweighted_iterator_tag, unweighted_iterator_tag> {
146 typedef unweighted_iterator_tag type;
158 template <
class T1,
class T2>
165 typedef typename detail::unweighted_type_and<w_type1, w_type2>::type
type;
171 template <
class T1,
class T2,
class T3>
178 typedef typename detail::unweighted_type_and<tmp, w_type3>::type
type;
199 template <
class Iter>
201 { detail::check_iterator_is_unweighted(
typename
225 typedef char (&no)[2];
234 yes has_mutable(
double&);
243 no has_mutable(
const T&);
252 template <
class Iter>
253 struct iter_has_mutable_data
258 static const bool value =
259 sizeof(has_mutable((*iter).data())) ==
sizeof(yes);
270 template <
class Iter>
271 struct iter_has_mutable_weight
276 static const bool value =
277 sizeof(has_mutable((*iter).weight())) ==
sizeof(yes);
292 template<
typename Iter>
294 :
public boost::is_same<weighted_iterator_tag
295 , typename weighted_iterator_traits<Iter>::type>
303 template<
typename Iter>
305 :
public boost::is_same<unweighted_iterator_tag
306 , typename weighted_iterator_traits<Iter>::type>
317 template <
typename Iter,
typename Enable =
void>
318 struct iterator_traits_detail {
322 typedef typename std::iterator_traits<Iter>::reference data_reference;
327 typedef const double weight_reference;
332 data_reference data(Iter iter)
const {
return *iter; }
337 weight_reference weight(Iter iter)
const {
return 1.0; }
345 struct mutable_reference {
347 typedef const double type;
355 struct mutable_reference<true> {
357 typedef double& type;
367 template <
typename Iter>
368 struct iterator_traits_detail<Iter,
369 typename boost::enable_if<is_weighted<Iter> >::type >
376 typename mutable_reference<iter_has_mutable_data<Iter>::value>::type
384 typename mutable_reference<iter_has_mutable_weight<Iter>::value>::type
390 data_reference data(Iter iter)
const {
return (*iter).data(); }
395 weight_reference weight(Iter iter)
const {
return (*iter).weight(); }
411 template <
typename Iter>
414 typedef detail::iterator_traits_detail<Iter> traits;
441 {
return traits().data(iter); }
447 {
return traits().weight(iter); }
detail::weighted_iterator_traits_detail< value >::type type
Definition: iterator_traits.h:114
data_reference data(Iter iter) const
Definition: iterator_traits.h:440
Definition: iterator_traits.h:412
Definition: iterator_traits.h:47
Definition: iterator_traits.h:55
Definition: iterator_traits.h:105
void check_iterator_is_unweighted(Iter iter)
check (at compile time) that iterator is unweighted.
Definition: iterator_traits.h:200
traits::data_reference data_reference
Definition: iterator_traits.h:425
Definition: iterator_traits.h:172
traits::weight_reference weight_reference
Definition: iterator_traits.h:435
detail::unweighted_type_and< tmp, w_type3 >::type type
return unweighted if all are unweighted
Definition: iterator_traits.h:178
weight_reference weight(Iter iter) const
Definition: iterator_traits.h:446
detail::unweighted_type_and< w_type1, w_type2 >::type type
return unweighted if both are unweighted
Definition: iterator_traits.h:165
Definition: iterator_traits.h:159