• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <vector>
10 #include <algorithm>
11 #include <iostream>
12 #include <cassert>
13 
14 #define PHOENIX_LIMIT 15
15 #include <boost/spirit/include/phoenix1_operators.hpp>
16 #include <boost/spirit/include/phoenix1_primitives.hpp>
17 #include <boost/spirit/include/phoenix1_composite.hpp>
18 #include <boost/spirit/include/phoenix1_special_ops.hpp>
19 #include <boost/spirit/include/phoenix1_statements.hpp>
20 #include <boost/spirit/include/phoenix1_functions.hpp>
21 #include <boost/spirit/include/phoenix1_closures.hpp>
22 
23 //////////////////////////////////
24 using namespace phoenix;
25 
26 //////////////////////////////////
27 int
main()28 main()
29 {
30     struct my_closure : closure<int, std::string, double> {
31 
32         member1 num;
33         member2 message;
34         member3 real;
35     };
36 
37     my_closure clos;
38 
39     {   //  First stack frame
40         closure_frame<my_closure::self_t> frame(clos);
41         (clos.num = 123)();
42         (clos.num += 456)();
43         (clos.real = clos.num / 56.5)();
44         (clos.message = "Hello " + std::string("World "))();
45 
46         {   //  Second stack frame
47             closure_frame<my_closure::self_t> frame(clos);
48             (clos.num = 987)();
49             (clos.message = "Abracadabra ")();
50             (clos.real = clos.num * 1e30)();
51 
52             {   //  Third stack frame
53                 tuple<int, char const*, double> init(-1, "Direct Init ", 3.14);
54                 closure_frame<my_closure::self_t> frame(clos, init);
55 
56                 (std::cout << clos.message << clos.num << ", " << clos.real << '\n')();
57             }
58 
59             (std::cout << clos.message << clos.num << ", " << clos.real << '\n')();
60         }
61 
62         (std::cout << clos.message << clos.num << ", " << clos.real << '\n')();
63     }
64 
65     return 0;
66 }
67