14
14
#include < boost/core/ignore_unused.hpp>
15
15
#include < boost/describe/class.hpp>
16
16
#include < boost/describe/enum.hpp>
17
+ #include < boost/variant2/variant.hpp>
18
+ #include < boost/config.hpp>
17
19
18
20
#include " test_suite.hpp"
19
21
22
24
#include < unordered_map>
23
25
#include < vector>
24
26
27
+ #ifndef BOOST_NO_CXX17_HDR_VARIANT
28
+ # include < variant>
29
+ #endif
30
+
25
31
namespace value_to_test_ns
26
32
{
27
33
@@ -470,24 +476,24 @@ class value_to_test
470
476
#endif
471
477
}
472
478
473
- template < class ... Context >
479
+ template <
480
+ template <class ...> class Variant , class Monostate , class ... Context >
474
481
static
475
482
void
476
483
testVariant ( Context const & ... ctx )
477
484
{
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>;
481
487
482
488
value jv (4 );
483
489
auto v = value_to<Var>( jv, ctx... );
484
490
BOOST_TEST ( v.index () == 0 );
485
- BOOST_TEST ( std:: get<0 >(v) == 4 );
491
+ BOOST_TEST ( get<0 >(v) == 4 );
486
492
487
493
jv = " foobar" ;
488
494
v = value_to<Var>( jv, ctx... );
489
495
BOOST_TEST ( v.index () == 2 );
490
- BOOST_TEST ( std:: get<2 >(v) == " foobar" );
496
+ BOOST_TEST ( get<2 >(v) == " foobar" );
491
497
492
498
jv = " T2" ;
493
499
v = value_to<Var>( jv, ctx... );
@@ -497,10 +503,9 @@ class value_to_test
497
503
BOOST_TEST_THROWS_WITH_LOCATION (
498
504
value_to<Var>( jv, ctx... ));
499
505
500
- value_to<std::monostate >( value (), ctx... );
506
+ value_to<Monostate >( value (), ctx... );
501
507
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... ));
504
509
}
505
510
506
511
template < class ... Context >
@@ -718,7 +723,10 @@ class value_to_test
718
723
testNullptr ( Context ()... );
719
724
testDescribed ( Context ()... );
720
725
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
722
730
testNonThrowing ( Context ()... );
723
731
testUserConversion ( Context ()... );
724
732
}
0 commit comments