Skip to content

Commit 65c8d4c

Browse files
committed
Tests: operator== WIP
1 parent c1d73fa commit 65c8d4c

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

libcxx/include/__functional/reference_wrapper.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,12 @@ class _LIBCPP_TEMPLATE_VIS reference_wrapper : public __weak_result_type<_Tp> {
7373
// [refwrap.comparisons], comparisons
7474

7575
friend constexpr bool operator==(reference_wrapper __x, reference_wrapper __y) {
76-
// Mandates: The expression x.get() == y.get() is well-formed and its result is convertible to bool.
7776
static_assert(is_convertible_v<decltype(__x.get() == __y.get()), bool>);
7877

7978
return __x.get() == __y.get();
8079
}
8180

8281
friend constexpr bool operator==(reference_wrapper __x, const _Tp& __y) {
83-
// Mandates: The expression x.get() == y is well-formed and its result is convertible to bool.
8482
static_assert(is_convertible_v<decltype(__x.get() == __y), bool>);
8583

8684
return __x.get() == __y;
@@ -89,29 +87,22 @@ class _LIBCPP_TEMPLATE_VIS reference_wrapper : public __weak_result_type<_Tp> {
8987
friend constexpr bool operator==(reference_wrapper __x, reference_wrapper<const _Tp> __y)
9088
requires(!is_const_v<_Tp>)
9189
{
92-
// Constraints: is_const_v<T> is false.
93-
// Mandates: The expression x.get() == y.get() is well-formed and its result is convertible to bool.
9490
static_assert(is_convertible_v<decltype(__x.get() == __y.get()), bool>);
9591

9692
return __x.get() == __y.get();
9793
}
9894

9995
friend constexpr __synth_three_way_result<_Tp> operator<=>(reference_wrapper __x, reference_wrapper __y) {
100-
// return __synth_three_way_result(x.get(), y.get());
10196
return std::__synth_three_way(__x.get(), __y.get());
10297
}
10398

10499
friend constexpr __synth_three_way_result<_Tp> operator<=>(reference_wrapper __x, const _Tp& __y) {
105-
// return __synth_three_way_result(__x.get(), __y);
106100
return std::__synth_three_way(__x.get(), __y.get());
107101
}
108102

109103
friend constexpr __synth_three_way_result<_Tp> operator<=>(reference_wrapper __x, reference_wrapper<const _Tp> __y)
110104
requires(!is_const_v<_Tp>)
111105
{
112-
// Constraints: is_const_v<T> is false.
113-
114-
// return __synth_three_way_result(__x.get(), __y.get());
115106
return std::__synth_three_way(__x.get(), __y.get());
116107
}
117108

libcxx/test/std/utilities/function.objects/refwrap/refwrap.comparissons/equal.pass.cpp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,39 @@
2323
#include "test_macros.h"
2424

2525
constexpr bool test() {
26+
int i = 92;
27+
int j = 84;
28+
29+
// ==
2630
{
27-
int i = 92;
2831
std::reference_wrapper<int> lhs{i};
2932
std::reference_wrapper<int> rhs = lhs;
3033
assert(lhs == rhs);
3134
}
3235
{
33-
int i = 92;
3436
std::reference_wrapper<int> lhs{i};
35-
int j = 84;
37+
assert(lhs == i);
38+
}
39+
{
40+
std::reference_wrapper<int> lhs{i};
41+
std::reference_wrapper<const int> rhs = lhs;
42+
assert(lhs == rhs);
43+
}
44+
// !=
45+
{
46+
std::reference_wrapper<int> lhs{i};
3647
std::reference_wrapper<int> rhs{j};
3748
assert(lhs != rhs);
3849
}
50+
{
51+
std::reference_wrapper<int> lhs{i};
52+
assert(lhs != j);
53+
}
54+
{
55+
std::reference_wrapper<int> lhs{i};
56+
std::reference_wrapper<const int> rhs{j};
57+
assert(lhs != rhs);
58+
}
3959

4060
return true;
4161
}

0 commit comments

Comments
 (0)