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

source code of boost/libs/phoenix/test/scope/let_tests_113.cpp