diff --git a/Redcraft.Utility/Source/Public/Containers/Array.h b/Redcraft.Utility/Source/Public/Containers/Array.h index 26418b0..ddabc08 100644 --- a/Redcraft.Utility/Source/Public/Containers/Array.h +++ b/Redcraft.Utility/Source/Public/Containers/Array.h @@ -304,18 +304,15 @@ public: return true; } - /** Compares the contents of two arrays. */ + /** Compares the contents of 'LHS' and 'RHS' lexicographically. */ NODISCARD friend auto operator<=>(const TArray& LHS, const TArray& RHS) requires (CSynthThreeWayComparable) { using OrderingType = TSynthThreeWayResult; - if (LHS.Num() < RHS.Num()) return OrderingType::less; - if (LHS.Num() > RHS.Num()) return OrderingType::greater; - ConstIterator LHSIter = LHS.Begin(); ConstIterator RHSIter = RHS.Begin(); - while (LHSIter != LHS.End()) + while (LHSIter != LHS.End() || RHSIter != RHS.End()) { TSynthThreeWayResult Ordering = SynthThreeWayCompare(*LHSIter, *RHSIter); @@ -325,9 +322,7 @@ public: ++RHSIter; } - check(RHSIter == RHS.End()); - - return OrderingType::equivalent; + return LHS.Num() <=> RHS.Num(); } /** Inserts 'InValue' before 'Iter' in the container. */ diff --git a/Redcraft.Utility/Source/Public/Containers/StaticArray.h b/Redcraft.Utility/Source/Public/Containers/StaticArray.h index 90daa86..01f0195 100644 --- a/Redcraft.Utility/Source/Public/Containers/StaticArray.h +++ b/Redcraft.Utility/Source/Public/Containers/StaticArray.h @@ -62,18 +62,15 @@ public: return true; } - /** Compares the contents of two arrays. */ + /** Compares the contents of 'LHS' and 'RHS' lexicographically. */ NODISCARD friend constexpr auto operator<=>(const TStaticArray& LHS, const TStaticArray& RHS) requires (CSynthThreeWayComparable) { using OrderingType = TSynthThreeWayResult; - if (LHS.Num() < RHS.Num()) return OrderingType::less; - if (LHS.Num() > RHS.Num()) return OrderingType::greater; - ConstIterator LHSIter = LHS.Begin(); ConstIterator RHSIter = RHS.Begin(); - while (LHSIter != LHS.End()) + while (LHSIter != LHS.End() || RHSIter != RHS.End()) { TSynthThreeWayResult Ordering = SynthThreeWayCompare(*LHSIter, *RHSIter); @@ -83,9 +80,7 @@ public: ++RHSIter; } - check(RHSIter == RHS.End()); - - return OrderingType::equivalent; + return LHS.Num() <=> RHS.Num(); } /** @return The pointer to the underlying element storage. */