xref: /llvm-project/libcxx/test/std/utilities/optional/optional.specalg/make_optional_explicit.pass.cpp (revision 2b2ee24d5330d0db93e430b8f0776779ed699f55)
1a9e65961SEric Fiselier //===----------------------------------------------------------------------===//
2a9e65961SEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6a9e65961SEric Fiselier //
7a9e65961SEric Fiselier //===----------------------------------------------------------------------===//
8a9e65961SEric Fiselier 
931cbe0f2SLouis Dionne // UNSUPPORTED: c++03, c++11, c++14
10a9e65961SEric Fiselier // <optional>
11a9e65961SEric Fiselier 
12a9e65961SEric Fiselier // template <class T, class... Args>
13a9e65961SEric Fiselier //   constexpr optional<T> make_optional(Args&&... args);
14a9e65961SEric Fiselier 
15a9e65961SEric Fiselier #include <optional>
16a9e65961SEric Fiselier #include <string>
17a9e65961SEric Fiselier #include <memory>
18a9e65961SEric Fiselier #include <cassert>
19a9e65961SEric Fiselier 
207fc6a556SMarshall Clow #include "test_macros.h"
217fc6a556SMarshall Clow 
main(int,char **)222df59c50SJF Bastien int main(int, char**)
23a9e65961SEric Fiselier {
24a9e65961SEric Fiselier     {
25*2b2ee24dSArthur O'Dwyer         constexpr auto opt = std::make_optional<int>('a');
26*2b2ee24dSArthur O'Dwyer         static_assert(*opt == int('a'));
27a9e65961SEric Fiselier     }
28a9e65961SEric Fiselier     {
29*2b2ee24dSArthur O'Dwyer         std::string s = "123";
30*2b2ee24dSArthur O'Dwyer         auto opt = std::make_optional<std::string>(s);
31*2b2ee24dSArthur O'Dwyer         assert(*opt == "123");
32a9e65961SEric Fiselier     }
33a9e65961SEric Fiselier     {
34*2b2ee24dSArthur O'Dwyer         std::unique_ptr<int> s = std::make_unique<int>(3);
35*2b2ee24dSArthur O'Dwyer         auto opt = std::make_optional<std::unique_ptr<int>>(std::move(s));
36a9e65961SEric Fiselier         assert(**opt == 3);
37a9e65961SEric Fiselier         assert(s == nullptr);
38a9e65961SEric Fiselier     }
39a9e65961SEric Fiselier     {
40*2b2ee24dSArthur O'Dwyer         auto opt = std::make_optional<std::string>(4u, 'X');
41a9e65961SEric Fiselier         assert(*opt == "XXXX");
42a9e65961SEric Fiselier     }
432df59c50SJF Bastien 
442df59c50SJF Bastien   return 0;
45a9e65961SEric Fiselier }
46