Debian Codegraph @

libcxx/test/std/utilities/expected/expected.expected/equality/equality.T2.pass.cpp

raw
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 T2> friend constexpr bool operator==(const expected& x, const T2& v);
11
12 #include <cassert>
13 #include <concepts>
14 #include <expected>
15 #include <type_traits>
16 #include <utility>
17
18 #include "test_macros.h"
19
20 struct 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
27 constexpr bool test() {
28 // x.has_value()
29 {
30 const std::expected<Data, int> e1(std::in_place, 5);
31 int i2 = 10;
32 int i3 = 5;
33 assert(e1 != i2);
34 assert(e1 == i3);
35 }
36
37 // !x.has_value()
38 {
39 const std::expected<Data, int> e1(std::unexpect, 5);
40 int i2 = 10;
41 int i3 = 5;
42 assert(e1 != i2);
43 assert(e1 != i3);
44 }
45
46 return true;
47 }
48
49 int main(int, char**) {
50 test();
51 static_assert(test());
52 return 0;
53 }