]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/variant/test/test1.cpp
1 //-----------------------------------------------------------------------------
2 // boost-libs variant/test/test1.cpp header file
3 // See http://www.boost.org for updates, documentation, and revision history.
4 //-----------------------------------------------------------------------------
7 // Eric Friedman, Itay Maman
9 // Distributed under the Boost Software License, Version 1.0. (See
10 // accompanying file LICENSE_1_0.txt or copy at
11 // http://www.boost.org/LICENSE_1_0.txt)
13 #include "boost/config.hpp"
16 #pragma warning(disable:4244) // conversion from const int to const short
19 #include "boost/test/minimal.hpp"
20 #include "boost/variant.hpp"
34 using boost::apply_visitor
;
41 typedef variant
< char*, string
, short > t_var0
;
42 typedef variant
< int, string
, double > t_var1
;
43 typedef variant
< short, const char* > t_var2
;
44 typedef variant
< string
, char > t_var3
;
45 typedef variant
< unsigned short, const char* > t_var4
;
46 typedef variant
< unsigned short, const char*, t_var2
> t_var5
;
47 typedef variant
< unsigned short, const char*, t_var5
> t_var6
;
48 typedef variant
< class_a
, const void* > t_var7
;
49 typedef variant
< t_var6
, int > t_var8
;
50 typedef variant
< t_var8
, unsigned short > t_var9
;
51 typedef variant
< char, unsigned char > t_var10
;
52 typedef variant
< short, int, vector
<int>, long> t_var11
;
69 // Check assignment rules
74 verify(v4
, spec
<unsigned short>());
78 verify(v4
, spec
<const char*>(), "[V] abc");
81 verify(v5
, spec
<const char*>(), "[V] def");
84 verify(v5
, spec
<t_var2
>(), "[V] [V] abc");
87 verify(v6
, spec
<unsigned short>(), "[V] 58");
90 verify(v6
, spec
<t_var5
>(), "[V] [V] [V] abc");
93 verify(v8
, spec
<t_var6
>(), "[V] [V] abc");
96 verify(v8
, spec
<t_var6
>(), "[V] [V] [V] [V] abc");
99 verify(v7
, spec
<const void*>());
102 verify(v7
, spec
<class_a
>(), "[V] class_a(199)");
106 verify(v7
, spec
<class_a
>(), "[V] class_a(200)");
111 // Check sizes of held values
116 apply_visitor(ts
, v1
);
119 apply_visitor(ts
, v1
);
122 apply_visitor(ts
, v1
);
124 BOOST_CHECK(ts
.result() == sizeof(int) + sizeof(double)*2);
127 string res_s
= apply_visitor(int_printer(), v11
);
128 BOOST_CHECK(res_s
== "5");
131 // A variant object holding an std::vector
133 vector
<int> int_vec_1
;
134 int_vec_1
.push_back(512);
135 int_vec_1
.push_back(256);
136 int_vec_1
.push_back(128);
137 int_vec_1
.push_back(64);
140 res_s
= apply_visitor(int_printer(), v11
);
141 BOOST_CHECK(res_s
== ",512,256,128,64");
146 int test_main(int , char* [])