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 <cmath>
9 #include <algorithm>
10 #include <vector>
11 
12 #include <boost/phoenix/core/limits.hpp>
13 
14 #include <boost/detail/lightweight_test.hpp>
15 #include <boost/fusion/tuple.hpp>
16 #include <boost/phoenix/core.hpp>
17 #include <boost/phoenix/operator.hpp>
18 #include <boost/phoenix/function.hpp>
19 #include <boost/phoenix/fusion.hpp>
20 #include <boost/phoenix/scope.hpp>
21 
22 #include <typeinfo>
23 
24 namespace fusion = boost::fusion;
25 namespace mpl = boost::mpl;
26 
27 int
main()28 main()
29 {
30     using boost::phoenix::let;
31     using boost::phoenix::val;
32     using boost::phoenix::arg_names::_1;
33     using boost::phoenix::arg_names::_2;
34     //using boost::phoenix::arg_names::_3;
35     using boost::phoenix::local_names::_a;
36     using boost::phoenix::local_names::_b;
37     //using boost::phoenix::local_names::_c;
38     //using boost::phoenix::local_names::_d;
39     //using boost::phoenix::local_names::_e;
40     //using boost::phoenix::local_names::_x;
41     //using boost::phoenix::local_names::_y;
42     //using boost::phoenix::local_names::_z;
43     //using boost::phoenix::placeholders::arg1;
44     /*
45     {
46         int x = 1;
47         BOOST_TEST(
48             let(_a = _1)
49             [
50                 _a
51             ]
52             (x) == x
53         )
54         ;
55     }
56 
57     {
58         int x = 1, y = 10;
59         BOOST_TEST(
60             let(_a = _1, _b = _2)
61             [
62                 _a + _b
63             ]
64             (x, y) == x + y
65         );
66     }
67 
68     {
69         int x = 1, y = 10, z = 13;
70         BOOST_TEST(
71             let(_x = _1, _y = _2)
72             [
73                 let(_z = _3)
74                 [
75                     _x + _y + _z
76                 ]
77             ]
78             (x, y, z) == x + y + z
79         );
80     }
81 
82     {
83         int x = 1, y = 10;
84         BOOST_TEST(
85             let(_x = _1)
86             [
87                 _x +
88                     let(_x = _2)
89                     [
90                         -_x
91                     ]
92             ]
93             (x, y) == x + -y
94         );
95     }
96 
97     {
98         int x = 999;
99         BOOST_TEST(
100             let(_x = _1) // _x is a reference to x
101             [
102                 _x += 888
103             ]
104             (x) == 999 + 888
105         );
106 
107         BOOST_TEST(x == 888 + 999);
108     }
109 
110     {
111         int x = 999;
112 
113         BOOST_TEST(
114             let(_x = val(_1)) // _x holds x by value
115             [
116                 _x += 888
117             ]
118             (x) == x + 888
119         );
120 
121         BOOST_TEST(x == 999);
122 
123         BOOST_TEST(
124             let(_x = val(_1)) // _x holds x by value
125             [
126                 val(_x += 888)
127             ]
128             (x) == x + 888
129         );
130 
131         BOOST_TEST(x == 999);
132     }
133 
134     {
135         BOOST_TEST(
136             let(_a = 1, _b = 2, _c = 3, _d = 4, _e = 5)
137             [
138                 _a + _b + _c + _d + _e
139             ]
140             () == 1 + 2 + 3 + 4 + 5
141         );
142     }
143 
144 #ifdef PHOENIX_SHOULD_NOT_COMPILE_TEST
145     {
146         // disallow this:
147         int i;
148         (_a + _b)(i);
149     }
150 #endif
151     */
152     {
153         // show that we can return a local from an outer scope
154         int y = 0;
155 #if defined(__OPTIMIZE__) && __OPTIMIZE__
156         int x = (let(_a = _2)[let(_b = _1)[ _a ]])(y,1);
157 #else
158         int x = (let(_a = 1)[let(_b = _1)[ _a ]])(y);
159 #endif
160         BOOST_TEST(x == 1);
161     }
162     /*
163     {
164         // show that this code returns an lvalue
165         int i = 1;
166         let(_a = arg1)[ _a ](i)++;
167         BOOST_TEST(i == 2);
168     }
169 
170     {
171         // show that what you put in is what you get out
172         int i = 1;
173         int& j = let(_a = arg1)[_a](i);
174         BOOST_TEST(&i == &j);
175     }
176 
177     {
178         using boost::phoenix::at_c;
179 
180         boost::fusion::tuple<int, int> t = boost::fusion::make_tuple(0, 1);
181         int i = let(_a = at_c<0>(_1))[_a](t);
182 
183         BOOST_TEST( i == 0 );
184     }
185 
186     {
187         int i = 0;
188         let(_a = _1)[_a = _2](i, 2);
189         BOOST_TEST(i == 2);
190     }
191     */
192     return boost::report_errors();
193 }
194 
195