From 68f0d19cac936808261801b7210adf1d0be2c049 Mon Sep 17 00:00:00 2001 From: Redstone1024 <2824517378@qq.com> Date: Tue, 17 Dec 2024 15:51:35 +0800 Subject: [PATCH] fix(*): fix the implementation of iterator functions such as operator++(int) --- .../Source/Public/Iterator/MoveIterator.h | 2 +- .../Source/Public/Iterator/ReverseIterator.h | 4 ++-- Redcraft.Utility/Source/Public/Range/Factory.h | 18 +++++++++--------- .../Source/Public/Range/FilterView.h | 6 +++--- .../Source/Public/Range/TransformView.h | 6 +++--- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Redcraft.Utility/Source/Public/Iterator/MoveIterator.h b/Redcraft.Utility/Source/Public/Iterator/MoveIterator.h index 4a672e5..3993072 100644 --- a/Redcraft.Utility/Source/Public/Iterator/MoveIterator.h +++ b/Redcraft.Utility/Source/Public/Iterator/MoveIterator.h @@ -41,7 +41,7 @@ public: FORCEINLINE constexpr explicit TMoveIterator(FIteratorType InValue) : Current(MoveTemp(InValue)) { } template requires (!CSameAs && CConstructibleFrom) - FORCEINLINE constexpr explicit (!CConvertibleTo) TMoveIterator(const TReverseIterator& InValue) : Current(InValue.GetBase()) { } + FORCEINLINE constexpr explicit (!CConvertibleTo) TMoveIterator(const TMoveIterator& InValue) : Current(InValue.GetBase()) { } template requires (!CSameAs && CConvertibleTo && CAssignableFrom) FORCEINLINE constexpr TMoveIterator& operator=(const TMoveIterator& InValue) { Current = InValue.GetBase(); return *this; } diff --git a/Redcraft.Utility/Source/Public/Iterator/ReverseIterator.h b/Redcraft.Utility/Source/Public/Iterator/ReverseIterator.h index 41057cf..bb8f02d 100644 --- a/Redcraft.Utility/Source/Public/Iterator/ReverseIterator.h +++ b/Redcraft.Utility/Source/Public/Iterator/ReverseIterator.h @@ -59,8 +59,8 @@ public: FORCEINLINE constexpr TReverseIterator& operator++() { --Current; return *this; } FORCEINLINE constexpr TReverseIterator& operator--() { ++Current; return *this; } - FORCEINLINE constexpr TReverseIterator operator++(int) { TReverseIterator Temp = *this; --Current; return Temp; } - FORCEINLINE constexpr TReverseIterator operator--(int) { TReverseIterator Temp = *this; ++Current; return Temp; } + FORCEINLINE constexpr TReverseIterator operator++(int) { TReverseIterator Temp = *this; ++*this; return Temp; } + FORCEINLINE constexpr TReverseIterator operator--(int) { TReverseIterator Temp = *this; --*this; return Temp; } FORCEINLINE constexpr TReverseIterator& operator+=(ptrdiff Offset) requires (CRandomAccessIterator) { Current -= Offset; return *this; } FORCEINLINE constexpr TReverseIterator& operator-=(ptrdiff Offset) requires (CRandomAccessIterator) { Current += Offset; return *this; } diff --git a/Redcraft.Utility/Source/Public/Range/Factory.h b/Redcraft.Utility/Source/Public/Range/Factory.h index 2e11ed6..284e207 100644 --- a/Redcraft.Utility/Source/Public/Range/Factory.h +++ b/Redcraft.Utility/Source/Public/Range/Factory.h @@ -154,7 +154,7 @@ private: FORCEINLINE constexpr FIteratorImpl& operator++() { ++Value; return *this; } - FORCEINLINE constexpr FIteratorImpl operator++(int) { FIteratorImpl Temp = *this; ++Value; return Temp; } + FORCEINLINE constexpr FIteratorImpl operator++(int) { FIteratorImpl Temp = *this; ++*this; return Temp; } private: @@ -270,18 +270,18 @@ private: FORCEINLINE constexpr FIteratorImpl& operator++() { ++Current; return *this; } FORCEINLINE constexpr FIteratorImpl& operator--() { --Current; return *this; } - FORCEINLINE constexpr FIteratorImpl operator++(int) { FIteratorImpl Temp = *this; --Current; return Temp; } - FORCEINLINE constexpr FIteratorImpl operator--(int) { FIteratorImpl Temp = *this; ++Current; return Temp; } + FORCEINLINE constexpr FIteratorImpl operator++(int) { FIteratorImpl Temp = *this; ++*this; return Temp; } + FORCEINLINE constexpr FIteratorImpl operator--(int) { FIteratorImpl Temp = *this; --*this; return Temp; } - FORCEINLINE constexpr FIteratorImpl& operator+=(ptrdiff Offset) { Current -= Offset; return *this; } - FORCEINLINE constexpr FIteratorImpl& operator-=(ptrdiff Offset) { Current += Offset; return *this; } + FORCEINLINE constexpr FIteratorImpl& operator+=(ptrdiff Offset) { Current += Offset; return *this; } + FORCEINLINE constexpr FIteratorImpl& operator-=(ptrdiff Offset) { Current -= Offset; return *this; } - NODISCARD friend FORCEINLINE constexpr FIteratorImpl operator+(FIteratorImpl Iter, ptrdiff Offset) { FIteratorImpl Temp = Iter; Temp -= Offset; return Temp; } - NODISCARD friend FORCEINLINE constexpr FIteratorImpl operator+(ptrdiff Offset, FIteratorImpl Iter) { FIteratorImpl Temp = Iter; Temp -= Offset; return Temp; } + NODISCARD friend FORCEINLINE constexpr FIteratorImpl operator+(FIteratorImpl Iter, ptrdiff Offset) { FIteratorImpl Temp = Iter; Temp += Offset; return Temp; } + NODISCARD friend FORCEINLINE constexpr FIteratorImpl operator+(ptrdiff Offset, FIteratorImpl Iter) { FIteratorImpl Temp = Iter; Temp += Offset; return Temp; } - NODISCARD FORCEINLINE constexpr FIteratorImpl operator-(ptrdiff Offset) const { FIteratorImpl Temp = *this; Temp += Offset; return Temp; } + NODISCARD FORCEINLINE constexpr FIteratorImpl operator-(ptrdiff Offset) const { FIteratorImpl Temp = *this; Temp -= Offset; return Temp; } - NODISCARD friend FORCEINLINE constexpr ptrdiff operator-(const FIteratorImpl& LHS, const FIteratorImpl& RHS) { return RHS.Current - LHS.Current; } + NODISCARD friend FORCEINLINE constexpr ptrdiff operator-(const FIteratorImpl& LHS, const FIteratorImpl& RHS) { return LHS.Current - RHS.Current; } private: diff --git a/Redcraft.Utility/Source/Public/Range/FilterView.h b/Redcraft.Utility/Source/Public/Range/FilterView.h index f38a80f..1af6f07 100644 --- a/Redcraft.Utility/Source/Public/Range/FilterView.h +++ b/Redcraft.Utility/Source/Public/Range/FilterView.h @@ -106,9 +106,9 @@ private: return *this; } - FORCEINLINE constexpr void operator++(int) { Current++; } - FORCEINLINE constexpr FIteratorImpl operator++(int) requires (CForwardIterator>) { return FIteratorImpl(Owner, Current++); } - FORCEINLINE constexpr FIteratorImpl operator--(int) requires (CBidirectionalIterator>) { return FIteratorImpl(Owner, Current--); } + FORCEINLINE constexpr void operator++(int) { ++*this; } + FORCEINLINE constexpr FIteratorImpl operator++(int) requires (CForwardIterator>) { FIteratorImpl Temp = *this; ++*this; return Temp; } + FORCEINLINE constexpr FIteratorImpl operator--(int) requires (CBidirectionalIterator>) { FIteratorImpl Temp = *this; --*this; return Temp; } NODISCARD FORCEINLINE constexpr const TRangeIterator& GetBase() const& { return Current; } NODISCARD FORCEINLINE constexpr TRangeIterator GetBase() && { return MoveTemp(Current); } diff --git a/Redcraft.Utility/Source/Public/Range/TransformView.h b/Redcraft.Utility/Source/Public/Range/TransformView.h index d5c0d50..2ca46d7 100644 --- a/Redcraft.Utility/Source/Public/Range/TransformView.h +++ b/Redcraft.Utility/Source/Public/Range/TransformView.h @@ -114,9 +114,9 @@ private: FORCEINLINE constexpr FIteratorImpl& operator++() { ++Current; return *this; } FORCEINLINE constexpr FIteratorImpl& operator--() requires (CBidirectionalRange) { --Current; return *this; } - FORCEINLINE constexpr void operator++(int) { Current++; } - FORCEINLINE constexpr FIteratorImpl operator++(int) requires (CForwardRange) { return FIteratorImpl(Current++); } - FORCEINLINE constexpr FIteratorImpl operator--(int) requires (CBidirectionalRange) { return FIteratorImpl(Current--); } + FORCEINLINE constexpr void operator++(int) { ++*this; } + FORCEINLINE constexpr FIteratorImpl operator++(int) requires (CForwardRange) { FIteratorImpl Temp = *this; ++*this; return Temp; } + FORCEINLINE constexpr FIteratorImpl operator--(int) requires (CBidirectionalRange) { FIteratorImpl Temp = *this; --*this; return Temp; } FORCEINLINE constexpr FIteratorImpl& operator+=(ptrdiff Offset) requires (CRandomAccessRange) { Current += Offset; return *this; } FORCEINLINE constexpr FIteratorImpl& operator-=(ptrdiff Offset) requires (CRandomAccessRange) { Current -= Offset; return *this; }