| 1 | #include <iostream>
|
|---|
| 2 |
|
|---|
| 3 | #include <boost/spirit/home/qi.hpp>
|
|---|
| 4 | #include <boost/spirit/home/support.hpp>
|
|---|
| 5 | #include <boost/spirit/home/support/multi_pass.hpp>
|
|---|
| 6 | #include <boost/spirit/home/support/iterators/detail/functor_input_policy.hpp>
|
|---|
| 7 |
|
|---|
| 8 | // define the function object
|
|---|
| 9 | class iterate_a2m
|
|---|
| 10 | {
|
|---|
| 11 | public:
|
|---|
| 12 | typedef char result_type;
|
|---|
| 13 |
|
|---|
| 14 | iterate_a2m() : c_('A') {}
|
|---|
| 15 | iterate_a2m(char c) : c_(c) {}
|
|---|
| 16 |
|
|---|
| 17 | result_type operator()()
|
|---|
| 18 | {
|
|---|
| 19 | if (c_ == 'M')
|
|---|
| 20 | return eof;
|
|---|
| 21 | return c_++;
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 | static result_type eof;
|
|---|
| 25 |
|
|---|
| 26 | private:
|
|---|
| 27 | char c_;
|
|---|
| 28 | };
|
|---|
| 29 |
|
|---|
| 30 | iterate_a2m::result_type iterate_a2m::eof = iterate_a2m::result_type('M');
|
|---|
| 31 |
|
|---|
| 32 | using namespace boost::spirit;
|
|---|
| 33 |
|
|---|
| 34 | // create two iterators using the define function object, one of which is
|
|---|
| 35 | // an end iterator
|
|---|
| 36 | typedef multi_pass<iterate_a2m
|
|---|
| 37 | , iterator_policies::default_policy<
|
|---|
| 38 | iterator_policies::first_owner
|
|---|
| 39 | , iterator_policies::no_check
|
|---|
| 40 | , iterator_policies::functor_input
|
|---|
| 41 | , iterator_policies::split_std_deque> >
|
|---|
| 42 | functor_multi_pass_t;
|
|---|
| 43 |
|
|---|
| 44 | int main() {
|
|---|
| 45 |
|
|---|
| 46 | functor_multi_pass_t first = functor_multi_pass_t(iterate_a2m());
|
|---|
| 47 | functor_multi_pass_t last;
|
|---|
| 48 |
|
|---|
| 49 | // use the iterators: this will print "ABCDEFGHIJKL"
|
|---|
| 50 | while (first != last) {
|
|---|
| 51 | std::cout << *first;
|
|---|
| 52 | ++first;
|
|---|
| 53 | }
|
|---|
| 54 | std::cout << endl;
|
|---|
| 55 | }
|
|---|