]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/variant/test/variant_multivisit_test.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / variant / test / variant_multivisit_test.cpp
1 //-----------------------------------------------------------------------------
2 // boost-libs variant/test/variant_multivisit_test.cpp source file
3 // See http://www.boost.org for updates, documentation, and revision history.
4 //-----------------------------------------------------------------------------
5 //
6 // Copyright (c) 2013-2022 Antony Polukhin
7 //
8 // Distributed under the Boost Software License, Version 1.0. (See
9 // accompanying file LICENSE_1_0.txt or copy at
10 // http://www.boost.org/LICENSE_1_0.txt)
11
12 #include "boost/config.hpp"
13 #include "boost/noncopyable.hpp"
14 #define BOOST_VARAINT_MAX_MULTIVIZITOR_PARAMS 5
15 #include "boost/variant/multivisitors.hpp"
16 #include "boost/variant.hpp"
17
18 #include "boost/core/lightweight_test.hpp"
19
20 struct my_noncopyable : boost::noncopyable {
21 my_noncopyable(){}
22 ~my_noncopyable(){}
23 };
24
25 typedef boost::variant<my_noncopyable, int> variant_noncopy_t;
26
27
28 typedef boost::variant<char, unsigned char, signed char, unsigned short, int> variant5_t;
29
30 struct test_visitor: boost::static_visitor<> {
31 // operators that shall not be called
32 template <class T1, class T2, class T3>
33 void operator()(T1&, T2&, T3&) const
34 {
35 BOOST_TEST(false);
36 }
37
38 template <class T1, class T2, class T3, class T4>
39 void operator()(T1&, T2&, T3&, T4&) const
40 {
41 BOOST_TEST(false);
42 }
43
44 template <class T1, class T2, class T3, class T4, class T5>
45 void operator()(T1&, T2&, T3&, T4&, T5&) const
46 {
47 BOOST_TEST(false);
48 }
49
50 // operators that are OK to call
51 void operator()(char v0, unsigned char v1, signed char v2) const
52 {
53 BOOST_TEST(v0 == 0);
54 BOOST_TEST(v1 == 1);
55 BOOST_TEST(v2 == 2);
56 }
57
58 void operator()(char v0, unsigned char v1, signed char v2, unsigned short v3) const
59 {
60 BOOST_TEST(v0 == 0);
61 BOOST_TEST(v1 == 1);
62 BOOST_TEST(v2 == 2);
63 BOOST_TEST(v3 == 3);
64 }
65
66 void operator()(char v0, unsigned char v1, signed char v2, unsigned short v3, int v4) const
67 {
68 BOOST_TEST(v0 == 0);
69 BOOST_TEST(v1 == 1);
70 BOOST_TEST(v2 == 2);
71 BOOST_TEST(v3 == 3);
72 BOOST_TEST(v4 == 4);
73 }
74
75
76 // Noncopyables
77 void operator()(my_noncopyable&, my_noncopyable&, my_noncopyable&) const {
78 BOOST_TEST(true);
79 }
80 void operator()(my_noncopyable&, my_noncopyable&, my_noncopyable&, my_noncopyable&) const {
81 BOOST_TEST(true);
82 }
83 void operator()(my_noncopyable&, my_noncopyable&, my_noncopyable&, my_noncopyable&, my_noncopyable&) const {
84 BOOST_TEST(true);
85 }
86 void operator()(my_noncopyable&, my_noncopyable&, my_noncopyable&, my_noncopyable&, my_noncopyable&, my_noncopyable&) const {
87 BOOST_TEST(true);
88 }
89 };
90
91 typedef boost::variant<int, double, bool> bool_like_t;
92 typedef boost::variant<int, double> arithmetics_t;
93
94 struct if_visitor: public boost::static_visitor<arithmetics_t> {
95 template <class T0, class T1, class T2>
96 arithmetics_t operator()(T0 b, T1 v1, T2 v2) const {
97 if (!!b) {
98 return v1;
99 } else {
100 return v2;
101 }
102 }
103 };
104
105
106 int main()
107 {
108 test_visitor v;
109
110 variant5_t v_array5[5];
111 v_array5[0] = char(0);
112 v_array5[1] = static_cast<unsigned char>(1);
113 v_array5[2] = static_cast<signed char>(2);
114 v_array5[3] = static_cast<unsigned short>(3);
115 v_array5[4] = static_cast<int>(4);
116
117 boost::apply_visitor(v, v_array5[0], v_array5[1], v_array5[2]);
118 boost::apply_visitor(test_visitor(), v_array5[0], v_array5[1], v_array5[2]);
119
120 // Following test also pass, but requires many Gigabytes of RAM for compilation and compile for about 15 minutes
121 //#define BOOST_VARIANT_MULTIVISITORS_TEST_VERY_EXTREME
122 #ifdef BOOST_VARIANT_MULTIVISITORS_TEST_VERY_EXTREME
123 boost::apply_visitor(v, v_array5[0], v_array5[1], v_array5[2], v_array5[3]);
124 boost::apply_visitor(test_visitor(), v_array5[0], v_array5[1], v_array5[2], v_array5[3]);
125
126 boost::apply_visitor(v, v_array5[0], v_array5[1], v_array5[2], v_array5[3], v_array5[4]);
127 boost::apply_visitor(test_visitor(), v_array5[0], v_array5[1], v_array5[2], v_array5[3], v_array5[4]);
128 #endif
129
130 bool_like_t v0(1), v1(true), v2(1.0);
131
132 BOOST_TEST(
133 boost::apply_visitor(if_visitor(), v0, v1, v2)
134 ==
135 arithmetics_t(true)
136 );
137
138 #if !defined(BOOST_VARIANT_DO_NOT_USE_VARIADIC_TEMPLATES)
139 if_visitor if_vis;
140 BOOST_TEST(
141 boost::apply_visitor(if_vis)(v0, v1, v2)
142 ==
143 arithmetics_t(true)
144 );
145 #endif
146
147
148 variant_noncopy_t vnonc[6];
149 boost::apply_visitor(v, vnonc[0], vnonc[1], vnonc[2]);
150 boost::apply_visitor(test_visitor(), vnonc[0], vnonc[1], vnonc[2], vnonc[3]);
151
152 #ifdef BOOST_VARIANT_MULTIVISITORS_TEST_VERY_EXTREME
153 boost::apply_visitor(v, vnonc[0], vnonc[1], vnonc[2], vnonc[3], vnonc[4]);
154 boost::apply_visitor(test_visitor(), vnonc[0], vnonc[1], vnonc[2], vnonc[3], vnonc[4], vnonc[5]);
155 #endif
156
157 return boost::report_errors();
158 }