]> git.lyx.org Git - lyx.git/blob - boost/boost/generator_iterator.hpp
fix reading the author field.
[lyx.git] / boost / boost / generator_iterator.hpp
1 // (C) Copyright Jens Maurer 2001. Permission to copy, use,
2 // modify, sell and distribute this software is granted provided this
3 // copyright notice appears in all copies. This software is provided
4 // "as is" without express or implied warranty, and with no claim as
5 // to its suitability for any purpose.
6 //
7 // Revision History:
8
9 // 15 Nov 2001   Jens Maurer
10 //      created.
11
12 //  See http://www.boost.org/libs/utility/iterator_adaptors.htm for documentation.
13
14 #ifndef BOOST_ITERATOR_ADAPTOR_GENERATOR_ITERATOR_HPP
15 #define BOOST_ITERATOR_ADAPTOR_GENERATOR_ITERATOR_HPP
16
17 #include <boost/iterator/iterator_facade.hpp>
18 #include <boost/ref.hpp>
19
20 namespace boost {
21
22 template<class Generator>
23 class generator_iterator
24   : public iterator_facade<
25         generator_iterator<Generator>
26       , typename Generator::result_type
27       , single_pass_traversal_tag
28       , typename Generator::result_type const&
29     >
30 {
31     typedef iterator_facade<
32         generator_iterator<Generator>
33       , typename Generator::result_type
34       , single_pass_traversal_tag
35       , typename Generator::result_type const&
36     > super_t;
37     
38  public:
39     generator_iterator() {}
40     generator_iterator(Generator* g) : m_g(g), m_value((*m_g)()) {}
41
42     void increment()
43     {
44         m_value = (*m_g)();
45     }
46
47     const typename Generator::result_type&
48     dereference() const
49     {
50         return m_value;
51     }
52
53     bool equal(generator_iterator const& y) const
54     {
55         return this->m_g == y.m_g && this->m_value == y.m_value;
56     }
57
58  private:
59     Generator* m_g;
60     typename Generator::result_type m_value;
61 };
62
63 template<class Generator>
64 struct generator_iterator_generator
65 {
66   typedef generator_iterator<Generator> type;
67 };
68
69 template <class Generator>
70 inline generator_iterator<Generator>
71 make_generator_iterator(Generator & gen)
72 {
73   typedef generator_iterator<Generator> result_t;
74   return result_t(&gen);
75 }
76
77 } // namespace boost
78
79
80 #endif // BOOST_ITERATOR_ADAPTOR_GENERATOR_ITERATOR_HPP
81