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.
9 // 15 Nov 2001 Jens Maurer
12 // See http://www.boost.org/libs/utility/iterator_adaptors.htm for documentation.
14 #ifndef BOOST_ITERATOR_ADAPTOR_GENERATOR_ITERATOR_HPP
15 #define BOOST_ITERATOR_ADAPTOR_GENERATOR_ITERATOR_HPP
17 #include <boost/iterator/iterator_facade.hpp>
18 #include <boost/ref.hpp>
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&
31 typedef iterator_facade<
32 generator_iterator<Generator>
33 , typename Generator::result_type
34 , single_pass_traversal_tag
35 , typename Generator::result_type const&
39 generator_iterator() {}
40 generator_iterator(Generator* g) : m_g(g), m_value((*m_g)()) {}
47 const typename Generator::result_type&
53 bool equal(generator_iterator const& y) const
55 return this->m_g == y.m_g && this->m_value == y.m_value;
60 typename Generator::result_type m_value;
63 template<class Generator>
64 struct generator_iterator_generator
66 typedef generator_iterator<Generator> type;
69 template <class Generator>
70 inline generator_iterator<Generator>
71 make_generator_iterator(Generator & gen)
73 typedef generator_iterator<Generator> result_t;
74 return result_t(&gen);
80 #endif // BOOST_ITERATOR_ADAPTOR_GENERATOR_ITERATOR_HPP