01afa5c6e4
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@189772 91177308-0d34-0410-b5e6-96231b3b80d8
52 lines
1.3 KiB
C++
52 lines
1.3 KiB
C++
//===----------------------------------------------------------------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is dual licensed under the MIT and the University of Illinois Open
|
|
// Source Licenses. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// <optional>
|
|
|
|
// template <class T>
|
|
// constexpr
|
|
// optional<typename decay<T>::type>
|
|
// make_optional(T&& v);
|
|
|
|
#include <optional>
|
|
#include <string>
|
|
#include <memory>
|
|
#include <cassert>
|
|
|
|
#if _LIBCPP_STD_VER > 11
|
|
|
|
#endif // _LIBCPP_STD_VER > 11
|
|
|
|
int main()
|
|
{
|
|
#if _LIBCPP_STD_VER > 11
|
|
{
|
|
std::optional<int> opt = std::make_optional(2);
|
|
assert(*opt == 2);
|
|
}
|
|
{
|
|
std::string s("123");
|
|
std::optional<std::string> opt = std::make_optional(s);
|
|
assert(*opt == s);
|
|
}
|
|
{
|
|
std::string s("123");
|
|
std::optional<std::string> opt = std::make_optional(std::move(s));
|
|
assert(*opt == "123");
|
|
assert(s.empty());
|
|
}
|
|
{
|
|
std::unique_ptr<int> s(new int(3));
|
|
std::optional<std::unique_ptr<int>> opt = std::make_optional(std::move(s));
|
|
assert(**opt == 3);
|
|
assert(s == nullptr);
|
|
}
|
|
#endif // _LIBCPP_STD_VER > 11
|
|
}
|