fix mac build, try 42
MODIFY
util/spaceship.h
util/spaceship.h
namespace {
template <typename T>
-std::weak_ordering operator<=>(const std::vector<T> &lhs,
- const std::vector<T> &rhs) {
- auto sz = lhs.size() <=> rhs.size();
- if (std::is_neq(sz))
- return sz;
-
- auto I = rhs.begin();
- for (const auto &e : lhs) {
- auto cmp = e <=> *I++;
+std::weak_ordering compare_iterators(T &&I, const T &E, T &&II, const T &EE) {
+ while (I != E && II != EE) {
+ auto cmp = *I <=> *II;
if (std::is_neq(cmp))
return cmp;
+ ++I, ++II;
}
- return std::weak_ordering::equivalent;
+ if (I == E)
+ return II == EE ? std::weak_ordering::equivalent : std::weak_ordering::less;
+ return std::weak_ordering::greater;
+}
+
+template <typename T>
+std::weak_ordering operator<=>(const std::vector<T> &lhs,
+ const std::vector<T> &rhs) {
+ return compare_iterators(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
+}
+
+template <typename T>
+std::weak_ordering operator<=>(const std::set<T> &lhs, const std::set<T> &rhs) {
+ return compare_iterators(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
}
template <typename K, typename V>
std::weak_ordering operator<=>(const std::map<K,V> &lhs,
const std::map<K,V> &rhs) {
- auto sz = lhs.size() <=> rhs.size();
- if (std::is_neq(sz))
- return sz;
-
- auto I = rhs.begin();
- for (const auto &[k,v] : lhs) {
- if (auto cmp = k <=> I->first;
- std::is_neq(cmp))
- return cmp;
- if (auto cmp = v <=> I->second;
- std::is_neq(cmp))
- return cmp;
- ++I;
+ return compare_iterators(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
}
- return std::weak_ordering::equivalent;
+
+template <typename X, typename Y>
+std::weak_ordering operator<=>(const std::pair<X,Y> &lhs,
+ const std::pair<X,Y> &rhs) {
+ return compare_iterators(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
+}
+
}
+static inline
+std::weak_ordering operator<=>(const std::string &lhs, const std::string &rhs) {
+ auto cmp = lhs.compare(rhs);
+ if (cmp == 0)
+ return std::weak_ordering::equivalent;
+ return cmp < 0 ? std::weak_ordering::less : std::weak_ordering::equivalent;
}
#endif

fix mac build, try 42