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 // <optional> 10 // UNSUPPORTED: c++03, c++11, c++14 11 12 // template<class T> 13 // optional(T) -> optional<T>; 14 15 #include <optional> 16 #include <cassert> 17 18 #include "test_macros.h" 19 20 struct A {}; 21 22 int main(int, char**) 23 { 24 // Test the explicit deduction guides 25 { 26 // optional(T) 27 std::optional opt(5); 28 static_assert(std::is_same_v<decltype(opt), std::optional<int>>, ""); 29 assert(static_cast<bool>(opt)); 30 assert(*opt == 5); 31 } 32 33 { 34 // optional(T) 35 std::optional opt(A{}); 36 static_assert(std::is_same_v<decltype(opt), std::optional<A>>, ""); 37 assert(static_cast<bool>(opt)); 38 } 39 40 // Test the implicit deduction guides 41 { 42 // optional(optional); 43 std::optional<char> source('A'); 44 std::optional opt(source); 45 static_assert(std::is_same_v<decltype(opt), std::optional<char>>, ""); 46 assert(static_cast<bool>(opt) == static_cast<bool>(source)); 47 assert(*opt == *source); 48 } 49 50 return 0; 51 } 52