]> git.lyx.org Git - lyx.git/blob - boost/boost/generator_iterator.hpp
complie fix
[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 #ifndef BOOST_ITERATOR_ADAPTOR_GENERATOR_ITERATOR_HPP
13 #define BOOST_ITERATOR_ADAPTOR_GENERATOR_ITERATOR_HPP
14
15 #include <boost/iterator_adaptors.hpp>
16 #include <boost/ref.hpp>
17
18 namespace boost {
19
20 template<class Generator>
21 class generator_iterator_policies
22 {
23 public:
24     generator_iterator_policies() { }
25
26     template<class Base>
27     void initialize(Base& base) {
28       m_value = (*base)();
29     }
30
31     // The Iter template argument is necessary for compatibility with a MWCW
32     // bug workaround
33     template <class IteratorAdaptor>
34     void increment(IteratorAdaptor& iter) {
35       m_value = (*iter.base())();
36     }
37
38     template <class IteratorAdaptor>
39     const typename Generator::result_type&
40     dereference(const IteratorAdaptor&) const
41         { return m_value; }
42
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; }
47
48 private:
49   typename Generator::result_type m_value;
50 };
51
52 template<class Generator>
53 struct generator_iterator_generator
54 {
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,
58     long>       type;
59 };
60
61 template <class Generator>
62 inline typename generator_iterator_generator<Generator>::type
63 make_generator_iterator(Generator & gen)
64 {
65   typedef typename generator_iterator_generator<Generator>::type result_t;
66   return result_t(&gen);
67 }
68
69 } // namespace boost
70
71
72 #endif // BOOST_ITERATOR_ADAPTOR_GENERATOR_ITERATOR_HPP
73