Add test/variant_derived_construct2. Refs #43.

This commit is contained in:
Peter Dimov
2024-03-24 18:41:49 +02:00
parent c125b32938
commit a936eae01b
2 changed files with 62 additions and 0 deletions

View File

@ -133,3 +133,5 @@ run variant_json_value_from.cpp : : : $(JSON) ;
run variant_json_value_to.cpp : : : $(JSON) ;
compile variant_uses_double_storage.cpp ;
run variant_derived_construct2.cpp ;

View 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();
}