]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/yap/test/value.cpp
1 // Copyright (C) 2016-2018 T. Zachary Laine
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>
8 #include <boost/mpl/assert.hpp>
10 #include <boost/test/minimal.hpp>
14 using term
= boost::yap::terminal
<boost::yap::expression
, T
>;
17 using ref
= boost::yap::expression_ref
<boost::yap::expression
, T
>;
19 namespace yap
= boost::yap
;
20 namespace bh
= boost::hana
;
23 template<boost::yap::expr_kind Kind
, typename Tuple
>
26 static boost::yap::expr_kind
const kind
= Kind
;
31 BOOST_YAP_USER_BINARY_OPERATOR(plus
, user_expr
, user_expr
)
34 using user_term
= boost::yap::terminal
<user_expr
, T
>;
37 using user_ref
= boost::yap::expression_ref
<user_expr
, T
>;
40 int test_main(int, char * [])
44 BOOST_MPL_ASSERT((std::is_same
<decltype(yap::value(1.0)), double &&>));
45 BOOST_CHECK(yap::value(1.0) == 1.0);
50 BOOST_MPL_ASSERT((std::is_same
<decltype(yap::value(d
)), double &>));
51 BOOST_CHECK(yap::value(d
) == 2.0);
57 (std::is_same
<decltype(yap::value(d
)), double const &>));
58 BOOST_CHECK(yap::value(d
) == 3.0);
64 term
<double> td
= {{1.0}};
66 (std::is_same
<decltype(yap::value(std::move(td
))), double &&>));
67 BOOST_CHECK(yap::value(std::move(td
)) == 1.0);
71 term
<double> td
= {{2.0}};
72 BOOST_MPL_ASSERT((std::is_same
<decltype(yap::value(td
)), double &>));
73 BOOST_CHECK(yap::value(td
) == 2.0);
77 term
<double> const td
= {{3.0}};
79 (std::is_same
<decltype(yap::value(td
)), double const &>));
80 BOOST_CHECK(yap::value(td
) == 3.0);
83 term
<double> unity
= {{1.0}};
84 using plus_expr_type
= yap::expression
<
86 bh::tuple
<ref
<term
<double> &>, term
<int>>>;
87 plus_expr_type plus_expr
= unity
+ term
<int>{{1}};
90 ref
<term
<double> &> ref
= bh::front(plus_expr
.elements
);
92 (std::is_same
<decltype(yap::value(std::move(ref
))), double &>));
96 ref
<term
<double> &> ref
= bh::front(plus_expr
.elements
);
97 BOOST_MPL_ASSERT((std::is_same
<decltype(yap::value(ref
)), double &>));
101 ref
<term
<double> &> const ref
= bh::front(plus_expr
.elements
);
102 BOOST_MPL_ASSERT((std::is_same
<decltype(yap::value(ref
)), double &>));
106 term
<double> const unity
= {{1.0}};
108 yap::expr_kind::plus
,
109 bh::tuple
<ref
<term
<double> const &>, term
<int>>>
110 plus_expr
= unity
+ term
<int>{{1}};
113 ref
<term
<double> const &> ref
= bh::front(plus_expr
.elements
);
114 BOOST_MPL_ASSERT((std::is_same
<
115 decltype(yap::value(std::move(ref
))),
120 ref
<term
<double> const &> ref
= bh::front(plus_expr
.elements
);
122 (std::is_same
<decltype(yap::value(ref
)), double const &>));
126 ref
<term
<double> const &> const ref
= bh::front(plus_expr
.elements
);
128 (std::is_same
<decltype(yap::value(ref
)), double const &>));
135 user_term
<double> td
= {{1.0}};
137 (std::is_same
<decltype(yap::value(std::move(td
))), double &&>));
138 BOOST_CHECK(yap::value(std::move(td
)) == 1.0);
142 user_term
<double> td
= {{2.0}};
143 BOOST_MPL_ASSERT((std::is_same
<decltype(yap::value(td
)), double &>));
144 BOOST_CHECK(yap::value(td
) == 2.0);
148 user_term
<double> const td
= {{3.0}};
150 (std::is_same
<decltype(yap::value(td
)), double const &>));
151 BOOST_CHECK(yap::value(td
) == 3.0);
154 user_term
<double> unity
= {{1.0}};
155 using plus_expr_type
= user_expr
<
156 yap::expr_kind::plus
,
157 bh::tuple
<user_ref
<user_term
<double> &>, user_term
<int>>>;
158 plus_expr_type plus_expr
= unity
+ user_term
<int>{{1}};
161 user_ref
<user_term
<double> &> ref
= bh::front(plus_expr
.elements
);
163 (std::is_same
<decltype(yap::value(std::move(ref
))), double &>));
167 user_ref
<user_term
<double> &> ref
= bh::front(plus_expr
.elements
);
168 BOOST_MPL_ASSERT((std::is_same
<decltype(yap::value(ref
)), double &>));
172 user_ref
<user_term
<double> &> const ref
= bh::front(plus_expr
.elements
);
173 BOOST_MPL_ASSERT((std::is_same
<decltype(yap::value(ref
)), double &>));
177 user_term
<double> const unity
= {{1.0}};
179 yap::expr_kind::plus
,
180 bh::tuple
<user_ref
<user_term
<double> const &>, user_term
<int>>>
181 plus_expr
= unity
+ user_term
<int>{{1}};
184 user_ref
<user_term
<double> const &> ref
=
185 bh::front(plus_expr
.elements
);
186 BOOST_MPL_ASSERT((std::is_same
<
187 decltype(yap::value(std::move(ref
))),
192 user_ref
<user_term
<double> const &> ref
=
193 bh::front(plus_expr
.elements
);
195 (std::is_same
<decltype(yap::value(ref
)), double const &>));
199 user_ref
<user_term
<double> const &> const ref
=
200 bh::front(plus_expr
.elements
);
202 (std::is_same
<decltype(yap::value(ref
)), double const &>));