From 8eab5e65386d74346e8a1a51bcb683eab082e5e8 Mon Sep 17 00:00:00 2001 From: Redstone1024 <2824517378@qq.com> Date: Sun, 15 Dec 2024 16:19:45 +0800 Subject: [PATCH] fix(iterator): fix requires on some iterator adapter member functions --- Redcraft.Utility/Source/Public/Iterator/MoveIterator.h | 7 ++++--- Redcraft.Utility/Source/Public/Iterator/ReverseIterator.h | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Redcraft.Utility/Source/Public/Iterator/MoveIterator.h b/Redcraft.Utility/Source/Public/Iterator/MoveIterator.h index 69d9721..b83d5c1 100644 --- a/Redcraft.Utility/Source/Public/Iterator/MoveIterator.h +++ b/Redcraft.Utility/Source/Public/Iterator/MoveIterator.h @@ -30,7 +30,8 @@ public: using ElementType = TIteratorElement; - FORCEINLINE constexpr TMoveIterator() = default; + FORCEINLINE constexpr TMoveIterator() requires (CDefaultConstructible) = default; + FORCEINLINE constexpr TMoveIterator(const TMoveIterator&) = default; FORCEINLINE constexpr TMoveIterator(TMoveIterator&&) = default; FORCEINLINE constexpr TMoveIterator& operator=(const TMoveIterator&) = default; @@ -45,7 +46,7 @@ public: template requires (!CSameAs && CConvertibleTo && CAssignableFrom) FORCEINLINE constexpr TMoveIterator& operator=(const TMoveIterator& InValue) { Current = InValue.GetBase(); return *this; } - template requires (CSentinelFor) + template requires (CEqualityComparable) NODISCARD friend FORCEINLINE constexpr bool operator==(const TMoveIterator& LHS, const TMoveIterator& RHS) { return LHS.GetBase() == RHS.GetBase(); } template requires (CThreeWayComparable) @@ -70,7 +71,7 @@ public: NODISCARD friend FORCEINLINE constexpr TMoveIterator operator+(ptrdiff Offset, const TMoveIterator& Iter) requires (CRandomAccessIterator) { return Iter + Offset; } - NODISCARD friend FORCEINLINE constexpr ptrdiff operator-(const TMoveIterator& LHS, const TMoveIterator& RHS) requires (CRandomAccessIterator) { return LHS.GetBase() - RHS.GetBase(); } + NODISCARD friend FORCEINLINE constexpr ptrdiff operator-(const TMoveIterator& LHS, const TMoveIterator& RHS) requires (CSizedSentinelFor) { return LHS.GetBase() - RHS.GetBase(); } NODISCARD FORCEINLINE constexpr const IteratorType& GetBase() const& { return Current; } NODISCARD FORCEINLINE constexpr IteratorType GetBase() && { return MoveTemp(Current); } diff --git a/Redcraft.Utility/Source/Public/Iterator/ReverseIterator.h b/Redcraft.Utility/Source/Public/Iterator/ReverseIterator.h index 061b239..627e27b 100644 --- a/Redcraft.Utility/Source/Public/Iterator/ReverseIterator.h +++ b/Redcraft.Utility/Source/Public/Iterator/ReverseIterator.h @@ -44,7 +44,7 @@ public: template requires (!CSameAs && CConvertibleTo && CAssignableFrom) FORCEINLINE constexpr TReverseIterator& operator=(const TReverseIterator& InValue) { Current = InValue.GetBase(); return *this; } - template requires (CSentinelFor) + template requires (CEqualityComparable) NODISCARD friend FORCEINLINE constexpr bool operator==(const TReverseIterator& LHS, const TReverseIterator& RHS) { return LHS.GetBase() == RHS.GetBase(); } template requires (CThreeWayComparable) @@ -70,7 +70,7 @@ public: NODISCARD friend FORCEINLINE constexpr TReverseIterator operator+(ptrdiff Offset, const TReverseIterator& Iter) requires (CRandomAccessIterator) { return Iter + Offset; } - NODISCARD friend FORCEINLINE constexpr ptrdiff operator-(const TReverseIterator& LHS, const TReverseIterator& RHS) requires (CRandomAccessIterator) { return RHS.GetBase() - LHS.GetBase(); } + NODISCARD friend FORCEINLINE constexpr ptrdiff operator-(const TReverseIterator& LHS, const TReverseIterator& RHS) requires (CSizedSentinelFor) { return RHS.GetBase() - LHS.GetBase(); } NODISCARD FORCEINLINE constexpr const IteratorType& GetBase() const& { return Current; } NODISCARD FORCEINLINE constexpr IteratorType GetBase() && { return MoveTemp(Current); }