]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/support/regression_multi_pass_functor.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / spirit / test / support / regression_multi_pass_functor.cpp
1 // Copyright (c) 2010 Larry Evans
2 //
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6 //Purpose:
7 // Demonstrate error in non-classic multi_pass iterator compilation.
8 //
9
10 #include <boost/spirit/home/qi.hpp>
11 #include <boost/spirit/home/support.hpp>
12 #include <boost/spirit/home/support/multi_pass.hpp>
13 #include <boost/spirit/home/support/iterators/detail/functor_input_policy.hpp>
14
15 #include <fstream>
16
17 //[iterate_a2m:
18 // copied from:
19 // http://www.boost.org/doc/libs/1_41_0/libs/spirit/doc/html/spirit/support/multi_pass.html
20
21 // define the function object
22 template<typename CharT=char>
23 class istreambuf_functor
24 {
25 public:
26 typedef
27 std::istreambuf_iterator<CharT>
28 buf_iterator_type;
29 typedef
30 typename buf_iterator_type::int_type
31 result_type;
32 static
33 result_type
34 eof;
35
36 istreambuf_functor(void)
37 : current_chr(eof)
38 {}
39
40 istreambuf_functor(std::ifstream& input)
41 : my_first(input)
42 , current_chr(eof)
43 {}
44
45 result_type operator()()
46 {
47 buf_iterator_type last;
48 if (my_first == last)
49 {
50 return eof;
51 }
52 current_chr=*my_first;
53 ++my_first;
54 return current_chr;
55 }
56
57 private:
58 buf_iterator_type my_first;
59 result_type current_chr;
60 };
61
62 template<typename CharT>
63 typename istreambuf_functor<CharT>::result_type
64 istreambuf_functor<CharT>::
65 eof
66 ( istreambuf_functor<CharT>::buf_iterator_type::traits_type::eof()
67 )
68 ;
69
70 //]iterate_a2m:
71
72 typedef istreambuf_functor<char> base_iterator_type;
73
74 typedef
75 boost::spirit::multi_pass
76 < base_iterator_type
77 , boost::spirit::iterator_policies::default_policy
78 < boost::spirit::iterator_policies::first_owner
79 , boost::spirit::iterator_policies::no_check
80 , boost::spirit::iterator_policies::functor_input
81 , boost::spirit::iterator_policies::split_std_deque
82 >
83 >
84 chr_iterator_type;
85
86 // ======================================================================
87 // Main
88 int main()
89 {
90 std::ifstream in("multi_pass.txt");
91
92 unsigned num_toks=0;
93 unsigned const max_toks=10;
94
95 base_iterator_type base_first(in);
96 chr_iterator_type chr_first(base_first);
97 chr_iterator_type chr_last;
98 for
99 (
100 ; (chr_first != chr_last && ++num_toks < max_toks)
101 ; ++chr_first
102 )
103 {
104 std::cout<<":num_toks="<<num_toks<<":chr="<<*chr_first<<"\n";
105 }
106 return 0;
107 }