• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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++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 #include "test_macros.h"
21 
main(int,char **)22 int main(int, char**)
23 {
24     using std::optional;
25     using std::make_optional;
26 
27     {
28         constexpr auto opt = make_optional<int>('a');
29         static_assert(*opt == int('a'), "");
30     }
31     {
32         std::string s("123");
33         auto opt = make_optional<std::string>(s);
34         assert(*opt == s);
35     }
36     {
37         std::unique_ptr<int> s(new int(3));
38         auto opt = make_optional<std::unique_ptr<int>>(std::move(s));
39         assert(**opt == 3);
40         assert(s == nullptr);
41     }
42     {
43         auto opt = make_optional<std::string>(4u, 'X');
44         assert(*opt == "XXXX");
45     }
46 
47   return 0;
48 }
49