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_adaptors.hpp>
18 #include <boost/ref.hpp>
22 template<class Generator>
23 class generator_iterator_policies
26 generator_iterator_policies() { }
29 void initialize(Base& base) {
33 // The Iter template argument is necessary for compatibility with a MWCW
35 template <class IteratorAdaptor>
36 void increment(IteratorAdaptor& iter) {
37 m_value = (*iter.base())();
40 template <class IteratorAdaptor>
41 const typename Generator::result_type&
42 dereference(const IteratorAdaptor&) const
45 template <class IteratorAdaptor1, class IteratorAdaptor2>
46 bool equal(const IteratorAdaptor1& x, const IteratorAdaptor2& y) const
47 { return x.base() == y.base() &&
48 x.policies().m_value == y.policies().m_value; }
51 typename Generator::result_type m_value;
54 template<class Generator>
55 struct generator_iterator_generator
57 typedef iterator_adaptor<Generator*, generator_iterator_policies<Generator>,
58 typename Generator::result_type, const typename Generator::result_type&,
59 const typename Generator::result_type*, std::input_iterator_tag,
63 template <class Generator>
64 inline typename generator_iterator_generator<Generator>::type
65 make_generator_iterator(Generator & gen)
67 typedef typename generator_iterator_generator<Generator>::type result_t;
68 return result_t(&gen);
74 #endif // BOOST_ITERATOR_ADAPTOR_GENERATOR_ITERATOR_HPP