yat  0.10.4pre
iterator_traits.h
1 #ifndef _theplu_yat_utility_iterator_traits_
2 #define _theplu_yat_utility_iterator_traits_
3 
4 // $Id: iterator_traits.h 2472 2011-04-12 20:58:28Z peter $
5 
6 /*
7  Copyright (C) 2007 Jari Häkkinen, Peter Johansson
8  Copyright (C) 2008 Jari Häkkinen, Peter Johansson, Markus Ringnér
9  Copyright (C) 2010, 2011 Peter Johansson
10 
11  This file is part of the yat library, http://dev.thep.lu.se/yat
12 
13  The yat library is free software; you can redistribute it and/or
14  modify it under the terms of the GNU General Public License as
15  published by the Free Software Foundation; either version 3 of the
16  License, or (at your option) any later version.
17 
18  The yat library is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  General Public License for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with yat. If not, see <http://www.gnu.org/licenses/>.
25 */
26 
27 #include "DataWeight.h"
28 
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>
35 
36 #include <iterator>
37 
38 namespace theplu {
39 namespace yat {
40 namespace utility {
41 
47 
55 
56 
57 namespace detail {
63  template <typename T, typename Enable = void>
69  };
70 
76  template <typename T>
77  struct weighted_iterator_traits_detail<T, typename boost::enable_if<typename boost::is_convertible<T, DataWeight> >::type > {
82  };
83 
84 } // namespace detail
85 
86 
94  template <class Iterator>
96  {
97  private:
98  typedef typename std::iterator_traits<Iterator>::value_type value;
99  public:
105  };
106 
107 
108 namespace detail {
116  template <class T1, class T2>
122  };
123 
130  template <>
136  };
137 } // namespace detail
138 
144  template <class T1, class T2>
146  private:
149  public:
152  };
153 
157  template <class T1, class T2, class T3>
159  private:
160  typedef typename weighted_if_any2<T1, T2>::type tmp;
162  public:
165  };
166 
167  namespace detail {
173  inline void
175  } // namespace detail
176 
182  template <class Iter>
186  }
187 
188 
189 namespace detail {
190 
200  typedef char yes;
207  typedef char (&no)[2];
216  yes has_mutable(double&);
224  template<typename T>
225  no has_mutable(const T&);
226 
234  template <class Iter>
236  {
238  static Iter iter;
240  static const bool value =
241  sizeof(has_mutable((*iter).data())) == sizeof(yes);
242  };
243 
244 
252  template <class Iter>
254  {
256  static Iter iter;
258  static const bool value =
259  sizeof(has_mutable((*iter).weight())) == sizeof(yes);
260  };
261 
262 
274  template<typename Iter>
275  struct is_weighted
276  : public boost::is_same<weighted_iterator_tag
277  , typename weighted_iterator_traits<Iter>::type>
278  {};
279 
285  template<typename Iter>
287  : public boost::is_same<unweighted_iterator_tag
288  , typename weighted_iterator_traits<Iter>::type>
289  {};
290 
291 
299  template <typename Iter, typename Enable = void>
304  typedef typename std::iterator_traits<Iter>::reference data_reference;
305 
309  typedef const double weight_reference;
310 
314  data_reference data(Iter iter) const { return *iter; }
315 
319  weight_reference weight(Iter iter) const { return 1.0; }
320  };
321 
326  template<bool>
329  typedef const double type;
330  };
331 
336  template<>
337  struct mutable_reference<true> {
339  typedef double& type;
340  };
341 
342 
348  // we need remove_reference because is_const seems to not work on const&
349  template <typename Iter>
351  typename boost::enable_if<is_weighted<Iter> >::type >
352  {
357  typedef
360 
365  typedef
368 
372  data_reference data(Iter iter) const { return (*iter).data(); }
373 
377  weight_reference weight(Iter iter) const { return (*iter).weight(); }
378  };
379 
380 } // namespace detail
381 
390  template <typename Iter>
392  private:
394  public:
405 
415 
419  data_reference data(Iter iter) const
420  { return traits().data(iter); }
421 
425  weight_reference weight(Iter iter) const
426  { return traits().weight(iter); }
427 
428  };
429 
430 }}} // of namespace utility, yat, and theplu
431 
432 #endif

Generated on Mon Nov 11 2013 09:41:44 for yat by  doxygen 1.8.1