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 #ifndef BOOST_ITERATOR_ADAPTOR_GENERATOR_ITERATOR_HPP
13 #define BOOST_ITERATOR_ADAPTOR_GENERATOR_ITERATOR_HPP
15 #include <boost/iterator_adaptors.hpp>
16 #include <boost/ref.hpp>
20 template<class Generator>
21 class generator_iterator_policies
24 generator_iterator_policies() { }
27 void initialize(Base& base) {
31 // The Iter template argument is necessary for compatibility with a MWCW
33 template <class IteratorAdaptor>
34 void increment(IteratorAdaptor& iter) {
35 m_value = (*iter.base())();
38 template <class IteratorAdaptor>
39 const typename Generator::result_type&
40 dereference(const IteratorAdaptor&) const
43 template <class IteratorAdaptor1, class IteratorAdaptor2>
44 bool equal(const IteratorAdaptor1& x, const IteratorAdaptor2& y) const
45 { return x.base() == y.base() &&
46 x.policies().m_value == y.policies().m_value; }
49 typename Generator::result_type m_value;
52 template<class Generator>
53 struct generator_iterator_generator
55 typedef iterator_adaptor<Generator*, generator_iterator_policies<Generator>,
56 typename Generator::result_type, const typename Generator::result_type&,
57 const typename Generator::result_type*, std::input_iterator_tag,
61 template <class Generator>
62 inline typename generator_iterator_generator<Generator>::type
63 make_generator_iterator(Generator & gen)
65 typedef typename generator_iterator_generator<Generator>::type result_t;
66 return result_t(&gen);
72 #endif // BOOST_ITERATOR_ADAPTOR_GENERATOR_ITERATOR_HPP