From c889c0329caad7890480c3e3103b49830b8cb7e3 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 3 Nov 2023 13:08:26 +1100 Subject: [PATCH] Replace std::lexicographical_compare_three_way with custom code On latest MacOS this function is still not implemented --- src/string.hh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/string.hh b/src/string.hh index ec199d4c1..b6b313a13 100644 --- a/src/string.hh +++ b/src/string.hh @@ -343,8 +343,15 @@ inline bool operator==(const StringView& lhs, const StringView& rhs) inline auto operator<=>(const StringView& lhs, const StringView& rhs) { - return std::lexicographical_compare_three_way(lhs.begin(), lhs.end(), - rhs.begin(), rhs.end()); + auto lit = lhs.begin(), lend = lhs.end(), rit = rhs.begin(), rend = rhs.end(); + while (lit != lend and rit != rend) { + if (auto cmp = *lit++ <=> *rit++; cmp != 0) + return cmp; + } + if (lit == lend and rit == rend) + return std::strong_ordering::equal; + return lit == lend ? std::strong_ordering::less : std::strong_ordering::greater; + } inline String operator"" _str(const char* str, size_t)