#include #include #include #include #include // define the function object class iterate_a2m { public: typedef char result_type; iterate_a2m() : c_('A') {} iterate_a2m(char c) : c_(c) {} result_type operator()() { if (c_ == 'M') return eof; return c_++; } static result_type eof; private: char c_; }; iterate_a2m::result_type iterate_a2m::eof = iterate_a2m::result_type('M'); using namespace boost::spirit; // create two iterators using the define function object, one of which is // an end iterator typedef multi_pass > functor_multi_pass_t; int main() { functor_multi_pass_t first = functor_multi_pass_t(iterate_a2m()); functor_multi_pass_t last; // use the iterators: this will print "ABCDEFGHIJKL" while (first != last) { std::cout << *first; ++first; } std::cout << endl; }