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 11 // <optional> 12 13 // template <class T> 14 // constexpr 15 // optional<typename decay<T>::type> 16 // make_optional(T&& v); 17 18 #include <experimental/optional> 19 #include <string> 20 #include <memory> 21 #include <cassert> 22 23 #include "test_macros.h" 24 25 int main() 26 { 27 using std::experimental::optional; 28 using std::experimental::make_optional; 29 30 { 31 optional<int> opt = make_optional(2); 32 assert(*opt == 2); 33 } 34 { 35 std::string s("123"); 36 optional<std::string> opt = make_optional(s); 37 assert(*opt == s); 38 } 39 { 40 std::string s("123"); 41 optional<std::string> opt = make_optional(std::move(s)); 42 assert(*opt == "123"); 43 LIBCPP_ASSERT(s.empty()); 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