• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_x_plus_term()21 void compile_x_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<term<char const *>, ref<term<double> &>>>
31             unevaluated_expr = "3" + unity;
32         (void)unevaluated_expr;
33     }
34 
35     // std::string temporary
36     {
37         term<double> const unity{1.0};
38         yap::expression<
39             yap::expr_kind::plus,
40             bh::tuple<term<std::string>, ref<term<double> const &>>>
41             unevaluated_expr = "3"s + unity;
42         (void)unevaluated_expr;
43     }
44 
45     // arrays
46     {
47         term<double> unity{1.0};
48         int ints[] = {1, 2};
49         yap::expression<
50             yap::expr_kind::plus,
51             bh::tuple<term<int *>, ref<term<double> &>>>
52             unevaluated_expr = ints + unity;
53         (void)unevaluated_expr;
54     }
55 
56     {
57         term<double> unity{1.0};
58         int const ints[] = {1, 2};
59         yap::expression<
60             yap::expr_kind::plus,
61             bh::tuple<term<int const *>, ref<term<double> &>>>
62             unevaluated_expr = ints + unity;
63         (void)unevaluated_expr;
64     }
65 
66     {
67         term<double> unity{1.0};
68         int ints[] = {1, 2};
69         yap::expression<
70             yap::expr_kind::plus,
71             bh::tuple<term<int *>, ref<term<double> &>>>
72             unevaluated_expr = std::move(ints) + unity;
73         (void)unevaluated_expr;
74     }
75 
76     // pointers
77     {
78         term<double> unity{1.0};
79         int ints[] = {1, 2};
80         int * int_ptr = ints;
81         yap::expression<
82             yap::expr_kind::plus,
83             bh::tuple<term<int *&>, ref<term<double> &>>>
84             unevaluated_expr = int_ptr + unity;
85         (void)unevaluated_expr;
86     }
87 
88     {
89         term<double> unity{1.0};
90         int const ints[] = {1, 2};
91         int const * int_ptr = ints;
92         yap::expression<
93             yap::expr_kind::plus,
94             bh::tuple<term<int const *&>, ref<term<double> &>>>
95             unevaluated_expr = int_ptr + unity;
96         (void)unevaluated_expr;
97     }
98 
99     {
100         term<double> unity{1.0};
101         int ints[] = {1, 2};
102         int * int_ptr = ints;
103         yap::expression<
104             yap::expr_kind::plus,
105             bh::tuple<term<int *>, ref<term<double> &>>>
106             unevaluated_expr = std::move(int_ptr) + unity;
107         (void)unevaluated_expr;
108     }
109 
110     // const pointers
111     {
112         term<double> unity{1.0};
113         int ints[] = {1, 2};
114         int * const int_ptr = ints;
115         yap::expression<
116             yap::expr_kind::plus,
117             bh::tuple<term<int * const &>, ref<term<double> &>>>
118             unevaluated_expr = int_ptr + unity;
119         (void)unevaluated_expr;
120     }
121 
122     {
123         term<double> unity{1.0};
124         int const ints[] = {1, 2};
125         int const * const int_ptr = ints;
126         yap::expression<
127             yap::expr_kind::plus,
128             bh::tuple<term<int const * const &>, ref<term<double> &>>>
129             unevaluated_expr = int_ptr + unity;
130         (void)unevaluated_expr;
131     }
132 
133     {
134         term<double> unity{1.0};
135         int ints[] = {1, 2};
136         int * const int_ptr = ints;
137         yap::expression<
138             yap::expr_kind::plus,
139             bh::tuple<term<int * const>, ref<term<double> &>>>
140             unevaluated_expr = std::move(int_ptr) + unity;
141         (void)unevaluated_expr;
142     }
143 
144     // values
145     {
146         term<double> unity{1.0};
147         int i = 1;
148         yap::expression<
149             yap::expr_kind::plus,
150             bh::tuple<term<int &>, ref<term<double> &>>>
151             unevaluated_expr = i + unity;
152         (void)unevaluated_expr;
153     }
154 
155     {
156         term<double> unity{1.0};
157         int const i = 1;
158         yap::expression<
159             yap::expr_kind::plus,
160             bh::tuple<term<int const &>, ref<term<double> &>>>
161             unevaluated_expr = i + unity;
162         (void)unevaluated_expr;
163     }
164 
165     {
166         term<double> unity{1.0};
167         int i = 1;
168         yap::expression<
169             yap::expr_kind::plus,
170             bh::tuple<term<int>, ref<term<double> &>>>
171             unevaluated_expr = std::move(i) + unity;
172         (void)unevaluated_expr;
173     }
174 }
175