From 7779439e284bf8a0534f606d5c7f929674764941 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 3 Mar 2024 12:59:57 +0100 Subject: [PATCH] Backported comparison operators to Array from godot4. --- core/variant/array.cpp | 27 +++++++++++++++++++++++++++ core/variant/array.h | 5 +++++ 2 files changed, 32 insertions(+) diff --git a/core/variant/array.cpp b/core/variant/array.cpp index 36929e6c0..ea418e9a9 100644 --- a/core/variant/array.cpp +++ b/core/variant/array.cpp @@ -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; } diff --git a/core/variant/array.h b/core/variant/array.h index 28e81df28..ea2168dd2 100644 --- a/core/variant/array.h +++ b/core/variant/array.h @@ -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);