feature/spaceship: Clause 32: Thread support#1590
feature/spaceship: Clause 32: Thread support#1590StephanTLavavej merged 2 commits intomicrosoft:feature/spaceshipfrom
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.
Would it make sense to default the operator== for C++20 and make them hidden friends?
There was a problem hiding this comment.
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.
|
|
||
| #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.
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.
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.