source: trunk/yat/utility/DataIterator.h @ 1376

Last change on this file since 1376 was 1376, checked in by Peter, 13 years ago

add WeightIterator? - fixes #369

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.1 KB
Line 
1#ifndef _theplu_yat_utility_data_iterator_
2#define _theplu_yat_utility_data_iterator_
3
4// $Id: DataIterator.h 1376 2008-07-16 19:32:20Z peter $
5
6/*
7  Copyright (C) 2008 Peter Johansson
8
9  This file is part of the yat library, http://trac.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 2 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 this program; if not, write to the Free Software
23  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24  02111-1307, USA.
25*/
26
27#include "iterator_traits.h"
28
29#include <boost/iterator/iterator_adaptor.hpp>
30#include <boost/type_traits/remove_reference.hpp>
31
32namespace theplu {
33namespace yat {
34namespace utility {
35
36  /**
37     @brief DataIterator
38  */
39  template<typename Base>
40  class DataIterator
41    : public boost::iterator_adaptor<
42    DataIterator<Base>               // Derived
43    , Base                          // Base
44    , boost::remove_reference<typename iterator_traits<Base>::data_reference> 
45    , boost::forward_traversal_tag    // CategoryOrTraversal
46    , typename iterator_traits<Base>::data_reference // Reference
47    >
48
49  {
50  public:
51    /**
52       \brief Constructor from \a Base iterator
53     */
54    explicit DataIterator(Base b)
55      : DataIterator::iterator_adaptor_(b) {}
56
57    /**
58       using iterator_traits::data on Base iterator
59
60       \return data
61     */
62    typename iterator_traits<Base>::data_reference operator*(void) const
63    { return iterator_traits<Base>().data(this->base()); }
64
65  private:
66  };
67
68  /**
69     \brief convenient function to create DataIterator
70
71     Convenient function in same fashion as std::make_pair.
72   */
73  template<typename Base>
74  DataIterator<Base> make_data_iterator(Base base)
75  {
76    return DataIterator<Base>(base);
77  }
78 
79
80
81}}} // of namespace utility, yat, and theplu
82
83#endif
Note: See TracBrowser for help on using the repository browser.