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 11 using namespace boost::variant2; 12 13 #define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__) 14 main()15int main() 16 { 17 { 18 constexpr variant<int> v; 19 STATIC_ASSERT( holds_alternative<int>( v ) ); 20 } 21 22 { 23 constexpr variant<int, float> v; 24 STATIC_ASSERT( holds_alternative<int>( v ) ); 25 STATIC_ASSERT( !holds_alternative<float>( v ) ); 26 } 27 28 { 29 constexpr variant<int, float> v( 3.14f ); 30 STATIC_ASSERT( !holds_alternative<int>( v ) ); 31 STATIC_ASSERT( holds_alternative<float>( v ) ); 32 } 33 34 { 35 constexpr variant<int, float, float> v; 36 STATIC_ASSERT( holds_alternative<int>( v ) ); 37 } 38 39 { 40 constexpr variant<int, int, float> v( 3.14f ); 41 STATIC_ASSERT( holds_alternative<float>( v ) ); 42 } 43 } 44