Home | History | Annotate | Download | only in optional.specalg
      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 // template <class T>
     14 //   constexpr optional<decay_t<T>> make_optional(T&& v);
     15 
     16 #include <optional>
     17 #include <string>
     18 #include <memory>
     19 #include <cassert>
     20 
     21 #include "test_macros.h"
     22 
     23 int main()
     24 {
     25     using std::optional;
     26     using std::make_optional;
     27     {
     28         int arr[10]; ((void)arr);
     29         ASSERT_SAME_TYPE(decltype(make_optional(arr)), optional<int*>);
     30     }
     31     {
     32         constexpr auto opt = make_optional(2);
     33         ASSERT_SAME_TYPE(decltype(opt), const optional<int>);
     34         static_assert(opt.value() == 2);
     35     }
     36     {
     37         optional<int> opt = make_optional(2);
     38         assert(*opt == 2);
     39     }
     40     {
     41         std::string s("123");
     42         optional<std::string> opt = make_optional(s);
     43         assert(*opt == s);
     44     }
     45     {
     46         std::unique_ptr<int> s(new int(3));
     47         optional<std::unique_ptr<int>> opt = make_optional(std::move(s));
     48         assert(**opt == 3);
     49         assert(s == nullptr);
     50     }
     51 }
     52