1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // UNSUPPORTED: c++98, c++03, c++11, c++14
10 // <optional>
11 
12 // template <class T, class... Args>
13 //   constexpr optional<T> make_optional(Args&&... args);
14 
15 #include <optional>
16 #include <string>
17 #include <memory>
18 #include <cassert>
19 
20 int main(int, char**)
21 {
22     using std::optional;
23     using std::make_optional;
24 
25     {
26         constexpr auto opt = make_optional<int>('a');
27         static_assert(*opt == int('a'), "");
28     }
29     {
30         std::string s("123");
31         auto opt = make_optional<std::string>(s);
32         assert(*opt == s);
33     }
34     {
35         std::unique_ptr<int> s(new int(3));
36         auto opt = make_optional<std::unique_ptr<int>>(std::move(s));
37         assert(**opt == 3);
38         assert(s == nullptr);
39     }
40     {
41         auto opt = make_optional<std::string>(4, 'X');
42         assert(*opt == "XXXX");
43     }
44 
45   return 0;
46 }
47