Skip to content

Commit e35c0a9

Browse files
committed
Update tests
1 parent c343b6c commit e35c0a9

3 files changed

Lines changed: 636 additions & 0 deletions

File tree

‎tests/unit/operator_comparison_defaulted.cpp‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,28 @@ struct OrdOnly {
2626
bool operator==(const OrdOnly &) const = delete;
2727
};
2828

29+
struct Inner {
30+
int x;
31+
auto operator<=>(const Inner &) const = default;
32+
};
33+
34+
struct Outer {
35+
Inner i;
36+
int y;
37+
auto operator<=>(const Outer &) const = default;
38+
};
39+
40+
// Secondary comparison operators can be defaulted too; they are defined as
41+
// rewrites of the primary ones: != as !(a == b), < and >= via (a <=> b).
42+
struct Secondary {
43+
int a;
44+
bool operator==(const Secondary &) const = default;
45+
bool operator!=(const Secondary &) const = default;
46+
auto operator<=>(const Secondary &) const = default;
47+
bool operator<(const Secondary &) const = default;
48+
bool operator>=(const Secondary &) const = default;
49+
};
50+
2951
int main() {
3052
Eq e1{1, 2}, e2{1, 2}, e3{1, 3};
3153
assert(e1 == e2);
@@ -41,5 +63,14 @@ int main() {
4163
OrdOnly o1{1}, o2{2};
4264
assert(o1 < o2);
4365
assert((o2 <=> o1) == std::strong_ordering::greater);
66+
Outer x1{{1}, 9}, x2{{2}, 0}, x3{{1}, 9};
67+
assert(x1 < x2);
68+
assert(x1 == x3);
69+
assert((x2 <=> x1) == std::strong_ordering::greater);
70+
Secondary s1{1}, s2{2};
71+
assert(s1 != s2);
72+
assert(s1 < s2);
73+
assert(s2 >= s1);
74+
assert(!(s2 < s1));
4475
return 0;
4576
}

0 commit comments

Comments
 (0)