]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/experimental/optional/optional.object/optional.object.observe/value_const.pass.cpp
Vendor import of libc++ trunk r256633:
[FreeBSD/FreeBSD.git] / test / std / experimental / optional / optional.object / optional.object.observe / value_const.pass.cpp
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 // constexpr const T& optional<T>::value() const;
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::in_place_t;
23 using std::experimental::in_place;
24 using std::experimental::bad_optional_access;
25
26 struct X
27 {
28     X() = default;
29     X(const X&) = delete;
30    constexpr int test() const {return 3;}
31     int test() {return 4;}
32 };
33
34 #endif  // _LIBCPP_STD_VER > 11
35
36 int main()
37 {
38 #if _LIBCPP_STD_VER > 11
39     {
40         constexpr optional<X> opt(in_place);
41         static_assert(opt.value().test() == 3, "");
42     }
43     {
44         const optional<X> opt(in_place);
45         assert(opt.value().test() == 3);
46     }
47     {
48         const optional<X> opt;
49         try
50         {
51             opt.value();
52             assert(false);
53         }
54         catch (const bad_optional_access&)
55         {
56         }
57     }
58 #endif  // _LIBCPP_STD_VER > 11
59 }