5 // If we have libc++ 4.0 or greater we should have <optional>
6 // According to libc++ C++1z status page https://libcxx.llvm.org/cxx1z_status.html
7 #if _LIBCPP_VERSION >= 4000
9 #define HAVE_OPTIONAL 1
11 #define HAVE_OPTIONAL 0
17 bool has_optional = HAVE_OPTIONAL ;
19 printf( "%d\n", has_optional ) ; // break here
21 #if HAVE_OPTIONAL == 1
22 using int_vect = std::vector<int> ;
23 using optional_int = std::optional<int> ;
24 using optional_int_vect = std::optional<int_vect> ;
25 using optional_string = std::optional<std::string> ;
27 optional_int number_not_engaged ;
28 optional_int number_engaged = 42 ;
30 printf( "%d\n", *number_engaged) ;
32 optional_int_vect numbers{{1,2,3,4}} ;
34 printf( "%d %d\n", numbers.value()[0], numbers.value()[1] ) ;
36 optional_string ostring = "hello" ;
38 printf( "%s\n", ostring->c_str() ) ;
41 return 0; // break here