]>
git.proxmox.com Git - ceph.git/blob - 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
6 # pragma warning( disable: 4244 ) // conversion from float to int, possible loss of data
9 #include <boost/variant2/variant.hpp>
10 #include <boost/core/lightweight_test.hpp>
11 #include <boost/config.hpp>
12 #include <boost/config/workaround.hpp>
15 struct X
: boost::variant2::variant
<int, float>
17 #if BOOST_WORKAROUND( BOOST_MSVC, < 1940 )
19 template<class T
> explicit X( T
&& t
): variant( std::forward
<T
>( t
) ) {};
23 using variant::variant
;
28 template<class... T
> struct Y
: boost::variant2::variant
<T
...>
30 using boost::variant2::variant
<T
...>::variant
;
39 BOOST_TEST_EQ( (visit( []( int x1
, float x2
){ return (int)(x1
* 1000) + (int)(x2
* 100); }, v1
, v2
)), 1314 );
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
) );
46 Y
<int, float> v1( 1 );
47 Y
<int, float> const v2( 3.14f
);
49 BOOST_TEST_EQ( (visit( []( int x1
, float x2
){ return (int)(x1
* 1000) + (int)(x2
* 100); }, v1
, v2
)), 1314 );
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
) );
55 return boost::report_errors();