Skip to content

Commit

Permalink
Add test/variant_derived_construct2. Refs #43.
Browse files Browse the repository at this point in the history
  • Loading branch information
pdimov committed Mar 24, 2024
1 parent c125b32 commit a936eae
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;
60 changes: 60 additions & 0 deletions test/variant_derived_construct2.cpp
Original file line number Diff line number Diff line change
@@ -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();
}

0 comments on commit a936eae

Please sign in to comment.