]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/yap/test/placeholder_eval.cpp
48c1d98b43992030916f6ffe800b49f550fb3d20
[ceph.git] / ceph / src / boost / libs / yap / test / placeholder_eval.cpp
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 <boost/core/lightweight_test.hpp>
9
10 #include <sstream>
11
12
13 template<typename T>
14 using term = boost::yap::terminal<boost::yap::expression, T>;
15
16 template<long long I>
17 using place_term =
18 boost::yap::terminal<boost::yap::expression, boost::yap::placeholder<I>>;
19
20 template<typename T>
21 using ref = boost::yap::expression_ref<boost::yap::expression, T>;
22
23 namespace yap = boost::yap;
24 namespace bh = boost::hana;
25
26
27 int main()
28 {
29 {
30 using namespace boost::yap::literals;
31
32 place_term<3> p3 = 3_p;
33 int i_ = 42;
34 term<int> i{std::move(i_)};
35 yap::expression<
36 yap::expr_kind::plus,
37 bh::tuple<ref<place_term<3> &>, term<int>>>
38 expr = p3 + std::move(i);
39 yap::expression<
40 yap::expr_kind::plus,
41 bh::tuple<
42 ref<place_term<3> &>,
43 yap::expression<
44 yap::expr_kind::plus,
45 bh::tuple<ref<place_term<3> &>, term<int>>>>>
46 unevaluated_expr = p3 + std::move(expr);
47
48 {
49 double result = evaluate(p3, 5, 6, 7);
50 BOOST_TEST(result == 7);
51 }
52
53 {
54 double result = evaluate(expr, std::string("15"), 3, 1);
55 BOOST_TEST(result == 43);
56 }
57
58 {
59 double result = evaluate(unevaluated_expr, std::string("15"), 2, 3);
60 BOOST_TEST(result == 48);
61 }
62 }
63
64 return boost::report_errors();
65 }