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 #include <string>
9
10
11 template<typename T>
12 using term = boost::yap::terminal<boost::yap::expression, T>;
13
14 template<typename T>
15 using ref = boost::yap::expression_ref<boost::yap::expression, T>;
16
17 namespace yap = boost::yap;
18 namespace bh = boost::hana;
19
20
compile_term_plus_term()21 void compile_term_plus_term()
22 {
23 using namespace std::literals;
24
25 // char const * string
26 {
27 term<double> unity{1.0};
28 yap::expression<
29 yap::expr_kind::plus,
30 bh::tuple<ref<term<double> &>, term<char const *>>>
31 unevaluated_expr = unity + term<char const *>{"3"};
32 (void)unevaluated_expr;
33 }
34
35 // std::string temporary
36 {
37 term<double> unity{1.0};
38 yap::expression<
39 yap::expr_kind::plus,
40 bh::tuple<ref<term<double> &>, term<std::string>>>
41 unevaluated_expr = unity + term<std::string>{"3"s};
42 (void)unevaluated_expr;
43 }
44
45 // pointers
46 {
47 term<double> unity{1.0};
48 int ints_[] = {1, 2};
49 term<int *> ints = {ints_};
50 yap::expression<
51 yap::expr_kind::plus,
52 bh::tuple<ref<term<double> &>, ref<term<int *> &>>>
53 unevaluated_expr = unity + ints;
54 (void)unevaluated_expr;
55 }
56
57 {
58 term<double> unity{1.0};
59 int const ints_[] = {1, 2};
60 term<int const *> ints = {ints_};
61 yap::expression<
62 yap::expr_kind::plus,
63 bh::tuple<ref<term<double> &>, ref<term<int const *> &>>>
64 unevaluated_expr = unity + ints;
65 (void)unevaluated_expr;
66 }
67
68 {
69 term<double> unity{1.0};
70 int ints_[] = {1, 2};
71 term<int *> ints = {ints_};
72 yap::expression<
73 yap::expr_kind::plus,
74 bh::tuple<ref<term<double> &>, term<int *>>>
75 unevaluated_expr = unity + std::move(ints);
76 (void)unevaluated_expr;
77 }
78
79 // const pointers
80 {
81 term<double> unity{1.0};
82 int ints[] = {1, 2};
83 term<int * const> int_ptr = {ints};
84 yap::expression<
85 yap::expr_kind::plus,
86 bh::tuple<ref<term<double> &>, ref<term<int * const> &>>>
87 unevaluated_expr = unity + int_ptr;
88 (void)unevaluated_expr;
89 }
90
91 {
92 term<double> unity{1.0};
93 int const ints[] = {1, 2};
94 term<int const * const> int_ptr = {ints};
95 yap::expression<
96 yap::expr_kind::plus,
97 bh::tuple<ref<term<double> &>, ref<term<int const * const> &>>>
98 unevaluated_expr = unity + int_ptr;
99 (void)unevaluated_expr;
100 }
101
102 {
103 term<double> unity{1.0};
104 int ints[] = {1, 2};
105 term<int * const> int_ptr = {ints};
106 yap::expression<
107 yap::expr_kind::plus,
108 bh::tuple<ref<term<double> &>, term<int * const>>>
109 unevaluated_expr = unity + std::move(int_ptr);
110 (void)unevaluated_expr;
111 }
112
113 // values
114 {
115 term<double> unity{1.0};
116 term<int> i = {1};
117 yap::expression<
118 yap::expr_kind::plus,
119 bh::tuple<ref<term<double> &>, ref<term<int> &>>>
120 unevaluated_expr = unity + i;
121 (void)unevaluated_expr;
122 }
123
124 {
125 term<double> unity{1.0};
126 term<int const> i = {1};
127 yap::expression<
128 yap::expr_kind::plus,
129 bh::tuple<ref<term<double> &>, ref<term<int const> &>>>
130 unevaluated_expr = unity + i;
131 (void)unevaluated_expr;
132 }
133
134 {
135 term<double> unity{1.0};
136 term<int> i = {1};
137 yap::expression<
138 yap::expr_kind::plus,
139 bh::tuple<ref<term<double> &>, term<int>>>
140 unevaluated_expr = unity + std::move(i);
141 (void)unevaluated_expr;
142 }
143
144 // const value terminals
145 {
146 term<double> unity{1.0};
147 term<int> const i = {1};
148 yap::expression<
149 yap::expr_kind::plus,
150 bh::tuple<ref<term<double> &>, ref<term<int> const &>>>
151 unevaluated_expr = unity + i;
152 (void)unevaluated_expr;
153 }
154
155 {
156 term<double> unity{1.0};
157 term<int const> const i = {1};
158 yap::expression<
159 yap::expr_kind::plus,
160 bh::tuple<ref<term<double> &>, ref<term<int const> const &>>>
161 unevaluated_expr = unity + i;
162 (void)unevaluated_expr;
163 }
164
165 // lvalue refs
166 {
167 term<double> unity{1.0};
168 int i_ = 1;
169 term<int &> i{i_};
170 yap::expression<
171 yap::expr_kind::plus,
172 bh::tuple<ref<term<double> &>, ref<term<int &> &>>>
173 unevaluated_expr = unity + i;
174 (void)unevaluated_expr;
175 }
176
177 {
178 term<double> unity{1.0};
179 int i_ = 1;
180 term<int const &> i{i_};
181 yap::expression<
182 yap::expr_kind::plus,
183 bh::tuple<ref<term<double> &>, ref<term<int const &> &>>>
184 unevaluated_expr = unity + i;
185 (void)unevaluated_expr;
186 }
187
188 {
189 term<double> unity{1.0};
190 int i_ = 1;
191 term<int &> i{i_};
192 yap::expression<
193 yap::expr_kind::plus,
194 bh::tuple<ref<term<double> &>, term<int &>>>
195 unevaluated_expr = unity + std::move(i);
196 (void)unevaluated_expr;
197 }
198
199 // rvalue refs
200 {
201 term<double> unity{1.0};
202 int i_ = 1;
203 term<int &&> i{std::move(i_)};
204 yap::expression<
205 yap::expr_kind::plus,
206 bh::tuple<ref<term<double> &>, term<int &&>>>
207 unevaluated_expr = unity + std::move(i);
208 (void)unevaluated_expr;
209 }
210
211 {
212 term<double> unity{1.0};
213 int i_ = 1;
214 term<int &&> i{std::move(i_)};
215 yap::expression<
216 yap::expr_kind::plus,
217 bh::tuple<ref<term<double> &>, term<int &&>>>
218 unevaluated_expr = unity + std::move(i);
219 (void)unevaluated_expr;
220 }
221 }
222