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, c++14
14 // explicit optional(const optional<U>& rhs);
17 #include <type_traits>
20 #include "test_macros.h"
24 template <class T, class U>
26 test(const optional<U>& rhs, bool is_going_to_throw = false)
28 static_assert(!(std::is_convertible<const optional<U>&, optional<T>>::value), "");
29 bool rhs_engaged = static_cast<bool>(rhs);
30 #ifndef TEST_HAS_NO_EXCEPTIONS
34 assert(is_going_to_throw == false);
35 assert(static_cast<bool>(lhs) == rhs_engaged);
37 assert(*lhs == T(*rhs));
44 if (is_going_to_throw) return;
46 assert(static_cast<bool>(lhs) == rhs_engaged);
48 assert(*lhs == T(*rhs));
56 explicit X(int i) : i_(i) {}
57 X(const X& x) : i_(x.i_) {}
59 friend bool operator==(const X& x, const X& y) {return x.i_ == y.i_;}
66 explicit Y(int i) : i_(i) {}
68 friend constexpr bool operator==(const Y& x, const Y& y) {return x.i_ == y.i_;}
77 explicit Z(int i) : i_(i) { TEST_THROW(6);}
79 friend constexpr bool operator==(const Z& x, const Z& y) {return x.i_ == y.i_;}