Skip to content

Commit a17752d

Browse files
committed
_Get_comparison_category
1 parent 03d5ecc commit a17752d

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

stl/inc/xstring

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4619,26 +4619,23 @@ _NODISCARD bool operator>=(const basic_string<_Elem, _Traits, _Alloc>& _Left, _I
46194619
#endif // !_HAS_CXX20
46204620

46214621
#if _HAS_CXX20
4622+
template <class _Traits, class = void>
4623+
struct _Get_comparison_category {
4624+
using comparison_category = weak_ordering;
4625+
};
4626+
template <class _Traits>
4627+
struct _Get_comparison_category<_Traits, void_t<typename _Traits::comparison_category>> {
4628+
using comparison_category = typename _Traits::comparison_category;
4629+
};
46224630
template <class _Elem, class _Traits, class _Alloc>
4623-
_NODISCARD strong_ordering operator<=>(
4631+
_NODISCARD _Get_comparison_category<_Traits> operator<=>(
46244632
const basic_string<_Elem, _Traits, _Alloc>& _Left, const basic_string<_Elem, _Traits, _Alloc>& _Right) noexcept {
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;
4633+
return static_cast<_Get_comparison_category<_Traits>>(_Left.compare(_Right) <=> 0);
46324634
}
46334635
template <class _Elem, class _Traits, class _Alloc>
4634-
_NODISCARD strong_ordering operator<=>(const basic_string<_Elem, _Traits, _Alloc>& _Left, const _Elem* _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;
4636+
_NODISCARD _Get_comparison_category<_Traits> operator<=>(
4637+
const basic_string<_Elem, _Traits, _Alloc>& _Left, const _Elem* _Right) {
4638+
return static_cast<_Get_comparison_category<_Traits>>(_Left.compare(_Right) <=> 0);
46424639
}
46434640
#endif // _HAS_CXX20
46444641

0 commit comments

Comments
 (0)