mirror of
https://github.com/EnderIce2/Fennix.git
synced 2025-07-01 18:39:16 +00:00
feat(kernel/std): ✨ add three way compare for std::basic_string and std::vector
This commit is contained in:
@ -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>
|
||||
|
Reference in New Issue
Block a user