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 // constexpr const T& optional<T>::value() const; 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::in_place_t; 22 using std::experimental::in_place; 23 using std::experimental::bad_optional_access; 24 25 struct X 26 { 27 X() = default; 28 X(const X&) = delete; testX29 constexpr int test() const {return 3;} testX30 int test() {return 4;} 31 }; 32 33 #endif // _LIBCPP_STD_VER > 11 34 main()35int main() 36 { 37 #if _LIBCPP_STD_VER > 11 38 { 39 constexpr optional<X> opt(in_place); 40 static_assert(opt.value().test() == 3, ""); 41 } 42 { 43 const optional<X> opt(in_place); 44 assert(opt.value().test() == 3); 45 } 46 { 47 const optional<X> opt; 48 try 49 { 50 opt.value(); 51 assert(false); 52 } 53 catch (const bad_optional_access&) 54 { 55 } 56 } 57 #endif // _LIBCPP_STD_VER > 11 58 } 59