Skip to content

Commit 557676b

Browse files
committed
Add a variant2 test to value_to.cpp, extracted from #925
1 parent 25e740d commit 557676b

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

test/value_to.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include <boost/core/ignore_unused.hpp>
1515
#include <boost/describe/class.hpp>
1616
#include <boost/describe/enum.hpp>
17+
#include <boost/variant2/variant.hpp>
18+
#include <boost/config.hpp>
1719

1820
#include "test_suite.hpp"
1921

@@ -22,6 +24,10 @@
2224
#include <unordered_map>
2325
#include <vector>
2426

27+
#ifndef BOOST_NO_CXX17_HDR_VARIANT
28+
# include <variant>
29+
#endif
30+
2531
namespace value_to_test_ns
2632
{
2733

@@ -470,24 +476,24 @@ class value_to_test
470476
#endif
471477
}
472478

473-
template< class... Context >
479+
template<
480+
template <class...> class Variant, class Monostate, class... Context >
474481
static
475482
void
476483
testVariant( Context const& ... ctx )
477484
{
478-
ignore_unused( ctx... );
479-
#ifndef BOOST_NO_CXX17_HDR_VARIANT
480-
using Var = std::variant<int, ::value_to_test_ns::T2, std::string>;
485+
using std::get;
486+
using Var = Variant<int, ::value_to_test_ns::T2, std::string>;
481487

482488
value jv(4);
483489
auto v = value_to<Var>( jv, ctx... );
484490
BOOST_TEST( v.index() == 0 );
485-
BOOST_TEST( std::get<0>(v) == 4 );
491+
BOOST_TEST( get<0>(v) == 4 );
486492

487493
jv = "foobar";
488494
v = value_to<Var>( jv, ctx... );
489495
BOOST_TEST( v.index() == 2 );
490-
BOOST_TEST( std::get<2>(v) == "foobar" );
496+
BOOST_TEST( get<2>(v) == "foobar" );
491497

492498
jv = "T2";
493499
v = value_to<Var>( jv, ctx... );
@@ -497,10 +503,9 @@ class value_to_test
497503
BOOST_TEST_THROWS_WITH_LOCATION(
498504
value_to<Var>( jv, ctx... ));
499505

500-
value_to<std::monostate>( value(), ctx... );
506+
value_to<Monostate>( value(), ctx... );
501507
BOOST_TEST_THROWS_WITH_LOCATION(
502-
value_to<std::monostate>( jv, ctx... ));
503-
#endif // BOOST_NO_CXX17_HDR_VARIANT
508+
value_to<Monostate>( jv, ctx... ));
504509
}
505510

506511
template< class... Context >
@@ -718,7 +723,10 @@ class value_to_test
718723
testNullptr( Context()... );
719724
testDescribed( Context()... );
720725
testOptional( Context()... );
721-
testVariant( Context()... );
726+
testVariant< variant2::variant, variant2::monostate > ( Context()... );
727+
#ifndef BOOST_NO_CXX17_HDR_VARIANT
728+
testVariant< std::variant, std::monostate > ( Context()... );
729+
#endif // BOOST_NO_CXX17_HDR_VARIANT
722730
testNonThrowing( Context()... );
723731
testUserConversion( Context()... );
724732
}

0 commit comments

Comments
 (0)