1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // UNSUPPORTED: c++98, c++03, c++11, c++14 10 // <optional> 11 12 // template <class T, class U> constexpr bool operator==(const optional<T>& x, const U& v); 13 // template <class T, class U> constexpr bool operator==(const U& v, const optional<T>& x); 14 15 #include <optional> 16 17 using std::optional; 18 19 struct X { 20 int i_; 21 22 constexpr X(int i) : i_(i) {} 23 }; 24 25 constexpr bool operator==(const X& lhs, const X& rhs) { 26 return lhs.i_ == rhs.i_; 27 } 28 29 int main() { 30 { 31 typedef X T; 32 typedef optional<T> O; 33 34 constexpr T val(2); 35 constexpr O o1; // disengaged 36 constexpr O o2{1}; // engaged 37 constexpr O o3{val}; // engaged 38 39 static_assert(!(o1 == T(1)), ""); 40 static_assert((o2 == T(1)), ""); 41 static_assert(!(o3 == T(1)), ""); 42 static_assert((o3 == T(2)), ""); 43 static_assert((o3 == val), ""); 44 45 static_assert(!(T(1) == o1), ""); 46 static_assert((T(1) == o2), ""); 47 static_assert(!(T(1) == o3), ""); 48 static_assert((T(2) == o3), ""); 49 static_assert((val == o3), ""); 50 } 51 { 52 using O = optional<int>; 53 constexpr O o1(42); 54 static_assert(o1 == 42l, ""); 55 static_assert(!(101l == o1), ""); 56 } 57 { 58 using O = optional<const int>; 59 constexpr O o1(42); 60 static_assert(o1 == 42, ""); 61 static_assert(!(101 == o1), ""); 62 } 63 } 64