Home | History | Annotate | Download | only in optional.object.observe
      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 // XFAIL: libcpp-no-exceptions
     11 // <optional>
     12 
     13 // T& optional<T>::value();
     14 
     15 #include <experimental/optional>
     16 #include <type_traits>
     17 #include <cassert>
     18 
     19 #if _LIBCPP_STD_VER > 11
     20 
     21 using std::experimental::optional;
     22 using std::experimental::bad_optional_access;
     23 
     24 struct X
     25 {
     26     X() = default;
     27     X(const X&) = delete;
     28     constexpr int test() const {return 3;}
     29     int test() {return 4;}
     30 };
     31 
     32 #endif  // _LIBCPP_STD_VER > 11
     33 
     34 int main()
     35 {
     36 #if _LIBCPP_STD_VER > 11
     37     {
     38         optional<X> opt;
     39         opt.emplace();
     40         assert(opt.value().test() == 4);
     41     }
     42     {
     43         optional<X> opt;
     44         try
     45         {
     46             opt.value();
     47             assert(false);
     48         }
     49         catch (const bad_optional_access&)
     50         {
     51         }
     52     }
     53 #endif  // _LIBCPP_STD_VER > 11
     54 }
     55