From 93d0ceb2b935d210ba91f35d08694bdac29e2c09 Mon Sep 17 00:00:00 2001 From: Redstone1024 <2824517378@qq.com> Date: Sun, 27 Oct 2024 21:59:01 +0800 Subject: [PATCH] fix(containers): fix TCountedIterator implementation --- .../Source/Public/Containers/Iterator.h | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Redcraft.Utility/Source/Public/Containers/Iterator.h b/Redcraft.Utility/Source/Public/Containers/Iterator.h index b66a60a..62f71dc 100644 --- a/Redcraft.Utility/Source/Public/Containers/Iterator.h +++ b/Redcraft.Utility/Source/Public/Containers/Iterator.h @@ -361,7 +361,7 @@ public: using ElementType = TIteratorElementType; # if DO_CHECK - FORCEINLINE constexpr TCountedIterator() requires (CDefaultConstructible) : Length(1), MaxLength(0) { }; + FORCEINLINE constexpr TCountedIterator() requires (CDefaultConstructible) : Length(1), MaxLength(0) { } # else FORCEINLINE constexpr TCountedIterator() requires (CDefaultConstructible) = default; # endif @@ -388,20 +388,21 @@ public: template requires (!CSameAs && CConvertibleTo && CAssignableFrom) FORCEINLINE constexpr TCountedIterator& operator=(TCountedIterator&& InValue) { Current = MoveTemp(InValue).GetBase(); Length = InValue.Num(); check_code({ MaxLength = InValue.MaxLength; }); return *this; } - template requires (CSentinelFor) - NODISCARD friend FORCEINLINE constexpr bool operator==(const TCountedIterator& LHS, const TCountedIterator& RHS) { return LHS.GetBase() == RHS.GetBase(); } + template J> + NODISCARD friend FORCEINLINE constexpr bool operator==(const TCountedIterator& LHS, const TCountedIterator& RHS) { return LHS.Length == RHS.Length; } - template requires (CSizedSentinelFor) - NODISCARD friend FORCEINLINE constexpr TCompareThreeWayResult operator<=>(const TCountedIterator& LHS, const TCountedIterator& RHS) { return LHS.GetBase() <=> RHS.GetBase(); } + template J> + NODISCARD friend FORCEINLINE constexpr strong_ordering operator<=>(const TCountedIterator& LHS, const TCountedIterator& RHS) { return LHS.Length <=> RHS.Length; } NODISCARD FORCEINLINE constexpr bool operator==(FDefaultSentinel) const& { return Length == static_cast(0); } NODISCARD FORCEINLINE constexpr strong_ordering operator<=>(FDefaultSentinel) const& { return static_cast(0) <=> Length; } - NODISCARD FORCEINLINE constexpr TIteratorReferenceType operator*() { CheckThis(true); return *Current; } - NODISCARD FORCEINLINE constexpr TIteratorReferenceType operator*() const { CheckThis(true); return *Current; } - NODISCARD FORCEINLINE constexpr TIteratorPointerType operator->() { CheckThis(true); return AddressOf(operator*()); } - NODISCARD FORCEINLINE constexpr TIteratorPointerType operator->() const { CheckThis(true); return AddressOf(operator*()); } + NODISCARD FORCEINLINE constexpr TIteratorReferenceType operator*() { CheckThis(true); return *Current; } + + NODISCARD FORCEINLINE constexpr TIteratorReferenceType operator*() const requires (CDereferenceable) { CheckThis(true); return *Current; } + + NODISCARD FORCEINLINE constexpr TIteratorPointerType operator->() const requires (CContiguousIterator) { CheckThis(true); return AddressOf(operator*()); } NODISCARD FORCEINLINE constexpr TIteratorReferenceType operator[](ptrdiff Index) const requires (CRandomAccessIterator) { TCountedIterator Temp = *this + Index; return *Temp; } @@ -420,7 +421,8 @@ public: NODISCARD FORCEINLINE constexpr TCountedIterator operator-(ptrdiff Offset) const requires (CRandomAccessIterator) { TCountedIterator Temp = *this; Temp -= Offset; return Temp; } - NODISCARD friend FORCEINLINE constexpr ptrdiff operator-(const TCountedIterator& LHS, const TCountedIterator& RHS) { LHS.CheckThis(); RHS.CheckThis(); return LHS.GetBase() - RHS.GetBase(); } + template J> + NODISCARD friend FORCEINLINE constexpr ptrdiff operator-(const TCountedIterator& LHS, const TCountedIterator& RHS) { LHS.CheckThis(); RHS.CheckThis(); return LHS.Length - RHS.Length; } NODISCARD friend FORCEINLINE constexpr ptrdiff operator-(const TCountedIterator& LHS, FDefaultSentinel) { CheckThis(); return -LHS.Num(); } NODISCARD friend FORCEINLINE constexpr ptrdiff operator-(FDefaultSentinel, const TCountedIterator& RHS) { CheckThis(); return RHS.Num(); }