1//===----------------------------------------------------------------------===//
2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3// See https://llvm.org/LICENSE.txt for license information.
4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5//
6//===----------------------------------------------------------------------===//
7
8// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
9
10// template<class E2> friend constexpr bool operator==(const expected& x, const unexpected<E2>& e);
11
12#include <cassert>
13#include <concepts>
14#include <expected>
15#include <type_traits>
16#include <utility>
17
18#include "test_macros.h"
19
20struct Data {
21 int i;
22 constexpr Data(int ii) : i(ii) {}
23
24 friend constexpr bool operator==(const Data& data, int ii) { return data.i == ii; }
25};
26
27constexpr bool test() {
28 // x.has_value()
29 {
30 const std::expected<Data, Data> e1(std::in_place, 5);
31 std::unexpected<int> un2(10);
32 std::unexpected<int> un3(5);
33 assert(e1 != un2);
34 assert(e1 != un3);
35 }
36
37 // !x.has_value()
38 {
39 const std::expected<Data, Data> e1(std::unexpect, 5);
40 std::unexpected<int> un2(10);
41 std::unexpected<int> un3(5);
42 assert(e1 != un2);
43 assert(e1 == un3);
44 }
45
46 return true;
47}
48
49int main(int, char**) {
50 test();
51 static_assert(test());
52 return 0;
53}
54

source code of libcxx/test/std/utilities/expected/expected.expected/equality/equality.unexpected.pass.cpp