fix(containers): fix operator== and operator<=> of TArray etc
This commit is contained in:
parent
389a72444b
commit
f644372642
@ -288,38 +288,22 @@ public:
|
|||||||
{
|
{
|
||||||
if (LHS.Num() != RHS.Num()) return false;
|
if (LHS.Num() != RHS.Num()) return false;
|
||||||
|
|
||||||
ConstIterator LHSIter = LHS.Begin();
|
for (size_t Index = 0; Index < LHS.Num(); ++Index)
|
||||||
ConstIterator RHSIter = RHS.Begin();
|
|
||||||
|
|
||||||
while (LHSIter != LHS.End())
|
|
||||||
{
|
{
|
||||||
if (*LHSIter != *RHSIter) return false;
|
if (LHS[Index] != RHS[Index]) return false;
|
||||||
|
|
||||||
++LHSIter;
|
|
||||||
++RHSIter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
check(RHSIter == RHS.End());
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compares the contents of 'LHS' and 'RHS' lexicographically. */
|
/** Compares the contents of 'LHS' and 'RHS' lexicographically. */
|
||||||
NODISCARD friend auto operator<=>(const TArray& LHS, const TArray& RHS) requires (CSynthThreeWayComparable<ElementType>)
|
NODISCARD friend auto operator<=>(const TArray& LHS, const TArray& RHS) requires (CSynthThreeWayComparable<ElementType>)
|
||||||
{
|
{
|
||||||
using OrderingType = TSynthThreeWayResult<ElementType>;
|
const size_t NumToCompare = LHS.Num() < RHS.Num() ? LHS.Num() : RHS.Num();
|
||||||
|
|
||||||
ConstIterator LHSIter = LHS.Begin();
|
for (size_t Index = 0; Index < NumToCompare; ++Index)
|
||||||
ConstIterator RHSIter = RHS.Begin();
|
|
||||||
|
|
||||||
while (LHSIter != LHS.End() || RHSIter != RHS.End())
|
|
||||||
{
|
{
|
||||||
TSynthThreeWayResult<ElementType> Ordering = SynthThreeWayCompare(*LHSIter, *RHSIter);
|
if (const auto Result = SynthThreeWayCompare(LHS[Index], RHS[Index]); Result != 0) return Result;
|
||||||
|
|
||||||
if (Ordering != OrderingType::equivalent) return Ordering;
|
|
||||||
|
|
||||||
++LHSIter;
|
|
||||||
++RHSIter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return LHS.Num() <=> RHS.Num();
|
return LHS.Num() <=> RHS.Num();
|
||||||
|
@ -134,46 +134,25 @@ public:
|
|||||||
{
|
{
|
||||||
if (LHS.Num() != RHS.Num()) return false;
|
if (LHS.Num() != RHS.Num()) return false;
|
||||||
|
|
||||||
Iterator LHSIter = LHS.Begin();
|
for (size_t Index = 0; Index < LHS.Num(); ++Index)
|
||||||
Iterator RHSIter = RHS.Begin();
|
|
||||||
|
|
||||||
while (LHSIter != LHS.End())
|
|
||||||
{
|
{
|
||||||
if (*LHSIter != *RHSIter) return false;
|
if (LHS[Index] != RHS[Index]) return false;
|
||||||
|
|
||||||
++LHSIter;
|
|
||||||
++RHSIter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
check(RHSIter == RHS.End());
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compares the contents of two array views. */
|
/** Compares the contents of two array views. */
|
||||||
NODISCARD friend constexpr auto operator<=>(TArrayView LHS, TArrayView RHS) requires (CSynthThreeWayComparable<ElementType>)
|
NODISCARD friend constexpr auto operator<=>(TArrayView LHS, TArrayView RHS) requires (CSynthThreeWayComparable<ElementType>)
|
||||||
{
|
{
|
||||||
using OrderingType = TSynthThreeWayResult<ElementType>;
|
const size_t NumToCompare = LHS.Num() < RHS.Num() ? LHS.Num() : RHS.Num();
|
||||||
|
|
||||||
if (LHS.Num() < RHS.Num()) return OrderingType::less;
|
for (size_t Index = 0; Index < NumToCompare; ++Index)
|
||||||
if (LHS.Num() > RHS.Num()) return OrderingType::greater;
|
|
||||||
|
|
||||||
Iterator LHSIter = LHS.Begin();
|
|
||||||
Iterator RHSIter = RHS.Begin();
|
|
||||||
|
|
||||||
while (LHSIter != LHS.End())
|
|
||||||
{
|
{
|
||||||
TSynthThreeWayResult<ElementType> Ordering = SynthThreeWayCompare(*LHSIter, *RHSIter);
|
if (const auto Result = SynthThreeWayCompare(LHS[Index], RHS[Index]); Result != 0) return Result;
|
||||||
|
|
||||||
if (Ordering != OrderingType::equivalent) return Ordering;
|
|
||||||
|
|
||||||
++LHSIter;
|
|
||||||
++RHSIter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
check(RHSIter == RHS.End());
|
return LHS.Num() <=> RHS.Num();
|
||||||
|
|
||||||
return OrderingType::equivalent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Obtains an array view that is a view over the first 'Count' elements of this array view. */
|
/** Obtains an array view that is a view over the first 'Count' elements of this array view. */
|
||||||
|
@ -46,38 +46,22 @@ public:
|
|||||||
{
|
{
|
||||||
if (LHS.Num() != RHS.Num()) return false;
|
if (LHS.Num() != RHS.Num()) return false;
|
||||||
|
|
||||||
ConstIterator LHSIter = LHS.Begin();
|
for (size_t Index = 0; Index < LHS.Num(); ++Index)
|
||||||
ConstIterator RHSIter = RHS.Begin();
|
|
||||||
|
|
||||||
while (LHSIter != LHS.End())
|
|
||||||
{
|
{
|
||||||
if (*LHSIter != *RHSIter) return false;
|
if (LHS[Index] != RHS[Index]) return false;
|
||||||
|
|
||||||
++LHSIter;
|
|
||||||
++RHSIter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
check(RHSIter == RHS.End());
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Compares the contents of 'LHS' and 'RHS' lexicographically. */
|
/** Compares the contents of 'LHS' and 'RHS' lexicographically. */
|
||||||
NODISCARD friend constexpr auto operator<=>(const TStaticArray& LHS, const TStaticArray& RHS) requires (CSynthThreeWayComparable<ElementType>)
|
NODISCARD friend constexpr auto operator<=>(const TStaticArray& LHS, const TStaticArray& RHS) requires (CSynthThreeWayComparable<ElementType>)
|
||||||
{
|
{
|
||||||
using OrderingType = TSynthThreeWayResult<ElementType>;
|
const size_t NumToCompare = LHS.Num() < RHS.Num() ? LHS.Num() : RHS.Num();
|
||||||
|
|
||||||
ConstIterator LHSIter = LHS.Begin();
|
for (size_t Index = 0; Index < NumToCompare; ++Index)
|
||||||
ConstIterator RHSIter = RHS.Begin();
|
|
||||||
|
|
||||||
while (LHSIter != LHS.End() || RHSIter != RHS.End())
|
|
||||||
{
|
{
|
||||||
TSynthThreeWayResult<ElementType> Ordering = SynthThreeWayCompare(*LHSIter, *RHSIter);
|
if (const auto Result = SynthThreeWayCompare(LHS[Index], RHS[Index]); Result != 0) return Result;
|
||||||
|
|
||||||
if (Ordering != OrderingType::equivalent) return Ordering;
|
|
||||||
|
|
||||||
++LHSIter;
|
|
||||||
++RHSIter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return LHS.Num() <=> RHS.Num();
|
return LHS.Num() <=> RHS.Num();
|
||||||
|
Loading…
Reference in New Issue
Block a user