//===----------------------------------------------------------------------===// // // 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. // //===----------------------------------------------------------------------===// // UNSUPPORTED: c++98, c++03, c++11 // // template optional& operator=(U&& v); #include #include #include #include using std::experimental::optional; struct AllowConstAssign { AllowConstAssign() {} AllowConstAssign(AllowConstAssign const&) {} AllowConstAssign const& operator=(AllowConstAssign const&) const { return *this; } }; struct X { }; int main() { static_assert(std::is_assignable, int>::value, ""); static_assert(std::is_assignable, int&>::value, ""); static_assert(std::is_assignable&, int>::value, ""); static_assert(std::is_assignable&, int&>::value, ""); static_assert(std::is_assignable&, const int&>::value, ""); static_assert(!std::is_assignable&, const int&>::value, ""); static_assert(!std::is_assignable, X>::value, ""); { optional opt; opt = 1; assert(static_cast(opt) == true); assert(*opt == 1); } { optional opt; const int i = 2; opt = i; assert(static_cast(opt) == true); assert(*opt == i); } { optional opt(3); const int i = 2; opt = i; assert(static_cast(opt) == true); assert(*opt == i); } { optional opt; const AllowConstAssign other; opt = other; } { optional> opt; opt = std::unique_ptr(new int(3)); assert(static_cast(opt) == true); assert(**opt == 3); } { optional> opt(std::unique_ptr(new int(2))); opt = std::unique_ptr(new int(3)); assert(static_cast(opt) == true); assert(**opt == 3); } }