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 // UNSUPPORTED: c++98, c++03, c++11
     11 // <optional>
     12 
     13 // T& optional<T>::value();
     14 
     15 #include <experimental/optional>
     16 #include <type_traits>
     17 #include <cassert>
     18 
     19 #include "test_macros.h"
     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 int main()
     33 {
     34     {
     35         optional<X> opt;
     36         opt.emplace();
     37         assert(opt.value().test() == 4);
     38     }
     39 #ifndef TEST_HAS_NO_EXCEPTIONS
     40     {
     41         optional<X> opt;
     42         try
     43         {
     44             opt.value();
     45             assert(false);
     46         }
     47         catch (const bad_optional_access&)
     48         {
     49         }
     50     }
     51 #endif
     52 }
     53