diff --git a/stl/inc/thread b/stl/inc/thread index 2d46b78936d..60c41a0fb6d 100644 --- a/stl/inc/thread +++ b/stl/inc/thread @@ -14,6 +14,7 @@ #include #include #if _HAS_CXX20 +#include #include #endif // _HAS_CXX20 @@ -215,7 +216,11 @@ private: friend thread::id thread::get_id() const noexcept; friend thread::id this_thread::get_id() noexcept; 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 template friend basic_ostream<_Ch, _Tr>& operator<<(basic_ostream<_Ch, _Tr>& _Str, thread::id _Id); friend hash; @@ -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; +} +#else // ^^^ _HAS_CXX20 / !_HAS_CXX20 vvv _NODISCARD inline bool operator!=(thread::id _Left, thread::id _Right) noexcept { return !(_Left == _Right); } @@ -256,6 +266,7 @@ _NODISCARD inline bool operator>(thread::id _Left, thread::id _Right) noexcept { _NODISCARD inline bool operator>=(thread::id _Left, thread::id _Right) noexcept { return !(_Left < _Right); } +#endif // !_HAS_CXX20 template basic_ostream<_Ch, _Tr>& operator<<(basic_ostream<_Ch, _Tr>& _Str, thread::id _Id) { diff --git a/tests/std/tests/P1614R2_spaceship/test.cpp b/tests/std/tests/P1614R2_spaceship/test.cpp index 84160c9ece7..734bf99f7de 100644 --- a/tests/std/tests/P1614R2_spaceship/test.cpp +++ b/tests/std/tests/P1614R2_spaceship/test.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -481,6 +482,14 @@ void ordering_test_cases() { spaceship_test(c_mem[0], c_mem[0], c_mem[1]); } + { // thread::id + std::thread::id id1; + std::thread::id id1_equal; + std::thread::id id2 = std::this_thread::get_id(); + + // Implementation-specific assumption: std::thread::id{} occurs first in the unspecified total ordering. + spaceship_test(id1, id1_equal, id2); + } } template