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

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

making types in DataIterator? more generic - refs #369

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.1 KB
RevLine 
[1365]1#ifndef _theplu_yat_utility_data_iterator_
2#define _theplu_yat_utility_data_iterator_
[1363]3
4// $Id: DataIterator.h 1375 2008-07-16 17:51:54Z 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
[1365]27#include <boost/iterator/iterator_adaptor.hpp>
[1375]28#include <boost/type_traits/remove_reference.hpp>
[1363]29
30namespace theplu {
31namespace yat {
32namespace utility {
33
34  /**
[1365]35     @brief DataIterator
[1363]36  */
[1365]37  template<typename Base>
38  class DataIterator
39    : public boost::iterator_adaptor<
40    DataIterator<Base>               // Derived
41    , Base                          // Base
[1375]42    , boost::remove_reference<typename iterator_traits<Base>::data_reference> 
[1365]43    , boost::forward_traversal_tag    // CategoryOrTraversal
[1375]44    , typename iterator_traits<Base>::data_reference // Reference
[1365]45    >
46
[1363]47  {
48  public:
[1366]49    /**
50       \brief Constructor from \a Base iterator
51     */
[1365]52    explicit DataIterator(Base b)
53      : DataIterator::iterator_adaptor_(b) {}
[1363]54
[1366]55    /**
56       using iterator_traits::data on Base iterator
57
58       \return data
59     */
[1375]60    typename iterator_traits<Base>::data_reference operator*(void) const
[1365]61    { return iterator_traits<Base>().data(this->base()); }
62
[1363]63  private:
64  };
65
[1365]66  /**
67     \brief convenient function to create DataIterator
[1363]68
[1365]69     Convenient function in same fashion as std::make_pair.
70   */
71  template<typename Base>
72  DataIterator<Base> make_data_iterator(Base base)
73  {
74    return DataIterator<Base>(base);
75  }
76 
[1363]77
[1365]78
[1363]79}}} // of namespace utility, yat, and theplu
80
81#endif
Note: See TracBrowser for help on using the repository browser.