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