]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/variant2/test/variant_visit_derived.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / variant2 / test / variant_visit_derived.cpp
1 // Copyright 2017, 2020 Peter Dimov.
2 // Distributed under the Boost Software License, Version 1.0.
3 // https://www.boost.org/LICENSE_1_0.txt
4
5 #if defined(_MSC_VER)
6 # pragma warning( disable: 4244 ) // conversion from float to int, possible loss of data
7 #endif
8
9 #include <boost/variant2/variant.hpp>
10 #include <boost/core/lightweight_test.hpp>
11 #include <boost/config.hpp>
12 #include <boost/config/workaround.hpp>
13 #include <utility>
14
15 struct X: boost::variant2::variant<int, float>
16 {
17 #if BOOST_WORKAROUND( BOOST_MSVC, < 1940 )
18
19 template<class T> explicit X( T&& t ): variant( std::forward<T>( t ) ) {};
20
21 #else
22
23 using variant::variant;
24
25 #endif
26 };
27
28 template<class... T> struct Y: boost::variant2::variant<T...>
29 {
30 using boost::variant2::variant<T...>::variant;
31 };
32
33 int main()
34 {
35 {
36 X v1( 1 );
37 X const v2( 3.14f );
38
39 BOOST_TEST_EQ( (visit( []( int x1, float x2 ){ return (int)(x1 * 1000) + (int)(x2 * 100); }, v1, v2 )), 1314 );
40
41 visit( []( int x1, float x2 ){ BOOST_TEST_EQ( x1, 1 ); BOOST_TEST_EQ( x2, 3.14f ); }, v1, v2 );
42 visit( []( int x1, float x2 ){ BOOST_TEST_EQ( x1, 1 ); BOOST_TEST_EQ( x2, 3.14f ); }, std::move(v1), std::move(v2) );
43 }
44
45 {
46 Y<int, float> v1( 1 );
47 Y<int, float> const v2( 3.14f );
48
49 BOOST_TEST_EQ( (visit( []( int x1, float x2 ){ return (int)(x1 * 1000) + (int)(x2 * 100); }, v1, v2 )), 1314 );
50
51 visit( []( int x1, float x2 ){ BOOST_TEST_EQ( x1, 1 ); BOOST_TEST_EQ( x2, 3.14f ); }, v1, v2 );
52 visit( []( int x1, float x2 ){ BOOST_TEST_EQ( x1, 1 ); BOOST_TEST_EQ( x2, 3.14f ); }, std::move(v1), std::move(v2) );
53 }
54
55 return boost::report_errors();
56 }