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 | #include "../../types.h" |
21 | |
22 | #if TEST_STD_VER >= 26 |
23 | // https://wg21.link/P3379R0 |
24 | static_assert(CanCompare<std::expected<EqualityComparable, EqualityComparable>, std::unexpected<int>>); |
25 | static_assert(CanCompare<std::expected<EqualityComparable, int>, std::unexpected<EqualityComparable>>); |
26 | static_assert(!CanCompare<std::expected<EqualityComparable, NonComparable>, std::unexpected<int>>); |
27 | #endif |
28 | |
29 | constexpr bool test() { |
30 | // x.has_value() |
31 | { |
32 | const std::expected<EqualityComparable, EqualityComparable> e1(std::in_place, 5); |
33 | std::unexpected<int> un2(10); |
34 | std::unexpected<int> un3(5); |
35 | assert(e1 != un2); |
36 | assert(e1 != un3); |
37 | } |
38 | |
39 | // !x.has_value() |
40 | { |
41 | const std::expected<EqualityComparable, EqualityComparable> e1(std::unexpect, 5); |
42 | std::unexpected<int> un2(10); |
43 | std::unexpected<int> un3(5); |
44 | assert(e1 != un2); |
45 | assert(e1 == un3); |
46 | } |
47 | |
48 | return true; |
49 | } |
50 | |
51 | int main(int, char**) { |
52 | test(); |
53 | static_assert(test()); |
54 | return 0; |
55 | } |
56 | |