source: trunk/yat/utility/WeightIterator.h @ 1707

Last change on this file since 1707 was 1487, checked in by Jari Häkkinen, 13 years ago

Addresses #436. GPL license copy reference should also be updated.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.5 KB
Line 
1#ifndef _theplu_yat_utility_weight_iterator_
2#define _theplu_yat_utility_weight_iterator_
3
4// $Id: WeightIterator.h 1487 2008-09-10 08:41:36Z jari $
5
6/*
7  Copyright (C) 2008 Peter Johansson
8
9  This file is part of the yat library, http://dev.thep.lu.se/yat
10
11  The yat library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU General Public License as
13  published by the Free Software Foundation; either version 3 of the
14  License, or (at your option) any later version.
15
16  The yat library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20
21  You should have received a copy of the GNU General Public License
22  along with yat. If not, see <http://www.gnu.org/licenses/>.
23*/
24
25#include <boost/iterator/iterator_adaptor.hpp>
26#include <boost/type_traits/remove_reference.hpp>
27
28namespace theplu {
29namespace yat {
30namespace utility {
31
32  /**
33     @brief WeightIterator
34  */
35  template<typename Base>
36  class WeightIterator
37    : public boost::iterator_adaptor<
38    WeightIterator<Base>               // Derived
39    , Base                          // Base
40    , typename boost::remove_reference<typename iterator_traits<Base>::weight_reference>::type
41    , boost::forward_traversal_tag    // CategoryOrTraversal
42    , typename iterator_traits<Base>::weight_reference // Reference
43    >
44
45  {
46  public:
47    /**
48       \brief Constructor from \a Base iterator
49     */
50    explicit WeightIterator(Base b)
51      : WeightIterator::iterator_adaptor_(b) {}
52
53    /**
54       \brief Conversion constructor.
55
56       Create a WeightIterator<Base> from a
57       WeightIterator<B2>. Possible if B2 is convertible to a
58       Base. Constructor allows implicit conversions such as iterator
59       to const_iterator.
60     */
61    template<typename B2>
62    WeightIterator(WeightIterator<B2> other,
63                   typename boost::enable_if_convertible<B2, Base>::type* = 0 )
64      : WeightIterator::iterator_adaptor_(other.base()) {}
65
66    /**
67       using iterator_traits::data on Base iterator
68
69       \return data
70     */
71    typename iterator_traits<Base>::weight_reference operator*(void) const
72    { return iterator_traits<Base>().weight(this->base()); }
73
74  private:
75  };
76
77  /**
78     \brief convenient function to create WeightIterator
79
80     Convenient function in same fashion as std::make_pair.
81   */
82  template<typename Base>
83  WeightIterator<Base> weight_iterator(Base base)
84  {
85    return WeightIterator<Base>(base);
86  }
87 
88
89
90}}} // of namespace utility, yat, and theplu
91
92#endif
Note: See TracBrowser for help on using the repository browser.