Debian Codegraph @

libcxx/test/std/utilities/expected/expected.unexpected/equality.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 E2>
11 // friend constexpr bool operator==(const unexpected& x, const unexpected<E2>& y);
12 //
13 // Mandates: The expression x.error() == y.error() is well-formed and its result is convertible to bool.
14 //
15 // Returns: x.error() == y.error().
16
17 #include <cassert>
18 #include <concepts>
19 #include <expected>
20 #include <utility>
21
22 struct Error{
23 int i;
24 friend constexpr bool operator==(const Error&, const Error&) = default;
25 };
26
27 constexpr bool test() {
28 std::unexpected<Error> unex1(Error{2});
29 std::unexpected<Error> unex2(Error{3});
30 std::unexpected<Error> unex3(Error{2});
31 assert(unex1 == unex3);
32 assert(unex1 != unex2);
33 assert(unex2 != unex3);
34 return true;
35 }
36
37 int main(int, char**) {
38 test();
39 static_assert(test());
40 return 0;
41 }