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