]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/yap/test/deref.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 * [])
43 term
<double> unity
= {{1.0}};
44 using plus_expr_type
= yap::expression
<
46 bh::tuple
<ref
<term
<double> &>, term
<int>>>;
48 plus_expr_type plus_expr
= unity
+ term
<int>{{1}};
51 ref
<term
<double> &> ref
= bh::front(plus_expr
.elements
);
52 BOOST_MPL_ASSERT((std::is_same
<
53 decltype(yap::deref(std::move(ref
))),
55 BOOST_CHECK(yap::value(ref
) == 1.0);
59 ref
<term
<double> &> ref
= bh::front(plus_expr
.elements
);
61 (std::is_same
<decltype(yap::deref(ref
)), term
<double> &>));
62 BOOST_CHECK(yap::value(ref
) == 1.0);
66 ref
<term
<double> &> const ref
= bh::front(plus_expr
.elements
);
68 (std::is_same
<decltype(yap::deref(ref
)), term
<double> &>));
69 BOOST_CHECK(yap::value(ref
) == 1.0);
73 term
<double> const unity
= {{1.0}};
76 bh::tuple
<ref
<term
<double> const &>, term
<int>>>
77 plus_expr
= unity
+ term
<int>{{1}};
80 ref
<term
<double> const &> ref
= bh::front(plus_expr
.elements
);
81 BOOST_MPL_ASSERT((std::is_same
<
82 decltype(yap::deref(std::move(ref
))),
83 term
<double> const &>));
84 BOOST_CHECK(yap::value(ref
) == 1.0);
88 ref
<term
<double> const &> ref
= bh::front(plus_expr
.elements
);
89 BOOST_MPL_ASSERT((std::is_same
<
90 decltype(yap::deref(ref
)),
91 term
<double> const &>));
92 BOOST_CHECK(yap::value(ref
) == 1.0);
96 ref
<term
<double> const &> const ref
=
97 bh::front(plus_expr
.elements
);
98 BOOST_MPL_ASSERT((std::is_same
<
99 decltype(yap::deref(ref
)),
100 term
<double> const &>));
101 BOOST_CHECK(yap::value(ref
) == 1.0);
107 user_term
<double> unity
= {{1.0}};
108 using plus_expr_type
= user_expr
<
109 yap::expr_kind::plus
,
110 bh::tuple
<user_ref
<user_term
<double> &>, user_term
<int>>>;
112 plus_expr_type plus_expr
= unity
+ user_term
<int>{{1}};
115 user_ref
<user_term
<double> &> ref
= bh::front(plus_expr
.elements
);
116 BOOST_MPL_ASSERT((std::is_same
<
117 decltype(yap::deref(std::move(ref
))),
118 user_term
<double> &>));
119 BOOST_CHECK(yap::value(ref
) == 1.0);
123 user_ref
<user_term
<double> &> ref
= bh::front(plus_expr
.elements
);
125 (std::is_same
<decltype(yap::deref(ref
)), user_term
<double> &>));
126 BOOST_CHECK(yap::value(ref
) == 1.0);
130 user_ref
<user_term
<double> &> const ref
=
131 bh::front(plus_expr
.elements
);
133 (std::is_same
<decltype(yap::deref(ref
)), user_term
<double> &>));
134 BOOST_CHECK(yap::value(ref
) == 1.0);
138 user_term
<double> const unity
= {{1.0}};
140 yap::expr_kind::plus
,
141 bh::tuple
<user_ref
<user_term
<double> const &>, user_term
<int>>>
142 plus_expr
= unity
+ user_term
<int>{{1}};
145 user_ref
<user_term
<double> const &> ref
=
146 bh::front(plus_expr
.elements
);
147 BOOST_MPL_ASSERT((std::is_same
<
148 decltype(yap::deref(std::move(ref
))),
149 user_term
<double> const &>));
150 BOOST_CHECK(yap::value(ref
) == 1.0);
154 user_ref
<user_term
<double> const &> ref
=
155 bh::front(plus_expr
.elements
);
156 BOOST_MPL_ASSERT((std::is_same
<
157 decltype(yap::deref(ref
)),
158 user_term
<double> const &>));
159 BOOST_CHECK(yap::value(ref
) == 1.0);
163 user_ref
<user_term
<double> const &> const ref
=
164 bh::front(plus_expr
.elements
);
165 BOOST_MPL_ASSERT((std::is_same
<
166 decltype(yap::deref(ref
)),
167 user_term
<double> const &>));
168 BOOST_CHECK(yap::value(ref
) == 1.0);