1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
11 // template<class T2, class E2> requires (is_void_v<T2>)
12 // friend constexpr bool operator==(const expected& x, const expected<T2, E2>& y);
17 #include <type_traits>
20 #include "test_macros.h"
23 template <class T1
, class T2
>
24 concept CanCompare
= requires(T1 t1
, T2 t2
) { t1
== t2
; };
27 static_assert(!CanCompare
<Foo
, Foo
>);
29 static_assert(CanCompare
<std::expected
<void, int>, std::expected
<void, int>>);
30 static_assert(CanCompare
<std::expected
<void, int>, std::expected
<void, short>>);
32 // Note this is true because other overloads in expected<non-void> are unconstrained
33 static_assert(CanCompare
<std::expected
<void, int>, std::expected
<int, int>>);
35 constexpr bool test() {
36 // x.has_value() && y.has_value()
38 const std::expected
<void, int> e1
;
39 const std::expected
<void, int> e2
;
43 // !x.has_value() && y.has_value()
45 const std::expected
<void, int> e1(std::unexpect
, 5);
46 const std::expected
<void, int> e2
;
50 // x.has_value() && !y.has_value()
52 const std::expected
<void, int> e1
;
53 const std::expected
<void, int> e2(std::unexpect
, 10);
54 const std::expected
<void, int> e3(std::unexpect
, 5);
59 // !x.has_value() && !y.has_value()
61 const std::expected
<void, int> e1(std::unexpect
, 5);
62 const std::expected
<void, int> e2(std::unexpect
, 10);
63 const std::expected
<void, int> e3(std::unexpect
, 5);
71 int main(int, char**) {
73 static_assert(test());