blob: e91805e9c8e5f66647b581c26c1ea2f1c9e3e4b8 [file] [log] [blame]
Howard Hinnant01afa5c2013-09-02 20:30:37 +00001//===----------------------------------------------------------------------===//
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// T& optional<T>::value();
13
Marshall Clow0cdbe602013-11-15 22:42:10 +000014#include <experimental/optional>
Howard Hinnant01afa5c2013-09-02 20:30:37 +000015#include <type_traits>
16#include <cassert>
17
18#if _LIBCPP_STD_VER > 11
19
Marshall Clow0cdbe602013-11-15 22:42:10 +000020using std::experimental::optional;
21using std::experimental::bad_optional_access;
22
Howard Hinnant01afa5c2013-09-02 20:30:37 +000023struct X
24{
25 X() = default;
26 X(const X&) = delete;
27 constexpr int test() const {return 3;}
28 int test() {return 4;}
29};
30
31#endif // _LIBCPP_STD_VER > 11
32
33int main()
34{
35#if _LIBCPP_STD_VER > 11
36 {
Marshall Clow0cdbe602013-11-15 22:42:10 +000037 optional<X> opt;
Howard Hinnant01afa5c2013-09-02 20:30:37 +000038 opt.emplace();
39 assert(opt.value().test() == 4);
40 }
41 {
Marshall Clow0cdbe602013-11-15 22:42:10 +000042 optional<X> opt;
Howard Hinnant01afa5c2013-09-02 20:30:37 +000043 try
44 {
45 opt.value();
46 assert(false);
47 }
Marshall Clow0cdbe602013-11-15 22:42:10 +000048 catch (const bad_optional_access&)
Howard Hinnant01afa5c2013-09-02 20:30:37 +000049 {
50 }
51 }
52#endif // _LIBCPP_STD_VER > 11
53}