]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/utilities/optional/optional.specalg/make_optional.pass.cpp
Vendor import of libc++ trunk r351319 (just before the release_80
[FreeBSD/FreeBSD.git] / test / std / utilities / optional / optional.specalg / make_optional.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, c++14
11 // <optional>
12
13 // XFAIL: availability=macosx10.13
14 // XFAIL: availability=macosx10.12
15 // XFAIL: availability=macosx10.11
16 // XFAIL: availability=macosx10.10
17 // XFAIL: availability=macosx10.9
18 // XFAIL: availability=macosx10.8
19 // XFAIL: availability=macosx10.7
20
21 // template <class T>
22 //   constexpr optional<decay_t<T>> make_optional(T&& v);
23
24 #include <optional>
25 #include <string>
26 #include <memory>
27 #include <cassert>
28
29 #include "test_macros.h"
30
31 int main()
32 {
33     using std::optional;
34     using std::make_optional;
35     {
36         int arr[10]; ((void)arr);
37         ASSERT_SAME_TYPE(decltype(make_optional(arr)), optional<int*>);
38     }
39     {
40         constexpr auto opt = make_optional(2);
41         ASSERT_SAME_TYPE(decltype(opt), const optional<int>);
42         static_assert(opt.value() == 2);
43     }
44     {
45         optional<int> opt = make_optional(2);
46         assert(*opt == 2);
47     }
48     {
49         std::string s("123");
50         optional<std::string> opt = make_optional(s);
51         assert(*opt == s);
52     }
53     {
54         std::unique_ptr<int> s(new int(3));
55         optional<std::unique_ptr<int>> opt = make_optional(std::move(s));
56         assert(**opt == 3);
57         assert(s == nullptr);
58     }
59 }