| 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 |
|
| 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<void, Data> e1; |
| 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<void, 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 |
|
| 49 |
int main(int, char**) { |
| 50 |
test(); |
| 51 |
static_assert(test()); |
| 52 |
return 0; |
| 53 |
} |