5 // If we have libc++ 4.0 or greater we should have <variant>
6 // According to libc++ C++1z status page https://libcxx.llvm.org/cxx1z_status.html
7 #if _LIBCPP_VERSION >= 4000
11 #define HAVE_VARIANT 0
15 operator int() { throw 42; }
21 bool has_variant = HAVE_VARIANT ;
23 printf( "%d\n", has_variant ) ; // break here
26 std::variant<int, double, char> v1;
27 std::variant<int, double, char> &v1_ref = v1;
28 std::variant<int, double, char> v2;
29 std::variant<int, double, char> v3;
30 std::variant<std::variant<int,double,char>> v_v1 ;
31 std::variant<int, double, char> v_no_value;
33 v1 = 12; // v contains int
35 int i = std::get<int>(v1);
36 printf( "%d\n", i ); // break here
39 double d = std::get<double>(v2) ;
43 char c = std::get<char>(v3) ;
46 // Checking v1 above and here to make sure we done maintain the incorrect
47 // state when we change its value.
49 d = std::get<double>(v1) ;
50 printf( "%f\n", d ); // break here
53 v_no_value.emplace<0>(S());
56 printf( "%zu\n", v_no_value.index() ) ;
59 return 0; // break here