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
22int main(int, char**)
23{
24 {
25 constexpr auto opt = std::make_optional<int>('a');
26 static_assert(*opt == int('a'));
27 }
28 {
29 std::string s = "123";
30 auto opt = std::make_optional<std::string>(s);
31 assert(*opt == "123");
32 }
33 {
34 std::unique_ptr<int> s = std::make_unique<int>(3);
35 auto opt = std::make_optional<std::unique_ptr<int>>(std::move(s));
36 assert(**opt == 3);
37 assert(s == nullptr);
38 }
39 {
40 auto opt = std::make_optional<std::string>(4u, 'X');
41 assert(*opt == "XXXX");
42 }
43
44 return 0;
45}
46

source code of libcxx/test/std/utilities/optional/optional.specalg/make_optional_explicit.pass.cpp