-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature/spaceship: Clause 32: Thread support #1590
feature/spaceship: Clause 32: Thread support #1590
Conversation
friend bool operator==(thread::id _Left, thread::id _Right) noexcept; | ||
#if _HAS_CXX20 | ||
friend strong_ordering operator<=>(thread::id _Left, thread::id _Right) noexcept; | ||
#else // ^^^ _HAS_CXX20 / !_HAS_CXX20 vvv | ||
friend bool operator<(thread::id _Left, thread::id _Right) noexcept; | ||
#endif // !_HAS_CXX20 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to default the operator==
for C++20 and make them hidden friends?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They can't be hidden friends; the difference is observable. Arguably operator==
also cannot be defaulted because doing so would make it constexpr
and we're forbidden to make things constexpr
where the Standard doesn't depict them as such.
@@ -237,6 +242,11 @@ _NODISCARD inline bool operator==(thread::id _Left, thread::id _Right) noexcept | |||
return _Left._Id == _Right._Id; | |||
} | |||
|
|||
#if _HAS_CXX20 | |||
_NODISCARD inline strong_ordering operator<=>(thread::id _Left, thread::id _Right) noexcept { | |||
return _Left._Id <=> _Right._Id; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fun fact: the Standard doesn't require the total ordering over thread ids that this function observes to be consistent with operator==
, so we could have the two functions order them differently ;)
(I've submitted an LWG issue to fix this.)
std::thread::id id1_equal; | ||
std::thread::id id2 = std::this_thread::get_id(); | ||
|
||
spaceship_test<std::strong_ordering>(id1, id1_equal, id2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe there's an implementation assumption here - nothing in the Standard appears to require that std::thread::id{}
occurs first in the unspecified total ordering. (It's a safe assumption for us, since we use 0
and store unsigned int
.) I'll push a comment.
Thanks for implementing and testing this Clause! 🛸 🧵 |
Works towards #62.