]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/yap/test/comma.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>
16 using term
= boost::yap::terminal
<boost::yap::expression
, T
>;
19 using term_ref
= boost::yap::expression_ref
<boost::yap::expression
, term
<T
> &>;
23 boost::yap::expression_ref
<boost::yap::expression
, term
<T
> const &>;
25 namespace yap
= boost::yap
;
26 namespace bh
= boost::hana
;
31 void operator()() { *called_
= (*call_count_
)++; }
40 *called_
= (*call_count_
)++;
47 struct double_callable
51 *called_
= (*call_count_
)++;
59 int test_main(int, char * [])
65 int double_called
= -1;
67 auto int_double_expr
=
68 (term
<int_callable
>{{&call_count
, &int_called
}}(),
69 term
<double_callable
>{{&call_count
, &double_called
}}());
71 BOOST_CHECK(evaluate(int_double_expr
) == 13.0);
72 BOOST_CHECK(int_called
== 0);
73 BOOST_CHECK(double_called
== 1);
79 int double_called
= -1;
81 auto double_int_expr
=
82 (term
<double_callable
>{{&call_count
, &double_called
}}(),
83 term
<int_callable
>{{&call_count
, &int_called
}}());
85 BOOST_CHECK(evaluate(double_int_expr
) == 42);
86 BOOST_CHECK(int_called
== 1);
87 BOOST_CHECK(double_called
== 0);
98 (term
<void_callable
>{{&call_count
, &void_called
}}(),
99 term
<int_callable
>{{&call_count
, &int_called
}}());
101 BOOST_CHECK(evaluate(void_int_expr
) == 42);
102 BOOST_CHECK(void_called
== 0);
103 BOOST_CHECK(int_called
== 1);
108 int void_called
= -1;
112 (term
<int_callable
>{{&call_count
, &int_called
}}(),
113 term
<void_callable
>{{&call_count
, &void_called
}}());
115 using eval_type
= decltype(evaluate(int_void_expr
));
117 (std::is_same
<void, eval_type
>));
119 evaluate(int_void_expr
);
120 BOOST_CHECK(void_called
== 1);
121 BOOST_CHECK(int_called
== 0);