• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 // Copyright 2017 Peter Dimov.
3 //
4 // 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
8 
9 #include <boost/variant2/variant.hpp>
10 #include <boost/core/lightweight_test.hpp>
11 #include <string>
12 
13 using namespace boost::variant2;
14 
main()15 int main()
16 {
17     {
18         variant<int> v;
19         BOOST_TEST( holds_alternative<int>( v ) );
20     }
21 
22     {
23         variant<int, float> v;
24         BOOST_TEST( holds_alternative<int>( v ) );
25         BOOST_TEST( !holds_alternative<float>( v ) );
26     }
27 
28     {
29         variant<int, float> v( 3.14f );
30         BOOST_TEST( !holds_alternative<int>( v ) );
31         BOOST_TEST( holds_alternative<float>( v ) );
32     }
33 
34     {
35         variant<int, float, float> v;
36         BOOST_TEST( holds_alternative<int>( v ) );
37     }
38 
39     {
40         variant<int, int, float> v( 3.14f );
41         BOOST_TEST( holds_alternative<float>( v ) );
42     }
43 
44     {
45         variant<int, float, std::string> v;
46         BOOST_TEST( holds_alternative<int>( v ) );
47         BOOST_TEST( !holds_alternative<float>( v ) );
48         BOOST_TEST( !holds_alternative<std::string>( v ) );
49     }
50 
51     {
52         variant<int, float, std::string> v( 3.14f );
53         BOOST_TEST( !holds_alternative<int>( v ) );
54         BOOST_TEST( holds_alternative<float>( v ) );
55         BOOST_TEST( !holds_alternative<std::string>( v ) );
56     }
57 
58     {
59         variant<int, float, std::string> v( "text" );
60         BOOST_TEST( !holds_alternative<int>( v ) );
61         BOOST_TEST( !holds_alternative<float>( v ) );
62         BOOST_TEST( holds_alternative<std::string>( v ) );
63     }
64 
65     {
66         variant<int, int, float, std::string> v( 3.14f );
67         BOOST_TEST( holds_alternative<float>( v ) );
68         BOOST_TEST( !holds_alternative<std::string>( v ) );
69     }
70 
71     {
72         variant<int, int, float, std::string> v( "text" );
73         BOOST_TEST( !holds_alternative<float>( v ) );
74         BOOST_TEST( holds_alternative<std::string>( v ) );
75     }
76 
77     return boost::report_errors();
78 }
79