1 /*=============================================================================
2 Phoenix V1.2.1
3 Copyright (c) 2001-2003 Joel de Guzman
4
5 Use, modification and distribution is subject to the Boost Software
6 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 http://www.boost.org/LICENSE_1_0.txt)
8 ==============================================================================*/
9 #include <iostream>
10 #include <vector>
11 #include <list>
12 #include <algorithm>
13 #include <boost/detail/lightweight_test.hpp>
14
15 #define PHOENIX_LIMIT 15
16 #include <boost/spirit/include/phoenix1_primitives.hpp>
17 #include <boost/spirit/include/phoenix1_composite.hpp>
18 #include <boost/spirit/include/phoenix1_functions.hpp>
19 #include <boost/spirit/include/phoenix1_operators.hpp>
20 #include <boost/spirit/include/phoenix1_binders.hpp>
21 #include <boost/spirit/include/phoenix1_special_ops.hpp>
22
23 using namespace phoenix;
24 using namespace std;
25
26 ///////////////////////////////////////////////////////////////////////////////
27 struct print_ { // a typical STL style monomorphic functor
28
29 typedef void result_type;
operator ()print_30 void operator()(int n0) { cout << "got 1 arg " << n0 << " \n"; }
31 };
32
33 functor<print_> print = print_();
34
35 ///////////////////////////////////////////////////////////////////////////////
36 int
main()37 main()
38 {
39
40 ///////////////////////////////////////////////////////////////////////////////
41 //
42 // STL algorithms
43 //
44 ///////////////////////////////////////////////////////////////////////////////
45 vector<int> v;
46 v.push_back(1);
47 v.push_back(2);
48 v.push_back(3);
49 v.push_back(4);
50 v.push_back(5);
51
52 for_each(v.begin(), v.end(), arg1 *= 2);
53 for (int m = 0; m < 5; ++m, (cout << ','))
54 {
55 cout << v[m];
56 BOOST_TEST(v[m] == (m+1)*2);
57 }
58 cout << endl;
59
60 for_each(v.begin(), v.end(), print(arg1));
61
62 vector<int>::iterator it = find_if(v.begin(), v.end(), arg1 > 5);
63 if (it != v.end())
64 cout << *it << endl;
65
66 ///////////////////////////////////////////////////////////////////////////////
67 //
68 // STL iterators and containers
69 //
70 ///////////////////////////////////////////////////////////////////////////////
71
72 BOOST_TEST((arg1[0])(v) == v[0]);
73 BOOST_TEST((arg1[1])(v) == v[1]);
74
75 list<int> l;
76 l.push_back(1);
77 l.push_back(2);
78 l.push_back(3);
79 l.push_back(4);
80 l.push_back(5);
81
82 list<int>::iterator first = l.begin();
83 list<int>::iterator last = l.end();
84
85 BOOST_TEST((*(++arg1))(first) == 2);
86 BOOST_TEST((*(----arg1))(last) == 4);
87
88 ///////////////////////////////////////////////////////////////////////////////
89 //
90 // End asserts
91 //
92 ///////////////////////////////////////////////////////////////////////////////
93
94 return boost::report_errors();
95 }
96