forked from boostorg/variant2
Add test/variant_derived_construct2. Refs #43.
This commit is contained in:
@ -133,3 +133,5 @@ run variant_json_value_from.cpp : : : $(JSON) ;
|
|||||||
run variant_json_value_to.cpp : : : $(JSON) ;
|
run variant_json_value_to.cpp : : : $(JSON) ;
|
||||||
|
|
||||||
compile variant_uses_double_storage.cpp ;
|
compile variant_uses_double_storage.cpp ;
|
||||||
|
|
||||||
|
run variant_derived_construct2.cpp ;
|
||||||
|
60
test/variant_derived_construct2.cpp
Normal file
60
test/variant_derived_construct2.cpp
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
// Copyright 2024 Peter Dimov.
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// https://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
#include <boost/variant2/variant.hpp>
|
||||||
|
#include <boost/core/lightweight_test.hpp>
|
||||||
|
|
||||||
|
struct expr: boost::variant2::variant<bool, int, double>
|
||||||
|
{
|
||||||
|
using variant::variant;
|
||||||
|
};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
using boost::variant2::get;
|
||||||
|
|
||||||
|
{
|
||||||
|
expr v{ true };
|
||||||
|
|
||||||
|
BOOST_TEST_EQ( v.index(), 0 );
|
||||||
|
BOOST_TEST_EQ( get<0>(v), true );
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
expr v{ 2 };
|
||||||
|
|
||||||
|
BOOST_TEST_EQ( v.index(), 1 );
|
||||||
|
BOOST_TEST_EQ( get<1>(v), 2 );
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
expr v{ 3.0 };
|
||||||
|
|
||||||
|
BOOST_TEST_EQ( v.index(), 2 );
|
||||||
|
BOOST_TEST_EQ( get<2>(v), 3.0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
expr v( true );
|
||||||
|
|
||||||
|
BOOST_TEST_EQ( v.index(), 0 );
|
||||||
|
BOOST_TEST_EQ( get<0>(v), true );
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
expr v( 2 );
|
||||||
|
|
||||||
|
BOOST_TEST_EQ( v.index(), 1 );
|
||||||
|
BOOST_TEST_EQ( get<1>(v), 2 );
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
expr v( 3.0 );
|
||||||
|
|
||||||
|
BOOST_TEST_EQ( v.index(), 2 );
|
||||||
|
BOOST_TEST_EQ( get<2>(v), 3.0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
Reference in New Issue
Block a user