]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/yap/test/comma.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / yap / test / comma.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/mpl/assert.hpp>
9
10 #include <boost/test/minimal.hpp>
11
12 #include <sstream>
13
14
15 template<typename T>
16 using term = boost::yap::terminal<boost::yap::expression, T>;
17
18 template<typename T>
19 using term_ref = boost::yap::expression_ref<boost::yap::expression, term<T> &>;
20
21 template<typename T>
22 using term_cref =
23 boost::yap::expression_ref<boost::yap::expression, term<T> const &>;
24
25 namespace yap = boost::yap;
26 namespace bh = boost::hana;
27
28
29 struct void_callable
30 {
31 void operator()() { *called_ = (*call_count_)++; }
32 int * call_count_;
33 int * called_;
34 };
35
36 struct int_callable
37 {
38 int operator()()
39 {
40 *called_ = (*call_count_)++;
41 return 42;
42 }
43 int * call_count_;
44 int * called_;
45 };
46
47 struct double_callable
48 {
49 double operator()()
50 {
51 *called_ = (*call_count_)++;
52 return 13.0;
53 }
54 int * call_count_;
55 int * called_;
56 };
57
58
59 int test_main(int, char * [])
60 {
61 {
62 {
63 int call_count = 0;
64 int int_called = -1;
65 int double_called = -1;
66
67 auto int_double_expr =
68 (term<int_callable>{{&call_count, &int_called}}(),
69 term<double_callable>{{&call_count, &double_called}}());
70
71 BOOST_CHECK(evaluate(int_double_expr) == 13.0);
72 BOOST_CHECK(int_called == 0);
73 BOOST_CHECK(double_called == 1);
74 }
75
76 {
77 int call_count = 0;
78 int int_called = -1;
79 int double_called = -1;
80
81 auto double_int_expr =
82 (term<double_callable>{{&call_count, &double_called}}(),
83 term<int_callable>{{&call_count, &int_called}}());
84
85 BOOST_CHECK(evaluate(double_int_expr) == 42);
86 BOOST_CHECK(int_called == 1);
87 BOOST_CHECK(double_called == 0);
88 }
89 }
90
91 {
92 {
93 int call_count = 0;
94 int void_called = -1;
95 int int_called = -1;
96
97 auto void_int_expr =
98 (term<void_callable>{{&call_count, &void_called}}(),
99 term<int_callable>{{&call_count, &int_called}}());
100
101 BOOST_CHECK(evaluate(void_int_expr) == 42);
102 BOOST_CHECK(void_called == 0);
103 BOOST_CHECK(int_called == 1);
104 }
105
106 {
107 int call_count = 0;
108 int void_called = -1;
109 int int_called = -1;
110
111 auto int_void_expr =
112 (term<int_callable>{{&call_count, &int_called}}(),
113 term<void_callable>{{&call_count, &void_called}}());
114
115 using eval_type = decltype(evaluate(int_void_expr));
116 BOOST_MPL_ASSERT(
117 (std::is_same<void, eval_type>));
118
119 evaluate(int_void_expr);
120 BOOST_CHECK(void_called == 1);
121 BOOST_CHECK(int_called == 0);
122 }
123 }
124
125 return 0;
126 }