mirror of
https://github.com/AnthonyCalandra/modern-cpp-features.git
synced 2025-12-16 17:47:02 +03:00
Make operator<=> friend.
This commit is contained in:
5
CPP20.md
5
CPP20.md
@@ -260,7 +260,7 @@ struct foo {
|
||||
char c;
|
||||
|
||||
// Compare `a` first, then `b`, then `c` ...
|
||||
auto operator<=>(const foo&) const = default;
|
||||
friend auto operator<=>(const foo&) const = default;
|
||||
};
|
||||
|
||||
foo f1{0, false, 'a'}, f2{0, true, 'b'};
|
||||
@@ -275,7 +275,8 @@ struct foo {
|
||||
int x;
|
||||
bool b;
|
||||
char c;
|
||||
std::strong_ordering operator<=>(const foo& other) const {
|
||||
|
||||
friend std::strong_ordering operator<=>(const foo& other) const {
|
||||
return x <=> other.x;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -364,7 +364,7 @@ struct foo {
|
||||
char c;
|
||||
|
||||
// Compare `a` first, then `b`, then `c` ...
|
||||
auto operator<=>(const foo&) const = default;
|
||||
friend auto operator<=>(const foo&) const = default;
|
||||
};
|
||||
|
||||
foo f1{0, false, 'a'}, f2{0, true, 'b'};
|
||||
@@ -379,7 +379,8 @@ struct foo {
|
||||
int x;
|
||||
bool b;
|
||||
char c;
|
||||
std::strong_ordering operator<=>(const foo& other) const {
|
||||
|
||||
friend std::strong_ordering operator<=>(const foo& other) const {
|
||||
return x <=> other.x;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user