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