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_x_this_ref_overloads()21 void compile_term_plus_x_this_ref_overloads()
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 + "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 + "3"s;
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<ref<term<double> &>, term<int *>>>
52             unevaluated_expr = unity + ints;
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<ref<term<double> &>, term<int const *>>>
62             unevaluated_expr = unity + ints;
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<ref<term<double> &>, term<int *>>>
72             unevaluated_expr = unity + std::move(ints);
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<ref<term<double> &>, term<int *&>>>
84             unevaluated_expr = unity + int_ptr;
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<ref<term<double> &>, term<int const *&>>>
95             unevaluated_expr = unity + int_ptr;
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<ref<term<double> &>, term<int *>>>
106             unevaluated_expr = unity + std::move(int_ptr);
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<ref<term<double> &>, term<int * const &>>>
118             unevaluated_expr = unity + int_ptr;
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<ref<term<double> &>, term<int const * const &>>>
129             unevaluated_expr = unity + int_ptr;
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<ref<term<double> &>, term<int * const>>>
140             unevaluated_expr = unity + std::move(int_ptr);
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<ref<term<double> &>, term<int &>>>
151             unevaluated_expr = unity + i;
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<ref<term<double> &>, term<int const &>>>
161             unevaluated_expr = unity + i;
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<ref<term<double> &>, term<int>>>
171             unevaluated_expr = unity + std::move(i);
172         (void)unevaluated_expr;
173     }
174 }
175