1 /*=============================================================================
2 Copyright (c) 2001-2007 Joel de Guzman
3
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 ==============================================================================*/
7 #include <iostream>
8 #include <vector>
9 #include <algorithm>
10 #include <boost/detail/lightweight_test.hpp>
11 #include <boost/phoenix/core.hpp>
12 #include <boost/phoenix/statement.hpp>
13 #include <boost/phoenix/operator.hpp>
14
15 int
main()16 main()
17 {
18 using boost::phoenix::arg_names::arg1;
19 using boost::phoenix::do_;
20 using boost::phoenix::ref;
21 using boost::phoenix::val;
22
23 using std::cout;
24 using std::endl;
25 using std::for_each;
26 using std::vector;
27
28 int init[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
29 vector<int> v(init, init+10);
30 vector<int> t = v;
31 cout << endl;
32 int x = 0;
33
34 for_each(v.begin(), v.end(),
35 (
36 while_(arg1--)
37 [
38 cout << arg1 << ", ",
39 ++ref(x)
40 ],
41 cout << val("\n")
42 )
43 );
44
45 BOOST_TEST(x == 1+2+3+4+5+6+7+8+9+10);
46 cout << endl;
47 v = t;
48 x = 0;
49
50 for_each(v.begin(), v.end(),
51 (
52 do_
53 [
54 cout << arg1 << ", ",
55 ++ref(x)
56 ]
57 .while_(arg1--),
58 cout << val("\n")
59 )
60 );
61
62 BOOST_TEST(x == 2+3+4+5+6+7+8+9+10+11);
63 cout << endl;
64 v = t;
65 x = 0;
66
67 int iii;
68 for_each(v.begin(), v.end(),
69 (
70 for_(ref(iii) = 0, ref(iii) < arg1, ++ref(iii))
71 [
72 cout << arg1 << ", ",
73 ++ref(x)
74 ],
75 cout << val("\n")
76 )
77 );
78
79 BOOST_TEST(x == 1+2+3+4+5+6+7+8+9+10);
80 cout << endl;
81 v = t;
82 x = 0;
83
84 return boost::report_errors();
85 }
86