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++03, c++11, c++14, c++17, c++20 10 11 // template<class E2> friend constexpr bool operator==(const expected& x, const unexpected<E2>& e); 12 13 #include <cassert> 14 #include <concepts> 15 #include <expected> 16 #include <type_traits> 17 #include <utility> 18 19 #include "test_macros.h" 20 21 struct Data { 22 int i; 23 constexpr Data(int ii) : i(ii) {} 24 25 friend constexpr bool operator==(const Data& data, int ii) { return data.i == ii; } 26 }; 27 28 constexpr bool test() { 29 // x.has_value() 30 { 31 const std::expected<Data, Data> e1(std::in_place, 5); 32 std::unexpected<int> un2(10); 33 std::unexpected<int> un3(5); 34 assert(e1 != un2); 35 assert(e1 != un3); 36 } 37 38 // !x.has_value() 39 { 40 const std::expected<Data, Data> e1(std::unexpect, 5); 41 std::unexpected<int> un2(10); 42 std::unexpected<int> un3(5); 43 assert(e1 != un2); 44 assert(e1 == un3); 45 } 46 47 return true; 48 } 49 50 int main(int, char**) { 51 test(); 52 static_assert(test()); 53 return 0; 54 } 55