1 #ifndef _theplu_yat_utility_iterator_traits_
2 #define _theplu_yat_utility_iterator_traits_
27 #include "DataWeight.h"
29 #include <boost/mpl/logical.hpp>
30 #include <boost/type_traits/is_const.hpp>
31 #include <boost/type_traits/is_convertible.hpp>
32 #include <boost/type_traits/is_same.hpp>
33 #include <boost/type_traits/remove_reference.hpp>
34 #include <boost/utility/enable_if.hpp>
65 template <
typename T,
typename Enable =
void>
66 struct weighted_iterator_traits_detail {
79 struct weighted_iterator_traits_detail<T, typename boost::enable_if<typename boost::is_convertible<T, DataWeight> >::type > {
83 typedef weighted_iterator_tag type;
98 template <
class Iterator>
102 typedef typename std::iterator_traits<Iterator>::value_type value;
108 typedef typename detail::weighted_iterator_traits_detail<value>::type
type;
121 template <
class T1,
class T2>
122 struct unweighted_type_and {
136 struct unweighted_type_and<unweighted_iterator_tag, unweighted_iterator_tag> {
140 typedef unweighted_iterator_tag type;
152 template <
class T1,
class T2>
159 typedef typename detail::unweighted_type_and<w_type1, w_type2>::type
type;
165 template <
class T1,
class T2,
class T3>
172 typedef typename detail::unweighted_type_and<tmp, w_type3>::type
type;
193 template <
class Iter>
195 { detail::check_iterator_is_unweighted(
typename
219 typedef char (&no)[2];
228 yes has_mutable(
double&);
237 no has_mutable(
const T&);
246 template <
class Iter>
247 struct iter_has_mutable_data
252 static const bool value =
253 sizeof(has_mutable((*iter).data())) ==
sizeof(yes);
264 template <
class Iter>
265 struct iter_has_mutable_weight
270 static const bool value =
271 sizeof(has_mutable((*iter).weight())) ==
sizeof(yes);
286 template<
typename Iter>
288 :
public boost::is_same<weighted_iterator_tag
289 , typename weighted_iterator_traits<Iter>::type>
297 template<
typename Iter>
299 :
public boost::is_same<unweighted_iterator_tag
300 , typename weighted_iterator_traits<Iter>::type>
311 template <
typename Iter,
typename Enable =
void>
312 struct iterator_traits_detail {
316 typedef typename std::iterator_traits<Iter>::reference data_reference;
321 typedef const double weight_reference;
326 data_reference data(Iter iter)
const {
return *iter; }
331 weight_reference weight(Iter iter)
const {
return 1.0; }
339 struct mutable_reference {
341 typedef const double type;
349 struct mutable_reference<true> {
351 typedef double& type;
361 template <
typename Iter>
362 struct iterator_traits_detail<Iter,
363 typename boost::enable_if<is_weighted<Iter> >::type >
370 typename mutable_reference<iter_has_mutable_data<Iter>::value>::type
378 typename mutable_reference<iter_has_mutable_weight<Iter>::value>::type
384 data_reference data(Iter iter)
const {
return (*iter).data(); }
389 weight_reference weight(Iter iter)
const {
return (*iter).weight(); }
405 template <
typename Iter>
408 typedef detail::iterator_traits_detail<Iter> traits;
435 {
return traits().data(iter); }
441 {
return traits().weight(iter); }
detail::weighted_iterator_traits_detail< value >::type type
Definition: iterator_traits.h:108
data_reference data(Iter iter) const
Definition: iterator_traits.h:434
Definition: iterator_traits.h:406
Definition: iterator_traits.h:46
Definition: iterator_traits.h:54
Definition: iterator_traits.h:99
void check_iterator_is_unweighted(Iter iter)
check (at compile time) that iterator is unweighted.
Definition: iterator_traits.h:194
traits::data_reference data_reference
Definition: iterator_traits.h:419
Definition: iterator_traits.h:166
traits::weight_reference weight_reference
Definition: iterator_traits.h:429
detail::unweighted_type_and< tmp, w_type3 >::type type
return unweighted if all are unweighted
Definition: iterator_traits.h:172
weight_reference weight(Iter iter) const
Definition: iterator_traits.h:440
detail::unweighted_type_and< w_type1, w_type2 >::type type
return unweighted if both are unweighted
Definition: iterator_traits.h:159
Definition: iterator_traits.h:153