From 30a6ca2307d6237c61c50abf25a88f86aa6e7c2a Mon Sep 17 00:00:00 2001 From: Anthony Calandra Date: Sat, 5 Apr 2025 19:59:07 -0400 Subject: [PATCH] Make operator<=> friend. --- CPP20.md | 5 +++-- README.md | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CPP20.md b/CPP20.md index 790cf20..08dfabf 100644 --- a/CPP20.md +++ b/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; } }; diff --git a/README.md b/README.md index 2d8b88e..f4dfbae 100644 --- a/README.md +++ b/README.md @@ -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; } };