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