0

Document that operator== and <=> can be defaulted inline

This was the conclusion of the cxx thread, and seeing people jump
through hoops to write and export these from the .cc file because
there's no guidance saying otherwise outside the thread.

https://groups.google.com/a/chromium.org/g/cxx/c/h4lVi2jHU-0/m/4M4cKcBtAgAJ

R=pkasting@chromium.org

Change-Id: I15d75a531a246b773fe52a2bca1608253b3cc3fd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5258880
Reviewed-by: Peter Kasting <pkasting@chromium.org>
Commit-Queue: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1255629}
This commit is contained in:
danakj
2024-02-02 17:31:33 +00:00
committed by Chromium LUCI CQ
parent 2b2453dd57
commit 4b9193eb41

@ -1646,9 +1646,15 @@ concepts, then enforcing them on template arguments.
```c++
class S : public T {
// Non-member equality operator with access to private members.
// Compares `T` bases, then `x`, then `y`, short-circuiting.
// Compares `T` bases, then `x`, then `y`, short-circuiting when
// it finds inequality.
friend bool operator==(const S&, const S&) = default;
// Non-member ordering operator with access to private members.
// Compares `T` bases, then `x`, then `y`, short-circuiting when
// it finds an ordering difference.
friend auto operator<=>(const S&, const S&) = default;
int x;
bool y;
};
@ -1665,7 +1671,13 @@ the address of any non-declared operator.
**Notes:**
*** promo
[Migration bug](https://crbug.com/1414530)
Unlike constructors/destructors, our compiler extensions do not require these
to be written out-of-line in the .cc file. Feel free to write `= default`
directly in the header, as this is much simpler to write.
- [Migration bug](https://crbug.com/1414530)
- [Discussion thread](https://groups.google.com/a/chromium.org/g/cxx/c/JVN4E4IIYA0)
***
### Designated initializers <sup>[allowed]</sup>