1 // Copyright (C) 2016-2018 T. Zachary Laine
2 //
3 // Distributed under the Boost Software License, Version 1.0. (See
4 // accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 #include <boost/yap/expression.hpp>
7
8
9 template<typename T>
10 using term = boost::yap::terminal<boost::yap::expression, T>;
11
12 template<typename T>
13 using ref = boost::yap::expression_ref<boost::yap::expression, T>;
14
15 namespace yap = boost::yap;
16 namespace bh = boost::hana;
17
18
compile_term_plus_expr()19 void compile_term_plus_expr()
20 {
21 // values
22 {
23 term<double> unity{1.0};
24 term<int> i = {1};
25 yap::expression<
26 yap::expr_kind::plus,
27 bh::tuple<ref<term<double> &>, ref<term<int> &>>>
28 expr = unity + i;
29 yap::expression<
30 yap::expr_kind::plus,
31 bh::tuple<
32 ref<term<double> &>,
33 ref<yap::expression<
34 yap::expr_kind::plus,
35 bh::tuple<ref<term<double> &>, ref<term<int> &>>> &>>>
36 unevaluated_expr = unity + expr;
37 (void)unevaluated_expr;
38 }
39
40 {
41 term<double> unity{1.0};
42 term<int const> i = {1};
43 yap::expression<
44 yap::expr_kind::plus,
45 bh::tuple<ref<term<double> &>, ref<term<int const> &>>>
46 expr = unity + i;
47 yap::expression<
48 yap::expr_kind::plus,
49 bh::tuple<
50 ref<term<double> &>,
51 ref<yap::expression<
52 yap::expr_kind::plus,
53 bh::tuple<ref<term<double> &>, ref<term<int const> &>>> &>>>
54 unevaluated_expr = unity + expr;
55 (void)unevaluated_expr;
56 }
57
58 {
59 term<double> unity{1.0};
60 term<int> i = {1};
61 yap::expression<
62 yap::expr_kind::plus,
63 bh::tuple<ref<term<double> &>, term<int>>>
64 expr = unity + std::move(i);
65 yap::expression<
66 yap::expr_kind::plus,
67 bh::tuple<
68 ref<term<double> &>,
69 ref<yap::expression<
70 yap::expr_kind::plus,
71 bh::tuple<ref<term<double> &>, term<int>>> &>>>
72 unevaluated_expr = unity + expr;
73 (void)unevaluated_expr;
74 }
75
76 // const value terminals/expressions
77 {
78 term<double> unity{1.0};
79 term<int> const i = {1};
80 yap::expression<
81 yap::expr_kind::plus,
82 bh::tuple<ref<term<double> &>, ref<term<int> const &>>> const expr =
83 unity + i;
84 yap::expression<
85 yap::expr_kind::plus,
86 bh::tuple<
87 ref<term<double> &>,
88 ref<yap::expression<
89 yap::expr_kind::plus,
90 bh::tuple<
91 ref<term<double> &>,
92 ref<term<int> const &>>> const &>>>
93 unevaluated_expr = unity + expr;
94 (void)unevaluated_expr;
95 }
96
97 {
98 term<double> unity{1.0};
99 term<int> i = {1};
100 yap::expression<
101 yap::expr_kind::plus,
102 bh::tuple<ref<term<double> &>, ref<term<int> &>>> const expr =
103 unity + i;
104 yap::expression<
105 yap::expr_kind::plus,
106 bh::tuple<
107 ref<term<double> &>,
108 ref<yap::expression<
109 yap::expr_kind::plus,
110 bh::tuple<ref<term<double> &>, ref<term<int> &>>> const &>>>
111 unevaluated_expr = unity + expr;
112 (void)unevaluated_expr;
113 }
114
115 // lvalue refs
116 {
117 term<double> unity{1.0};
118 int i_ = 1;
119 term<int &> i{i_};
120 yap::expression<
121 yap::expr_kind::plus,
122 bh::tuple<ref<term<double> &>, ref<term<int &> &>>>
123 expr = unity + i;
124 yap::expression<
125 yap::expr_kind::plus,
126 bh::tuple<
127 ref<term<double> &>,
128 ref<yap::expression<
129 yap::expr_kind::plus,
130 bh::tuple<ref<term<double> &>, ref<term<int &> &>>> &>>>
131 unevaluated_expr = unity + expr;
132 (void)unevaluated_expr;
133 }
134
135 {
136 term<double> unity{1.0};
137 int i_ = 1;
138 term<int const &> i{i_};
139 yap::expression<
140 yap::expr_kind::plus,
141 bh::tuple<ref<term<double> &>, ref<term<int const &> &>>>
142 expr = unity + i;
143 yap::expression<
144 yap::expr_kind::plus,
145 bh::tuple<
146 ref<term<double> &>,
147 ref<yap::expression<
148 yap::expr_kind::plus,
149 bh::tuple<
150 ref<term<double> &>,
151 ref<term<int const &> &>>> &>>>
152 unevaluated_expr = unity + expr;
153 (void)unevaluated_expr;
154 }
155
156 {
157 term<double> unity{1.0};
158 int i_ = 1;
159 term<int &> i{i_};
160 yap::expression<
161 yap::expr_kind::plus,
162 bh::tuple<ref<term<double> &>, term<int &>>>
163 expr = unity + std::move(i);
164 yap::expression<
165 yap::expr_kind::plus,
166 bh::tuple<
167 ref<term<double> &>,
168 ref<yap::expression<
169 yap::expr_kind::plus,
170 bh::tuple<ref<term<double> &>, term<int &>>> &>>>
171 unevaluated_expr = unity + expr;
172 (void)unevaluated_expr;
173 }
174
175 {
176 term<double> unity{1.0};
177 int i_ = 1;
178 term<int &> i{i_};
179 yap::expression<
180 yap::expr_kind::plus,
181 bh::tuple<ref<term<double> &>, ref<term<int &> &>>>
182 expr = unity + i;
183 yap::expression<
184 yap::expr_kind::plus,
185 bh::tuple<
186 ref<term<double> &>,
187 yap::expression<
188 yap::expr_kind::plus,
189 bh::tuple<ref<term<double> &>, ref<term<int &> &>>>>>
190 unevaluated_expr = unity + std::move(expr);
191 (void)unevaluated_expr;
192 }
193
194 {
195 term<double> unity{1.0};
196 int i_ = 1;
197 term<int const &> i{i_};
198 yap::expression<
199 yap::expr_kind::plus,
200 bh::tuple<ref<term<double> &>, ref<term<int const &> &>>>
201 expr = unity + i;
202 yap::expression<
203 yap::expr_kind::plus,
204 bh::tuple<
205 ref<term<double> &>,
206 yap::expression<
207 yap::expr_kind::plus,
208 bh::tuple<ref<term<double> &>, ref<term<int const &> &>>>>>
209 unevaluated_expr = unity + std::move(expr);
210 (void)unevaluated_expr;
211 }
212
213 {
214 term<double> unity{1.0};
215 int i_ = 1;
216 term<int &> i{i_};
217 yap::expression<
218 yap::expr_kind::plus,
219 bh::tuple<ref<term<double> &>, term<int &>>>
220 expr = unity + std::move(i);
221 yap::expression<
222 yap::expr_kind::plus,
223 bh::tuple<
224 ref<term<double> &>,
225 yap::expression<
226 yap::expr_kind::plus,
227 bh::tuple<ref<term<double> &>, term<int &>>>>>
228 unevaluated_expr = unity + std::move(expr);
229 (void)unevaluated_expr;
230 }
231
232 // rvalue refs
233 {
234 term<double> unity{1.0};
235 int i_ = 1;
236 term<int &&> i{std::move(i_)};
237 yap::expression<
238 yap::expr_kind::plus,
239 bh::tuple<ref<term<double> &>, term<int &&>>>
240 expr = unity + std::move(i);
241 yap::expression<
242 yap::expr_kind::plus,
243 bh::tuple<
244 ref<term<double> &>,
245 yap::expression<
246 yap::expr_kind::plus,
247 bh::tuple<ref<term<double> &>, term<int &&>>>>>
248 unevaluated_expr = unity + std::move(expr);
249 (void)unevaluated_expr;
250 }
251
252 {
253 term<double> unity{1.0};
254 int i_ = 1;
255 term<int &&> i{std::move(i_)};
256 yap::expression<
257 yap::expr_kind::plus,
258 bh::tuple<ref<term<double> &>, term<int &&>>>
259 expr = unity + std::move(i);
260 yap::expression<
261 yap::expr_kind::plus,
262 bh::tuple<
263 ref<term<double> &>,
264 yap::expression<
265 yap::expr_kind::plus,
266 bh::tuple<ref<term<double> &>, term<int &&>>>>>
267 unevaluated_expr = unity + std::move(expr);
268 (void)unevaluated_expr;
269 }
270
271 {
272 term<double> unity{1.0};
273 int i_ = 1;
274 term<int &&> i{std::move(i_)};
275 yap::expression<
276 yap::expr_kind::plus,
277 bh::tuple<ref<term<double> &>, term<int &&>>>
278 expr = unity + std::move(i);
279 yap::expression<
280 yap::expr_kind::plus,
281 bh::tuple<
282 ref<term<double> &>,
283 yap::expression<
284 yap::expr_kind::plus,
285 bh::tuple<ref<term<double> &>, term<int &&>>>>>
286 unevaluated_expr = unity + std::move(expr);
287 (void)unevaluated_expr;
288 }
289
290 {
291 term<double> unity{1.0};
292 int i_ = 1;
293 term<int &&> i{std::move(i_)};
294 yap::expression<
295 yap::expr_kind::plus,
296 bh::tuple<ref<term<double> &>, term<int &&>>>
297 expr = unity + std::move(i);
298 yap::expression<
299 yap::expr_kind::plus,
300 bh::tuple<
301 ref<term<double> &>,
302 yap::expression<
303 yap::expr_kind::plus,
304 bh::tuple<ref<term<double> &>, term<int &&>>>>>
305 unevaluated_expr = unity + std::move(expr);
306 (void)unevaluated_expr;
307 }
308 }
309