Skip to content

Commit d758ca3

Browse files
committed
Tests: operator== WIP
1 parent 8f7b9a8 commit d758ca3

File tree

2 files changed

+43
-19
lines changed

2 files changed

+43
-19
lines changed

libcxx/include/__functional/reference_wrapper.h

Lines changed: 1 addition & 10 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);
106-
return std::__synth_three_way(__x.get(), __y.get());
100+
return std::__synth_three_way(__x.get(), __y);
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: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,51 @@
2323
#include "test_macros.h"
2424

2525
constexpr bool test() {
26+
int i = 92;
27+
int j = 84;
28+
29+
// ==
30+
{
31+
// refwrap, refwrap
32+
std::reference_wrapper<int> rw1{i};
33+
std::reference_wrapper<int> rw2 = rw1;
34+
assert(rw1 == rw2);
35+
assert(rw2 == rw1);
36+
}
37+
{
38+
// refwrap, const&
39+
std::reference_wrapper<int> rw{i};
40+
assert(rw == i);
41+
assert(i == rw);
42+
}
43+
{
44+
// refwrap, refwrap<const>
45+
std::reference_wrapper<int> rw1{i};
46+
std::reference_wrapper<const int> rw2 = rw1;
47+
assert(rw1 == rw2);
48+
assert(rw2 == rw1);
49+
}
50+
51+
// !=
52+
{
53+
// refwrap, refwrap
54+
std::reference_wrapper<int> rw1{i};
55+
std::reference_wrapper<int> rw2{j};
56+
assert(rw1 != rw2);
57+
assert(rw2 != rw1);
58+
}
2659
{
27-
int i = 92;
28-
std::reference_wrapper<int> lhs{i};
29-
std::reference_wrapper<int> rhs = lhs;
30-
assert(lhs == rhs);
60+
// refwrap, const&
61+
std::reference_wrapper<int> rw{i};
62+
assert(rw != j);
63+
assert(j != rw);
3164
}
3265
{
33-
int i = 92;
34-
std::reference_wrapper<int> lhs{i};
35-
int j = 84;
36-
std::reference_wrapper<int> rhs{j};
37-
assert(lhs != rhs);
66+
// refwrap, refwrap<const>
67+
std::reference_wrapper<int> rw1{i};
68+
std::reference_wrapper<const int> rw2{j};
69+
assert(rw1 != rw2);
70+
assert(rw2 != rw1);
3871
}
3972

4073
return true;

0 commit comments

Comments
 (0)