feat(kernel/std): add three way compare for std::basic_string and std::vector

This commit is contained in:
2025-05-10 16:32:54 +00:00
parent dbb5a483e0
commit 9626ec4662
2 changed files with 37 additions and 8 deletions

View File

@ -21,6 +21,7 @@
#include <stdexcept>
#include <algorithm>
#include <iterator>
#include <compare>
#include <memory>
namespace std
@ -984,17 +985,32 @@ namespace std
constexpr bool operator==(const std::vector<T, Alloc> &lhs, const std::vector<T, Alloc> &rhs)
{
if (lhs.size() != rhs.size())
{
return false;
}
for (size_t i = 0; i < lhs.size(); i++)
return std::equal(lhs.begin(), lhs.end(), rhs.begin());
}
template <class T, class Alloc>
constexpr auto operator<=>(const std::vector<T, Alloc> &lhs, const std::vector<T, Alloc> &rhs)
{
// return std::lexicographical_compare_three_way(lhs.begin(), lhs.end(), rhs.begin(), rhs.end(), __synth_three_way);
auto it1 = lhs.begin();
auto it2 = rhs.begin();
while (it1 != lhs.end() && it2 != rhs.end())
{
if (lhs[i] != rhs[i])
{
return false;
}
if (*it1 < *it2)
return std::strong_ordering::less;
if (*it1 > *it2)
return std::strong_ordering::greater;
++it1;
++it2;
}
return true;
if (it1 == lhs.end() && it2 == rhs.end())
return std::strong_ordering::equal;
return (it1 == lhs.end()) ? std::strong_ordering::less : std::strong_ordering::greater;
}
template <class T, class Alloc>