1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <optional> 11 12 // T& optional<T>::value(); 13 14 #include <experimental/optional> 15 #include <type_traits> 16 #include <cassert> 17 18 #if _LIBCPP_STD_VER > 11 19 20 using std::experimental::optional; 21 using std::experimental::bad_optional_access; 22 23 struct X 24 { 25 X() = default; 26 X(const X&) = delete; testX27 constexpr int test() const {return 3;} testX28 int test() {return 4;} 29 }; 30 31 #endif // _LIBCPP_STD_VER > 11 32 main()33int main() 34 { 35 #if _LIBCPP_STD_VER > 11 36 { 37 optional<X> opt; 38 opt.emplace(); 39 assert(opt.value().test() == 4); 40 } 41 { 42 optional<X> opt; 43 try 44 { 45 opt.value(); 46 assert(false); 47 } 48 catch (const bad_optional_access&) 49 { 50 } 51 } 52 #endif // _LIBCPP_STD_VER > 11 53 } 54