Backported comparison operators to Array from godot4.

This commit is contained in:
Relintai 2024-03-03 12:59:57 +01:00
parent 0f07cedf57
commit 7779439e28
2 changed files with 32 additions and 0 deletions

View File

@ -487,6 +487,33 @@ Variant Array::max() const {
return maxval;
}
bool Array::operator<(const Array &p_array) const {
int a_len = size();
int b_len = p_array.size();
int min_cmp = MIN(a_len, b_len);
for (int i = 0; i < min_cmp; i++) {
if (operator[](i) < p_array[i]) {
return true;
} else if (p_array[i] < operator[](i)) {
return false;
}
}
return a_len < b_len;
}
bool Array::operator<=(const Array &p_array) const {
return !operator>(p_array);
}
bool Array::operator>(const Array &p_array) const {
return p_array < *this;
}
bool Array::operator>=(const Array &p_array) const {
return !operator<(p_array);
}
const void *Array::id() const {
return _p;
}

View File

@ -103,6 +103,11 @@ public:
Variant min() const;
Variant max() const;
bool operator<(const Array &p_array) const;
bool operator<=(const Array &p_array) const;
bool operator>(const Array &p_array) const;
bool operator>=(const Array &p_array) const;
const void *id() const;
Array(const Array &p_from);