1 //===----------------------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // UNSUPPORTED: c++98, c++03, c++11
13 // template <class U> optional<T>& operator=(U&& v);
15 #include <experimental/optional>
16 #include <type_traits>
20 using std::experimental::optional;
22 struct AllowConstAssign {
24 AllowConstAssign(AllowConstAssign const&) {}
25 AllowConstAssign const& operator=(AllowConstAssign const&) const {
36 static_assert(std::is_assignable<optional<int>, int>::value, "");
37 static_assert(std::is_assignable<optional<int>, int&>::value, "");
38 static_assert(std::is_assignable<optional<int>&, int>::value, "");
39 static_assert(std::is_assignable<optional<int>&, int&>::value, "");
40 static_assert(std::is_assignable<optional<int>&, const int&>::value, "");
41 static_assert(!std::is_assignable<const optional<int>&, const int&>::value, "");
42 static_assert(!std::is_assignable<optional<int>, X>::value, "");
46 assert(static_cast<bool>(opt) == true);
53 assert(static_cast<bool>(opt) == true);
60 assert(static_cast<bool>(opt) == true);
64 optional<const AllowConstAssign> opt;
65 const AllowConstAssign other;
69 optional<std::unique_ptr<int>> opt;
70 opt = std::unique_ptr<int>(new int(3));
71 assert(static_cast<bool>(opt) == true);
75 optional<std::unique_ptr<int>> opt(std::unique_ptr<int>(new int(2)));
76 opt = std::unique_ptr<int>(new int(3));
77 assert(static_cast<bool>(opt) == true);