1-
2- // Copyright 2017 Peter Dimov.
3- //
1+ // Copyright 2017, 2026 Peter Dimov.
42// Distributed under the Boost Software License, Version 1.0.
5- //
6- // See accompanying file LICENSE_1_0.txt or copy at
7- // http://www.boost.org/LICENSE_1_0.txt
3+ // https://www.boost.org/LICENSE_1_0.txt
84
95#include < boost/variant2/variant.hpp>
106#include < boost/core/lightweight_test.hpp>
@@ -34,13 +30,27 @@ int main()
3430 {
3531 variant<int , float , float > v;
3632 BOOST_TEST ( holds_alternative<int >( v ) );
33+ BOOST_TEST ( !holds_alternative<float >( v ) );
3734 }
3835
3936 {
4037 variant<int , int , float > v ( 3 .14f );
38+ BOOST_TEST ( !holds_alternative<int >( v ) );
4139 BOOST_TEST ( holds_alternative<float >( v ) );
4240 }
4341
42+ {
43+ variant<int , int , float > v ( in_place_index_t <0 >{} );
44+ BOOST_TEST ( holds_alternative<int >( v ) );
45+ BOOST_TEST ( !holds_alternative<float >( v ) );
46+ }
47+
48+ {
49+ variant<int , int , float > v ( in_place_index_t <1 >{} );
50+ BOOST_TEST ( holds_alternative<int >( v ) );
51+ BOOST_TEST ( !holds_alternative<float >( v ) );
52+ }
53+
4454 {
4555 variant<int , float , std::string> v;
4656 BOOST_TEST ( holds_alternative<int >( v ) );
@@ -64,15 +74,31 @@ int main()
6474
6575 {
6676 variant<int , int , float , std::string> v ( 3 .14f );
77+ BOOST_TEST ( !holds_alternative<int >( v ) );
6778 BOOST_TEST ( holds_alternative<float >( v ) );
6879 BOOST_TEST ( !holds_alternative<std::string>( v ) );
6980 }
7081
7182 {
7283 variant<int , int , float , std::string> v ( " text" );
84+ BOOST_TEST ( !holds_alternative<int >( v ) );
7385 BOOST_TEST ( !holds_alternative<float >( v ) );
7486 BOOST_TEST ( holds_alternative<std::string>( v ) );
7587 }
7688
89+ {
90+ variant<int , int , float , std::string> v ( in_place_index_t <0 >{} );
91+ BOOST_TEST ( holds_alternative<int >( v ) );
92+ BOOST_TEST ( !holds_alternative<float >( v ) );
93+ BOOST_TEST ( !holds_alternative<std::string>( v ) );
94+ }
95+
96+ {
97+ variant<int , int , float , std::string> v ( in_place_index_t <1 >{} );
98+ BOOST_TEST ( holds_alternative<int >( v ) );
99+ BOOST_TEST ( !holds_alternative<float >( v ) );
100+ BOOST_TEST ( !holds_alternative<std::string>( v ) );
101+ }
102+
77103 return boost::report_errors ();
78104}
0 commit comments