Index: libcxx/include/compare =================================================================== --- libcxx/include/compare +++ libcxx/include/compare @@ -676,6 +676,23 @@ template constexpr strong_equality strong_equal(const _Tp& __lhs, const _Tp& __rhs); template constexpr weak_equality weak_equal(const _Tp& __lhs, const _Tp& __rhs); +#if !defined(_LIBCPP_HAS_NO_SPACESHIP_OPERATOR) +inline constexpr auto __synth_three_way = [](const T& t, const U& u) +{ + // TODO(cjdb): add requirements once boolean-testable is committed + if constexpr (requires { t <=> u; }) { + return t <=> u; + } else { + if (t < u) return weak_ordering::less; + if (u < t) return weak_ordering::greater; + return weak_ordering::equivalent; + } +}; + +template +using __synth_three_way_result = decltype(__synth_three_way(declval(), declval())); +#endif // _LIBCPP_HAS_NO_SPACESHIP_OPERATOR + #endif // _LIBCPP_STD_VER > 17 _LIBCPP_END_NAMESPACE_STD Index: libcxx/include/vector =================================================================== --- libcxx/include/vector +++ libcxx/include/vector @@ -249,12 +249,8 @@ template struct hash>; -template bool operator==(const vector& x, const vector& y); -template bool operator< (const vector& x, const vector& y); -template bool operator!=(const vector& x, const vector& y); -template bool operator> (const vector& x, const vector& y); -template bool operator>=(const vector& x, const vector& y); -template bool operator<=(const vector& x, const vector& y); +template bool operator== (const vector& x, const vector& y); +template bool operator<=>(const vector& x, const vector& y); template void swap(vector& x, vector& y) @@ -3340,6 +3336,15 @@ return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); } +#if !defined(_LIBCPP_HAS_NO_SPACESHIP_OPERATOR) +template +inline _LIBCPP_INLINE_VISIBILITY +__synth_three_way_result<_Tp> +operator<=>(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y) +{ + return _VSTD::lexicographical_compare_three_way(__x.begin(), __x.end(), __y.begin(), __y.end(), __synth_three_way); +} +#else template inline _LIBCPP_INLINE_VISIBILITY bool @@ -3379,6 +3384,7 @@ { return !(__y < __x); } +#endif // _ template inline _LIBCPP_INLINE_VISIBILITY