Skip to content

Commit 3197da2

Browse files
committed
changed to return strong ordering results
1 parent 5ec03eb commit 3197da2

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

stl/inc/xstring

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4622,11 +4622,23 @@ _NODISCARD bool operator>=(const basic_string<_Elem, _Traits, _Alloc>& _Left, _I
46224622
template <class _Elem, class _Traits, class _Alloc>
46234623
_NODISCARD strong_ordering operator<=>(
46244624
const basic_string<_Elem, _Traits, _Alloc>& _Left, const basic_string<_Elem, _Traits, _Alloc>& _Right) noexcept {
4625-
return _Left.compare(_Right);
4625+
int _comparison = _Left.compare(_Right);
4626+
if (_comparison == 0) {
4627+
return strong_ordering::equivalent;
4628+
} else if (_comparison < 0) {
4629+
return strong_ordering::less;
4630+
}
4631+
return strong_ordering::greater;
46264632
}
46274633
template <class _Elem, class _Traits, class _Alloc>
46284634
_NODISCARD strong_ordering operator<=>(const basic_string<_Elem, _Traits, _Alloc>& _Left, const _Elem* _Right) {
4629-
return _Left.compare(_Right);
4635+
int _comparison = _Left.compare(_Right);
4636+
if (_comparison == 0) {
4637+
return strong_ordering::equivalent;
4638+
} else if (_comparison < 0) {
4639+
return strong_ordering::less;
4640+
}
4641+
return strong_ordering::greater;
46304642
}
46314643
#endif // _HAS_CXX20
46324644

tests/std/tests/P1614R2_spaceship/test.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -462,11 +462,11 @@ void ordering_test_cases() {
462462
std::string a5 = "abddef";
463463
std::string a6 = "abbdef";
464464

465-
assert((a1 <=> a2) == 0);
466-
assert((a1 <=> a3) == -1);
467-
assert((a1 <=> a4) == 1);
468-
assert((a1 <=> a5) == -1);
469-
assert((a1 <=> a6) == 1);
465+
assert((a1 <=> a2) == std::strong_ordering::equivalent);
466+
assert((a1 <=> a3) == std::strong_ordering::less);
467+
assert((a1 <=> a4) == std::strong_ordering::greater);
468+
assert((a1 <=> a5) == std::strong_ordering::less);
469+
assert((a1 <=> a6) == std::strong_ordering::greater);
470470

471471
assert(a1 == a2);
472472
assert(a1 >= a2);

0 commit comments

Comments
 (0)