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 // optional(optional<T>&& rhs) noexcept(is_nothrow_move_constructible<T>::value);
15 #include <experimental/optional>
16 #include <type_traits>
19 #include "test_macros.h"
21 using std::experimental::optional;
25 test(optional<T>& rhs, bool is_going_to_throw = false)
27 static_assert(std::is_nothrow_move_constructible<optional<T>>::value ==
28 std::is_nothrow_move_constructible<T>::value, "");
29 bool rhs_engaged = static_cast<bool>(rhs);
30 #ifdef TEST_HAS_NO_EXCEPTIONS
31 if (is_going_to_throw)
37 optional<T> lhs = std::move(rhs);
38 assert(is_going_to_throw == false);
39 assert(static_cast<bool>(lhs) == rhs_engaged);
41 #ifndef TEST_HAS_NO_EXCEPTIONS
45 assert(is_going_to_throw);
55 X(X&& x) : i_(x.i_) {x.i_ = 0;}
57 friend bool operator==(const X& x, const X& y) {return x.i_ == y.i_;}
65 Y(Y&& x) noexcept : i_(x.i_) {x.i_ = 0;}
67 friend constexpr bool operator==(const Y& x, const Y& y) {return x.i_ == y.i_;}
83 friend constexpr bool operator==(const Z& x, const Z& y) {return x.i_ == y.i_;}
91 ConstMovable(int i) : i_(i) {}
92 ConstMovable(const ConstMovable&& x) : i_(x.i_) {}
93 ~ConstMovable() {i_ = 0;}
94 friend bool operator==(const ConstMovable& x, const ConstMovable& y) {return x.i_ == y.i_;}
121 optional<T> rhs(X(3));
125 typedef const ConstMovable T;
126 optional<T> rhs(ConstMovable(3));
136 optional<T> rhs(Y(3));
146 optional<T> rhs(Z(3));