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 T2> friend constexpr bool operator==(const expected& x, const T2& v); |
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<int, int>, int>); |
25 | static_assert(CanCompare<std::expected<int, int>, EqualityComparable>); |
26 | static_assert(!CanCompare<std::expected<int, int>, NonComparable>); |
27 | #endif |
28 | |
29 | constexpr bool test() { |
30 | // x.has_value() |
31 | { |
32 | const std::expected<EqualityComparable, int> e1(std::in_place, 5); |
33 | int i2 = 10; |
34 | int i3 = 5; |
35 | assert(e1 != i2); |
36 | assert(e1 == i3); |
37 | } |
38 | |
39 | // !x.has_value() |
40 | { |
41 | const std::expected<EqualityComparable, int> e1(std::unexpect, 5); |
42 | int i2 = 10; |
43 | int i3 = 5; |
44 | assert(e1 != i2); |
45 | assert(e1 != i3); |
46 | } |
47 | |
48 | return true; |
49 | } |
50 | |
51 | int main(int, char**) { |
52 | test(); |
53 | static_assert(test()); |
54 | return 0; |
55 | } |
56 | |