]>
git.proxmox.com Git - ceph.git/blob - 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 //-----------------------------------------------------------------------------
6 // Copyright (c) 2013-2015 Antony Polukhin
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)
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"
18 #include "boost/test/minimal.hpp"
20 struct my_noncopyable
: boost::noncopyable
{
25 typedef boost::variant
<my_noncopyable
, int> variant_noncopy_t
;
28 typedef boost::variant
<char, unsigned char, signed char, unsigned short, int, unsigned int> variant6_t
;
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
38 template <class T1
, class T2
, class T3
, class T4
>
39 void operator()(T1
&, T2
&, T3
&, T4
&) const
44 template <class T1
, class T2
, class T3
, class T4
, class T5
>
45 void operator()(T1
&, T2
&, T3
&, T4
&, T5
&) const
50 // operators that are OK to call
51 void operator()(char v0
, unsigned char v1
, signed char v2
) const
58 void operator()(char v0
, unsigned char v1
, signed char v2
, unsigned short v3
) const
66 void operator()(char v0
, unsigned char v1
, signed char v2
, unsigned short v3
, int v4
) const
77 void operator()(my_noncopyable
&, my_noncopyable
&, my_noncopyable
&) const {
80 void operator()(my_noncopyable
&, my_noncopyable
&, my_noncopyable
&, my_noncopyable
&) const {
83 void operator()(my_noncopyable
&, my_noncopyable
&, my_noncopyable
&, my_noncopyable
&, my_noncopyable
&) const {
86 void operator()(my_noncopyable
&, my_noncopyable
&, my_noncopyable
&, my_noncopyable
&, my_noncopyable
&, my_noncopyable
&) const {
91 typedef boost::variant
<int, double, bool> bool_like_t
;
92 typedef boost::variant
<int, double> arithmetics_t
;
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 {
106 int test_main(int , char* [])
110 variant6_t v_array6
[6];
111 v_array6
[0] = char(0);
112 v_array6
[1] = static_cast<unsigned char>(1);
113 v_array6
[2] = static_cast<signed char>(2);
114 v_array6
[3] = static_cast<unsigned short>(3);
115 v_array6
[4] = static_cast<int>(4);
116 v_array6
[5] = static_cast<unsigned int>(5);
118 boost::apply_visitor(v
, v_array6
[0], v_array6
[1], v_array6
[2]);
119 boost::apply_visitor(test_visitor(), v_array6
[0], v_array6
[1], v_array6
[2]);
121 // Following test also pass, but requires many Gigabytes of RAM for compilation and compile for about 15 minutes
122 //#define BOOST_VARIANT_MULTIVISITORS_TEST_VERY_EXTREME
123 #ifdef BOOST_VARIANT_MULTIVISITORS_TEST_VERY_EXTREME
124 boost::apply_visitor(v
, v_array6
[0], v_array6
[1], v_array6
[2], v_array6
[3]);
125 boost::apply_visitor(test_visitor(), v_array6
[0], v_array6
[1], v_array6
[2], v_array6
[3]);
127 boost::apply_visitor(v
, v_array6
[0], v_array6
[1], v_array6
[2], v_array6
[3], v_array6
[4]);
128 boost::apply_visitor(test_visitor(), v_array6
[0], v_array6
[1], v_array6
[2], v_array6
[3], v_array6
[4]);
131 bool_like_t
v0(1), v1(true), v2(1.0);
134 boost::apply_visitor(if_visitor(), v0
, v1
, v2
)
139 #if !defined(BOOST_VARIANT_DO_NOT_USE_VARIADIC_TEMPLATES)
142 boost::apply_visitor(if_vis
)(v0
, v1
, v2
)
149 variant_noncopy_t vnonc
[6];
150 boost::apply_visitor(v
, vnonc
[0], vnonc
[1], vnonc
[2]);
151 boost::apply_visitor(test_visitor(), vnonc
[0], vnonc
[1], vnonc
[2], vnonc
[3]);
153 #ifdef BOOST_VARIANT_MULTIVISITORS_TEST_VERY_EXTREME
154 boost::apply_visitor(v
, vnonc
[0], vnonc
[1], vnonc
[2], vnonc
[3], vnonc
[4]);
155 boost::apply_visitor(test_visitor(), vnonc
[0], vnonc
[1], vnonc
[2], vnonc
[3], vnonc
[4], vnonc
[5]);
158 return boost::exit_success
;