]> 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 r290819:
[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 // UNSUPPORTED: c++98, c++03, c++11
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 #include "test_macros.h"
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 int main()
35 {
36     {
37         constexpr optional<X> opt(in_place);
38         static_assert(opt.value().test() == 3, "");
39     }
40     {
41         const optional<X> opt(in_place);
42         assert(opt.value().test() == 3);
43     }
44 #ifndef TEST_HAS_NO_EXCEPTIONS
45     {
46         const optional<X> opt;
47         try
48         {
49             opt.value();
50             assert(false);
51         }
52         catch (const bad_optional_access&)
53         {
54         }
55     }
56 #endif
57 }