diff --git a/Redcraft.Utility/Source/Private/Testing/StringTesting.cpp b/Redcraft.Utility/Source/Private/Testing/StringTesting.cpp index a86e148..03cd141 100644 --- a/Redcraft.Utility/Source/Private/Testing/StringTesting.cpp +++ b/Redcraft.Utility/Source/Private/Testing/StringTesting.cpp @@ -259,10 +259,10 @@ void TestStringView() always_check(ViewI == LITERAL(T, "Hello, World! Goodbye, World!")); always_check(ViewII == LITERAL(T, "Hello, World! Goodbye, World!")); - TStringView ViewA(ViewI.Begin(), 13); - TStringView ViewB(ViewI.Begin(), ViewI.End()); - TStringView ViewC(&Buffer[0], 13); - TStringView ViewD(&Buffer[0]); + TStringView ViewA(ViewI.Begin(), 13); + TStringView ViewB(ViewI.Begin(), ViewI.End()); + TStringView ViewC(&Buffer[0], 13); + TStringView ViewD(&Buffer[0]); always_check(ViewA == LITERAL(T, "Hello, World!")); always_check(ViewB == LITERAL(T, "Hello, World! Goodbye, World!")); @@ -335,10 +335,11 @@ void TestTemplateString() always_check(TStringView(Empty.ToCString()) == LITERAL(T, "")); TString StrA(32, LITERAL(T, 'A')); - TString StrB(LITERAL(T, "ABCDEFG"), 3); - TString StrC(LITERAL(T, "ABCDEFG")); - TString StrD(TStringView(LITERAL(T, "ABCDEFG"))); - TString StrE({ LITERAL(T, 'A'), LITERAL(T, 'B'), LITERAL(T, 'C') }); + + TString StrB(LITERAL(T, "ABCDEFG"), 3); + TString StrC(LITERAL(T, "ABCDEFG")); + TString StrD(TStringView(LITERAL(T, "ABCDEFG"))); + TString StrE({ LITERAL(T, 'A'), LITERAL(T, 'B'), LITERAL(T, 'C') }); always_check(TStringView(StrA.ToCString()) == LITERAL(T, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")); always_check(TStringView(StrB.ToCString()) == LITERAL(T, "ABC")); @@ -346,11 +347,11 @@ void TestTemplateString() always_check(TStringView(StrD.ToCString()) == LITERAL(T, "ABCDEFG")); always_check(TStringView(StrE.ToCString()) == LITERAL(T, "ABC")); - TString StrI(StrC); - TString StrII(MoveTemp(StrC)); + TString StrI(StrC); + TString StrII(MoveTemp(StrC)); - TString StrIII = Empty; - TString StrIV = Empty; + TString StrIII = Empty; + TString StrIV = Empty; StrIII = StrD; StrIV = MoveTemp(StrD); @@ -370,7 +371,7 @@ void TestTemplateString() } { - TString Str = LITERAL(T, "A"); + TString Str = LITERAL(T, "A"); always_check(!Str.IsEmpty()); always_check(Str.Num() == 1); @@ -398,7 +399,7 @@ void TestTemplateString() } { - TString Str = LITERAL(T, "##"); + TString Str = LITERAL(T, "##"); Str.Insert(1, LITERAL(T, 'A')); @@ -418,7 +419,7 @@ void TestTemplateString() } { - TString Str = LITERAL(T, "A"); + TString Str = LITERAL(T, "A"); Str.PushBack(LITERAL(T, 'B')); diff --git a/Redcraft.Utility/Source/Public/Containers/Array.h b/Redcraft.Utility/Source/Public/Containers/Array.h index 637e8ff..424a0be 100644 --- a/Redcraft.Utility/Source/Public/Containers/Array.h +++ b/Redcraft.Utility/Source/Public/Containers/Array.h @@ -23,8 +23,8 @@ class TArray final { private: - template - class IteratorImpl; + template > + class TIteratorImpl; public: @@ -34,8 +34,8 @@ public: using Reference = T&; using ConstReference = const T&; - using Iterator = IteratorImpl; - using ConstIterator = IteratorImpl; + using Iterator = TIteratorImpl; + using ConstIterator = TIteratorImpl; using ReverseIterator = TReverseIterator< Iterator>; using ConstReverseIterator = TReverseIterator; @@ -975,56 +975,56 @@ private: private: - template - class IteratorImpl + template + class TIteratorImpl { public: - using ElementType = TConditional; + using ElementType = TRemoveCV; - FORCEINLINE IteratorImpl() = default; + FORCEINLINE TIteratorImpl() = default; # if DO_CHECK - FORCEINLINE IteratorImpl(const IteratorImpl& InValue) requires (bConst) + FORCEINLINE TIteratorImpl(const TIteratorImpl& InValue) requires (bConst) : Owner(InValue.Owner), Pointer(InValue.Pointer) { } # else - FORCEINLINE IteratorImpl(const IteratorImpl& InValue) requires (bConst) + FORCEINLINE TIteratorImpl(const TIteratorImpl& InValue) requires (bConst) : Pointer(InValue.Pointer) { } # endif - FORCEINLINE IteratorImpl(const IteratorImpl&) = default; - FORCEINLINE IteratorImpl(IteratorImpl&&) = default; - FORCEINLINE IteratorImpl& operator=(const IteratorImpl&) = default; - FORCEINLINE IteratorImpl& operator=(IteratorImpl&&) = default; + FORCEINLINE TIteratorImpl(const TIteratorImpl&) = default; + FORCEINLINE TIteratorImpl(TIteratorImpl&&) = default; + FORCEINLINE TIteratorImpl& operator=(const TIteratorImpl&) = default; + FORCEINLINE TIteratorImpl& operator=(TIteratorImpl&&) = default; - NODISCARD friend FORCEINLINE bool operator==(const IteratorImpl& LHS, const IteratorImpl& RHS) { return LHS.Pointer == RHS.Pointer; } + NODISCARD friend FORCEINLINE bool operator==(const TIteratorImpl& LHS, const TIteratorImpl& RHS) { return LHS.Pointer == RHS.Pointer; } - NODISCARD friend FORCEINLINE strong_ordering operator<=>(const IteratorImpl& LHS, const IteratorImpl& RHS) { return LHS.Pointer <=> RHS.Pointer; } + NODISCARD friend FORCEINLINE strong_ordering operator<=>(const TIteratorImpl& LHS, const TIteratorImpl& RHS) { return LHS.Pointer <=> RHS.Pointer; } - NODISCARD FORCEINLINE ElementType& operator*() const { CheckThis(true); return *Pointer; } - NODISCARD FORCEINLINE ElementType* operator->() const { CheckThis(true); return Pointer; } + NODISCARD FORCEINLINE U& operator*() const { CheckThis(true); return *Pointer; } + NODISCARD FORCEINLINE U* operator->() const { CheckThis(true); return Pointer; } - NODISCARD FORCEINLINE ElementType& operator[](ptrdiff Index) const { IteratorImpl Temp = *this + Index; return *Temp; } + NODISCARD FORCEINLINE U& operator[](ptrdiff Index) const { TIteratorImpl Temp = *this + Index; return *Temp; } - FORCEINLINE IteratorImpl& operator++() { ++Pointer; CheckThis(); return *this; } - FORCEINLINE IteratorImpl& operator--() { --Pointer; CheckThis(); return *this; } + FORCEINLINE TIteratorImpl& operator++() { ++Pointer; CheckThis(); return *this; } + FORCEINLINE TIteratorImpl& operator--() { --Pointer; CheckThis(); return *this; } - FORCEINLINE IteratorImpl operator++(int) { IteratorImpl Temp = *this; ++*this; return Temp; } - FORCEINLINE IteratorImpl operator--(int) { IteratorImpl Temp = *this; --*this; return Temp; } + FORCEINLINE TIteratorImpl operator++(int) { TIteratorImpl Temp = *this; ++*this; return Temp; } + FORCEINLINE TIteratorImpl operator--(int) { TIteratorImpl Temp = *this; --*this; return Temp; } - FORCEINLINE IteratorImpl& operator+=(ptrdiff Offset) { Pointer += Offset; CheckThis(); return *this; } - FORCEINLINE IteratorImpl& operator-=(ptrdiff Offset) { Pointer -= Offset; CheckThis(); return *this; } + FORCEINLINE TIteratorImpl& operator+=(ptrdiff Offset) { Pointer += Offset; CheckThis(); return *this; } + FORCEINLINE TIteratorImpl& operator-=(ptrdiff Offset) { Pointer -= Offset; CheckThis(); return *this; } - NODISCARD friend FORCEINLINE IteratorImpl operator+(IteratorImpl Iter, ptrdiff Offset) { IteratorImpl Temp = Iter; Temp += Offset; return Temp; } - NODISCARD friend FORCEINLINE IteratorImpl operator+(ptrdiff Offset, IteratorImpl Iter) { IteratorImpl Temp = Iter; Temp += Offset; return Temp; } + NODISCARD friend FORCEINLINE TIteratorImpl operator+(TIteratorImpl Iter, ptrdiff Offset) { TIteratorImpl Temp = Iter; Temp += Offset; return Temp; } + NODISCARD friend FORCEINLINE TIteratorImpl operator+(ptrdiff Offset, TIteratorImpl Iter) { TIteratorImpl Temp = Iter; Temp += Offset; return Temp; } - NODISCARD FORCEINLINE IteratorImpl operator-(ptrdiff Offset) const { IteratorImpl Temp = *this; Temp -= Offset; return Temp; } + NODISCARD FORCEINLINE TIteratorImpl operator-(ptrdiff Offset) const { TIteratorImpl Temp = *this; Temp -= Offset; return Temp; } - NODISCARD friend FORCEINLINE ptrdiff operator-(const IteratorImpl& LHS, const IteratorImpl& RHS) { LHS.CheckThis(); RHS.CheckThis(); return LHS.Pointer - RHS.Pointer; } + NODISCARD friend FORCEINLINE ptrdiff operator-(const TIteratorImpl& LHS, const TIteratorImpl& RHS) { LHS.CheckThis(); RHS.CheckThis(); return LHS.Pointer - RHS.Pointer; } - NODISCARD FORCEINLINE explicit operator TObserverPtr() const { CheckThis(); return TObserverPtr(Pointer); } + NODISCARD FORCEINLINE explicit operator TObserverPtr() const { CheckThis(); return TObserverPtr(Pointer); } private: @@ -1032,14 +1032,14 @@ private: const TArray* Owner = nullptr; # endif - ElementType* Pointer = nullptr; + U* Pointer = nullptr; # if DO_CHECK - FORCEINLINE IteratorImpl(const TArray* InContainer, ElementType* InPointer) + FORCEINLINE TIteratorImpl(const TArray* InContainer, U* InPointer) : Owner(InContainer), Pointer(InPointer) { } # else - FORCEINLINE IteratorImpl(const TArray* InContainer, ElementType* InPointer) + FORCEINLINE TIteratorImpl(const TArray* InContainer, U* InPointer) : Pointer(InPointer) { } # endif @@ -1050,7 +1050,7 @@ private: checkf(!(bExceptEnd && Owner->End() == *this), TEXT("Read access violation. Please check IsValidIterator().")); } - template friend class IteratorImpl; + template friend class TIteratorImpl; friend TArray; diff --git a/Redcraft.Utility/Source/Public/Containers/ArrayView.h b/Redcraft.Utility/Source/Public/Containers/ArrayView.h index 5b04dd3..26e4112 100644 --- a/Redcraft.Utility/Source/Public/Containers/ArrayView.h +++ b/Redcraft.Utility/Source/Public/Containers/ArrayView.h @@ -303,7 +303,7 @@ public: { public: - using ElementType = T; + using ElementType = TRemoveCV; FORCEINLINE constexpr Iterator() = default; FORCEINLINE constexpr Iterator(const Iterator&) = default; @@ -315,10 +315,10 @@ public: NODISCARD friend FORCEINLINE constexpr strong_ordering operator<=>(const Iterator& LHS, const Iterator& RHS) { return LHS.Pointer <=> RHS.Pointer; } - NODISCARD FORCEINLINE constexpr ElementType& operator*() const { CheckThis(true); return *Pointer; } - NODISCARD FORCEINLINE constexpr ElementType* operator->() const { CheckThis(true); return Pointer; } + NODISCARD FORCEINLINE constexpr T& operator*() const { CheckThis(true); return *Pointer; } + NODISCARD FORCEINLINE constexpr T* operator->() const { CheckThis(true); return Pointer; } - NODISCARD FORCEINLINE constexpr ElementType& operator[](ptrdiff Index) const { Iterator Temp = *this + Index; return *Temp; } + NODISCARD FORCEINLINE constexpr T& operator[](ptrdiff Index) const { Iterator Temp = *this + Index; return *Temp; } FORCEINLINE constexpr Iterator& operator++() { ++Pointer; CheckThis(); return *this; } FORCEINLINE constexpr Iterator& operator--() { --Pointer; CheckThis(); return *this; } @@ -336,7 +336,7 @@ public: NODISCARD friend FORCEINLINE constexpr ptrdiff operator-(const Iterator& LHS, const Iterator& RHS) { LHS.CheckThis(); RHS.CheckThis(); return LHS.Pointer - RHS.Pointer; } - NODISCARD FORCEINLINE constexpr explicit operator TObserverPtr() const { CheckThis(); return TObserverPtr(Pointer); } + NODISCARD FORCEINLINE constexpr explicit operator TObserverPtr() const { CheckThis(); return TObserverPtr(Pointer); } private: @@ -344,14 +344,14 @@ public: const TArrayView* Owner = nullptr; # endif - ElementType* Pointer = nullptr; + T* Pointer = nullptr; # if DO_CHECK - FORCEINLINE constexpr Iterator(const TArrayView* InContainer, ElementType* InPointer) + FORCEINLINE constexpr Iterator(const TArrayView* InContainer, T* InPointer) : Owner(InContainer), Pointer(InPointer) { } # else - FORCEINLINE constexpr Iterator(const TArrayView* InContainer, ElementType* InPointer) + FORCEINLINE constexpr Iterator(const TArrayView* InContainer, T* InPointer) : Pointer(InPointer) { } # endif diff --git a/Redcraft.Utility/Source/Public/Containers/Bitset.h b/Redcraft.Utility/Source/Public/Containers/Bitset.h index 89a9da4..5487396 100644 --- a/Redcraft.Utility/Source/Public/Containers/Bitset.h +++ b/Redcraft.Utility/Source/Public/Containers/Bitset.h @@ -26,7 +26,7 @@ class TBitset final private: template - class IteratorImpl; + class TIteratorImpl; public: @@ -37,8 +37,8 @@ public: class Reference; using ConstReference = bool; - using Iterator = IteratorImpl; - using ConstIterator = IteratorImpl; + using Iterator = TIteratorImpl; + using ConstIterator = TIteratorImpl; using ReverseIterator = TReverseIterator< Iterator>; using ConstReverseIterator = TReverseIterator; @@ -905,7 +905,7 @@ public: FORCEINLINE Reference& operator=(bool InValue) { Data = (Data & ~Mask) | (InValue ? Mask : 0); return *this; } - FORCEINLINE Reference& operator=(const Reference& InValue) { return *this = static_cast(InValue); } + FORCEINLINE Reference& operator=(const Reference& InValue) { *this = static_cast(InValue); return *this; } FORCEINLINE Reference& operator&=(bool InValue) { Data &= InValue ? -1 : ~Mask; return *this; } FORCEINLINE Reference& operator|=(bool InValue) { Data |= InValue ? Mask : 0; return *this; } @@ -931,55 +931,53 @@ public: private: template - class IteratorImpl + class TIteratorImpl { - private: - public: - using ElementType = TConditional; + using ElementType = bool; - FORCEINLINE IteratorImpl() = default; + FORCEINLINE TIteratorImpl() = default; # if DO_CHECK - FORCEINLINE IteratorImpl(const IteratorImpl& InValue) requires (bConst) - : Owner(InValue.Owner), Pointer(InValue.Pointer), Offset(InValue.Offset) + FORCEINLINE TIteratorImpl(const TIteratorImpl& InValue) requires (bConst) + : Owner(InValue.Owner), Pointer(InValue.Pointer), BitOffset(InValue.BitOffset) { } # else - FORCEINLINE IteratorImpl(const IteratorImpl& InValue) requires (bConst) - : Pointer(InValue.Pointer), Offset(InValue.Offset) + FORCEINLINE TIteratorImpl(const TIteratorImpl& InValue) requires (bConst) + : Pointer(InValue.Pointer), BitOffset(InValue.BitOffset) { } # endif - FORCEINLINE IteratorImpl(const IteratorImpl&) = default; - FORCEINLINE IteratorImpl(IteratorImpl&&) = default; - FORCEINLINE IteratorImpl& operator=(const IteratorImpl&) = default; - FORCEINLINE IteratorImpl& operator=(IteratorImpl&&) = default; + FORCEINLINE TIteratorImpl(const TIteratorImpl&) = default; + FORCEINLINE TIteratorImpl(TIteratorImpl&&) = default; + FORCEINLINE TIteratorImpl& operator=(const TIteratorImpl&) = default; + FORCEINLINE TIteratorImpl& operator=(TIteratorImpl&&) = default; - NODISCARD friend FORCEINLINE bool operator==(const IteratorImpl& LHS, const IteratorImpl& RHS) { check(LHS.Pointer == RHS.Pointer); return LHS.Offset == RHS.Offset; } + NODISCARD friend FORCEINLINE bool operator==(const TIteratorImpl& LHS, const TIteratorImpl& RHS) { check(LHS.Pointer == RHS.Pointer); return LHS.BitOffset == RHS.BitOffset; } - NODISCARD friend FORCEINLINE strong_ordering operator<=>(const IteratorImpl& LHS, const IteratorImpl& RHS) { check(LHS.Pointer == RHS.Pointer); return LHS.Offset <=> RHS.Offset; } + NODISCARD friend FORCEINLINE strong_ordering operator<=>(const TIteratorImpl& LHS, const TIteratorImpl& RHS) { check(LHS.Pointer == RHS.Pointer); return LHS.BitOffset <=> RHS.BitOffset; } - NODISCARD FORCEINLINE Reference operator*() const requires (!bConst) { CheckThis(true); return Reference(*(Pointer + Offset / BlockWidth), 1ull << Offset % BlockWidth); } - NODISCARD FORCEINLINE ConstReference operator*() const requires ( bConst) { CheckThis(true); return (*(Pointer + Offset / BlockWidth) & (1ull << Offset % BlockWidth)); } + NODISCARD FORCEINLINE Reference operator*() const requires (!bConst) { CheckThis(true); return Reference(*(Pointer + BitOffset / BlockWidth), 1ull << BitOffset % BlockWidth); } + NODISCARD FORCEINLINE ConstReference operator*() const requires ( bConst) { CheckThis(true); return (*(Pointer + BitOffset / BlockWidth) & (1ull << BitOffset % BlockWidth)); } - NODISCARD FORCEINLINE auto operator[](ptrdiff Index) const { IteratorImpl Temp = *this + Index; return *Temp; } + NODISCARD FORCEINLINE auto operator[](ptrdiff Index) const { TIteratorImpl Temp = *this + Index; return *Temp; } - FORCEINLINE IteratorImpl& operator++() { ++Offset; CheckThis(); return *this; } - FORCEINLINE IteratorImpl& operator--() { --Offset; CheckThis(); return *this; } + FORCEINLINE TIteratorImpl& operator++() { ++BitOffset; CheckThis(); return *this; } + FORCEINLINE TIteratorImpl& operator--() { --BitOffset; CheckThis(); return *this; } - FORCEINLINE IteratorImpl operator++(int) { IteratorImpl Temp = *this; ++*this; return Temp; } - FORCEINLINE IteratorImpl operator--(int) { IteratorImpl Temp = *this; --*this; return Temp; } + FORCEINLINE TIteratorImpl operator++(int) { TIteratorImpl Temp = *this; ++*this; return Temp; } + FORCEINLINE TIteratorImpl operator--(int) { TIteratorImpl Temp = *this; --*this; return Temp; } - FORCEINLINE IteratorImpl& operator+=(ptrdiff Offset) { this->Offset += Offset; CheckThis(); return *this; } - FORCEINLINE IteratorImpl& operator-=(ptrdiff Offset) { this->Offset -= Offset; CheckThis(); return *this; } + FORCEINLINE TIteratorImpl& operator+=(ptrdiff Offset) { BitOffset += Offset; CheckThis(); return *this; } + FORCEINLINE TIteratorImpl& operator-=(ptrdiff Offset) { BitOffset -= Offset; CheckThis(); return *this; } - NODISCARD friend FORCEINLINE IteratorImpl operator+(IteratorImpl Iter, ptrdiff Offset) { IteratorImpl Temp = Iter; Temp += Offset; return Temp; } - NODISCARD friend FORCEINLINE IteratorImpl operator+(ptrdiff Offset, IteratorImpl Iter) { IteratorImpl Temp = Iter; Temp += Offset; return Temp; } + NODISCARD friend FORCEINLINE TIteratorImpl operator+(TIteratorImpl Iter, ptrdiff Offset) { TIteratorImpl Temp = Iter; Temp += Offset; return Temp; } + NODISCARD friend FORCEINLINE TIteratorImpl operator+(ptrdiff Offset, TIteratorImpl Iter) { TIteratorImpl Temp = Iter; Temp += Offset; return Temp; } - NODISCARD FORCEINLINE IteratorImpl operator-(ptrdiff Offset) const { IteratorImpl Temp = *this; Temp -= Offset; return Temp; } + NODISCARD FORCEINLINE TIteratorImpl operator-(ptrdiff Offset) const { TIteratorImpl Temp = *this; Temp -= Offset; return Temp; } - NODISCARD friend FORCEINLINE ptrdiff operator-(const IteratorImpl& LHS, const IteratorImpl& RHS) { check(LHS.Pointer == RHS.Pointer); return LHS.Offset - RHS.Offset; } + NODISCARD friend FORCEINLINE ptrdiff operator-(const TIteratorImpl& LHS, const TIteratorImpl& RHS) { check(LHS.Pointer == RHS.Pointer); return LHS.BitOffset - RHS.BitOffset; } private: @@ -989,16 +987,16 @@ private: using BlockPtr = TConditional; - BlockPtr Pointer = nullptr; - size_t Offset = 0; + BlockPtr Pointer = nullptr; + size_t BitOffset = 0; # if DO_CHECK - FORCEINLINE IteratorImpl(const TBitset* InContainer, BlockPtr InPointer, size_t InOffset) - : Owner(InContainer), Pointer(InPointer), Offset(InOffset) + FORCEINLINE TIteratorImpl(const TBitset* InContainer, BlockPtr InPointer, size_t Offset) + : Owner(InContainer), Pointer(InPointer), BitOffset(Offset) { } # else - FORCEINLINE IteratorImpl(const TBitset* InContainer, BlockPtr InPointer, size_t InOffset) - : Pointer(InPointer), Offset(InOffset) + FORCEINLINE TIteratorImpl(const TBitset* InContainer, BlockPtr InPointer, size_t Offset) + : Pointer(InPointer), BitOffset(Offset) { } # endif @@ -1008,7 +1006,7 @@ private: checkf(!(bExceptEnd && Owner->End() == *this), TEXT("Read access violation. Please check IsValidIterator().")); } - template friend class IteratorImpl; + template friend class TIteratorImpl; friend TBitset; diff --git a/Redcraft.Utility/Source/Public/Containers/Iterator.h b/Redcraft.Utility/Source/Public/Containers/Iterator.h index add1cab..93429c8 100644 --- a/Redcraft.Utility/Source/Public/Containers/Iterator.h +++ b/Redcraft.Utility/Source/Public/Containers/Iterator.h @@ -19,7 +19,7 @@ template using WithReference = T&; template struct TIteratorElementType { using Type = typename I::ElementType; }; -template struct TIteratorElementType { using Type = T; }; +template struct TIteratorElementType { using Type = TRemoveCV; }; template struct TIteratorPointerType { using Type = void; }; @@ -58,6 +58,7 @@ concept CIndirectlyReadable = { *Iter } -> CSameAs>; { MoveTemp(*Iter) } -> CSameAs>; } + && CSameAs, TRemoveCVRef>> && CCommonReference&&, TIteratorElementType&> && CCommonReference&&, TIteratorRValueReferenceType&&> && CCommonReference&&, const TIteratorElementType&>; @@ -124,10 +125,9 @@ concept CRandomAccessIterator = CBidirectionalIterator && CTotallyOrdered template concept CContiguousIterator = CRandomAccessIterator && CLValueReference> - && CSameAs, TRemoveReference>> + && CSameAs, TRemoveCVRef>> && requires(I& Iter) { - static_cast[]>>(Iter); { AddressOf(*Iter) } -> CSameAs>>; }; diff --git a/Redcraft.Utility/Source/Public/Containers/List.h b/Redcraft.Utility/Source/Public/Containers/List.h index 16aa4e4..dd11bd8 100644 --- a/Redcraft.Utility/Source/Public/Containers/List.h +++ b/Redcraft.Utility/Source/Public/Containers/List.h @@ -24,8 +24,8 @@ private: struct FNode; - template - class IteratorImpl; + template > + class TIteratorImpl; public: @@ -35,8 +35,8 @@ public: using Reference = T&; using ConstReference = const T&; - using Iterator = IteratorImpl; - using ConstIterator = IteratorImpl; + using Iterator = TIteratorImpl; + using ConstIterator = TIteratorImpl; using ReverseIterator = TReverseIterator< Iterator>; using ConstReverseIterator = TReverseIterator; @@ -553,44 +553,44 @@ private: } ALLOCATOR_WRAPPER_END(AllocatorType, FNode, Impl) - template - class IteratorImpl + template + class TIteratorImpl { public: - using ElementType = TConditional; + using ElementType = TRemoveCV; - FORCEINLINE IteratorImpl() = default; + FORCEINLINE TIteratorImpl() = default; - FORCEINLINE IteratorImpl(const IteratorImpl& InValue) requires (bConst) + FORCEINLINE TIteratorImpl(const TIteratorImpl& InValue) requires (bConst) : Pointer(InValue.Pointer) { } - FORCEINLINE IteratorImpl(const IteratorImpl&) = default; - FORCEINLINE IteratorImpl(IteratorImpl&&) = default; - FORCEINLINE IteratorImpl& operator=(const IteratorImpl&) = default; - FORCEINLINE IteratorImpl& operator=(IteratorImpl&&) = default; + FORCEINLINE TIteratorImpl(const TIteratorImpl&) = default; + FORCEINLINE TIteratorImpl(TIteratorImpl&&) = default; + FORCEINLINE TIteratorImpl& operator=(const TIteratorImpl&) = default; + FORCEINLINE TIteratorImpl& operator=(TIteratorImpl&&) = default; - NODISCARD friend FORCEINLINE bool operator==(const IteratorImpl& LHS, const IteratorImpl& RHS) { return LHS.Pointer == RHS.Pointer; } + NODISCARD friend FORCEINLINE bool operator==(const TIteratorImpl& LHS, const TIteratorImpl& RHS) { return LHS.Pointer == RHS.Pointer; } - NODISCARD FORCEINLINE ElementType& operator*() const { return Pointer->Value; } - NODISCARD FORCEINLINE ElementType* operator->() const { return &Pointer->Value; } + NODISCARD FORCEINLINE U& operator*() const { return Pointer->Value; } + NODISCARD FORCEINLINE U* operator->() const { return &Pointer->Value; } - FORCEINLINE IteratorImpl& operator++() { Pointer = Pointer->NextNode; return *this; } - FORCEINLINE IteratorImpl& operator--() { Pointer = Pointer->PrevNode; return *this; } + FORCEINLINE TIteratorImpl& operator++() { Pointer = Pointer->NextNode; return *this; } + FORCEINLINE TIteratorImpl& operator--() { Pointer = Pointer->PrevNode; return *this; } - FORCEINLINE IteratorImpl operator++(int) { IteratorImpl Temp = *this; ++*this; return Temp; } - FORCEINLINE IteratorImpl operator--(int) { IteratorImpl Temp = *this; --*this; return Temp; } + FORCEINLINE TIteratorImpl operator++(int) { TIteratorImpl Temp = *this; ++*this; return Temp; } + FORCEINLINE TIteratorImpl operator--(int) { TIteratorImpl Temp = *this; --*this; return Temp; } private: FNode* Pointer = nullptr; - FORCEINLINE IteratorImpl(FNode* InPointer) + FORCEINLINE TIteratorImpl(FNode* InPointer) : Pointer(InPointer) { } - template friend class IteratorImpl; + template friend class TIteratorImpl; friend TList; diff --git a/Redcraft.Utility/Source/Public/Containers/StaticArray.h b/Redcraft.Utility/Source/Public/Containers/StaticArray.h index cb4e856..52f38c8 100644 --- a/Redcraft.Utility/Source/Public/Containers/StaticArray.h +++ b/Redcraft.Utility/Source/Public/Containers/StaticArray.h @@ -21,8 +21,8 @@ struct TStaticArray final { private: - template - class IteratorImpl; + template > + class TIteratorImpl; public: @@ -31,8 +31,8 @@ public: using Reference = T&; using ConstReference = const T&; - using Iterator = IteratorImpl; - using ConstIterator = IteratorImpl; + using Iterator = TIteratorImpl; + using ConstIterator = TIteratorImpl; using ReverseIterator = TReverseIterator< Iterator>; using ConstReverseIterator = TReverseIterator; @@ -123,56 +123,56 @@ public: private: - template - class IteratorImpl + template + class TIteratorImpl { public: - using ElementType = TConditional; + using ElementType = TRemoveCV; - FORCEINLINE constexpr IteratorImpl() = default; + FORCEINLINE constexpr TIteratorImpl() = default; # if DO_CHECK - FORCEINLINE IteratorImpl(const IteratorImpl& InValue) requires (bConst) + FORCEINLINE TIteratorImpl(const TIteratorImpl& InValue) requires (bConst) : Owner(InValue.Owner), Pointer(InValue.Pointer) { } # else - FORCEINLINE IteratorImpl(const IteratorImpl& InValue) requires (bConst) + FORCEINLINE TIteratorImpl(const TIteratorImpl& InValue) requires (bConst) : Pointer(InValue.Pointer) { } # endif - FORCEINLINE constexpr IteratorImpl(const IteratorImpl&) = default; - FORCEINLINE constexpr IteratorImpl(IteratorImpl&&) = default; - FORCEINLINE constexpr IteratorImpl& operator=(const IteratorImpl&) = default; - FORCEINLINE constexpr IteratorImpl& operator=(IteratorImpl&&) = default; + FORCEINLINE constexpr TIteratorImpl(const TIteratorImpl&) = default; + FORCEINLINE constexpr TIteratorImpl(TIteratorImpl&&) = default; + FORCEINLINE constexpr TIteratorImpl& operator=(const TIteratorImpl&) = default; + FORCEINLINE constexpr TIteratorImpl& operator=(TIteratorImpl&&) = default; - NODISCARD friend FORCEINLINE constexpr bool operator==(const IteratorImpl& LHS, const IteratorImpl& RHS) { return LHS.Pointer == RHS.Pointer; } + NODISCARD friend FORCEINLINE constexpr bool operator==(const TIteratorImpl& LHS, const TIteratorImpl& RHS) { return LHS.Pointer == RHS.Pointer; } - NODISCARD friend FORCEINLINE constexpr strong_ordering operator<=>(const IteratorImpl& LHS, const IteratorImpl& RHS) { return LHS.Pointer <=> RHS.Pointer; } + NODISCARD friend FORCEINLINE constexpr strong_ordering operator<=>(const TIteratorImpl& LHS, const TIteratorImpl& RHS) { return LHS.Pointer <=> RHS.Pointer; } - NODISCARD FORCEINLINE constexpr ElementType& operator*() const { CheckThis(true); return *Pointer; } - NODISCARD FORCEINLINE constexpr ElementType* operator->() const { CheckThis(true); return Pointer; } + NODISCARD FORCEINLINE constexpr U& operator*() const { CheckThis(true); return *Pointer; } + NODISCARD FORCEINLINE constexpr U* operator->() const { CheckThis(true); return Pointer; } - NODISCARD FORCEINLINE constexpr ElementType& operator[](ptrdiff Index) const { IteratorImpl Temp = *this + Index; return *Temp; } + NODISCARD FORCEINLINE constexpr U& operator[](ptrdiff Index) const { TIteratorImpl Temp = *this + Index; return *Temp; } - FORCEINLINE constexpr IteratorImpl& operator++() { ++Pointer; CheckThis(); return *this; } - FORCEINLINE constexpr IteratorImpl& operator--() { --Pointer; CheckThis(); return *this; } + FORCEINLINE constexpr TIteratorImpl& operator++() { ++Pointer; CheckThis(); return *this; } + FORCEINLINE constexpr TIteratorImpl& operator--() { --Pointer; CheckThis(); return *this; } - FORCEINLINE constexpr IteratorImpl operator++(int) { IteratorImpl Temp = *this; ++*this; return Temp; } - FORCEINLINE constexpr IteratorImpl operator--(int) { IteratorImpl Temp = *this; --*this; return Temp; } + FORCEINLINE constexpr TIteratorImpl operator++(int) { TIteratorImpl Temp = *this; ++*this; return Temp; } + FORCEINLINE constexpr TIteratorImpl operator--(int) { TIteratorImpl Temp = *this; --*this; return Temp; } - FORCEINLINE constexpr IteratorImpl& operator+=(ptrdiff Offset) { Pointer += Offset; CheckThis(); return *this; } - FORCEINLINE constexpr IteratorImpl& operator-=(ptrdiff Offset) { Pointer -= Offset; CheckThis(); return *this; } + FORCEINLINE constexpr TIteratorImpl& operator+=(ptrdiff Offset) { Pointer += Offset; CheckThis(); return *this; } + FORCEINLINE constexpr TIteratorImpl& operator-=(ptrdiff Offset) { Pointer -= Offset; CheckThis(); return *this; } - NODISCARD friend FORCEINLINE constexpr IteratorImpl operator+(IteratorImpl Iter, ptrdiff Offset) { IteratorImpl Temp = Iter; Temp += Offset; return Temp; } - NODISCARD friend FORCEINLINE constexpr IteratorImpl operator+(ptrdiff Offset, IteratorImpl Iter) { IteratorImpl Temp = Iter; Temp += Offset; return Temp; } + NODISCARD friend FORCEINLINE constexpr TIteratorImpl operator+(TIteratorImpl Iter, ptrdiff Offset) { TIteratorImpl Temp = Iter; Temp += Offset; return Temp; } + NODISCARD friend FORCEINLINE constexpr TIteratorImpl operator+(ptrdiff Offset, TIteratorImpl Iter) { TIteratorImpl Temp = Iter; Temp += Offset; return Temp; } - NODISCARD FORCEINLINE constexpr IteratorImpl operator-(ptrdiff Offset) const { IteratorImpl Temp = *this; Temp -= Offset; return Temp; } + NODISCARD FORCEINLINE constexpr TIteratorImpl operator-(ptrdiff Offset) const { TIteratorImpl Temp = *this; Temp -= Offset; return Temp; } - NODISCARD friend FORCEINLINE constexpr ptrdiff operator-(const IteratorImpl& LHS, const IteratorImpl& RHS) { LHS.CheckThis(); RHS.CheckThis(); return LHS.Pointer - RHS.Pointer; } + NODISCARD friend FORCEINLINE constexpr ptrdiff operator-(const TIteratorImpl& LHS, const TIteratorImpl& RHS) { LHS.CheckThis(); RHS.CheckThis(); return LHS.Pointer - RHS.Pointer; } - NODISCARD FORCEINLINE constexpr explicit operator TObserverPtr() const { CheckThis(); return TObserverPtr(Pointer); } + NODISCARD FORCEINLINE constexpr explicit operator TObserverPtr() const { CheckThis(); return TObserverPtr(Pointer); } private: @@ -180,14 +180,14 @@ private: const TStaticArray* Owner = nullptr; # endif - ElementType* Pointer = nullptr; + U* Pointer = nullptr; # if DO_CHECK - FORCEINLINE constexpr IteratorImpl(const TStaticArray* InContainer, ElementType* InPointer) + FORCEINLINE constexpr TIteratorImpl(const TStaticArray* InContainer, U* InPointer) : Owner(InContainer), Pointer(InPointer) { } # else - FORCEINLINE constexpr IteratorImpl(const TStaticArray* InContainer, ElementType* InPointer) + FORCEINLINE constexpr TIteratorImpl(const TStaticArray* InContainer, U* InPointer) : Pointer(InPointer) { } # endif @@ -198,7 +198,7 @@ private: checkf(!(bExceptEnd && Owner->End() == *this), TEXT("Read access violation. Please check IsValidIterator().")); } - template friend class IteratorImpl; + template friend class TIteratorImpl; friend TStaticArray; diff --git a/Redcraft.Utility/Source/Public/Containers/StaticBitset.h b/Redcraft.Utility/Source/Public/Containers/StaticBitset.h index 450d6ac..39c8da8 100644 --- a/Redcraft.Utility/Source/Public/Containers/StaticBitset.h +++ b/Redcraft.Utility/Source/Public/Containers/StaticBitset.h @@ -33,7 +33,7 @@ class TStaticBitset final private: template - class IteratorImpl; + class TIteratorImpl; public: @@ -43,8 +43,8 @@ public: class Reference; using ConstReference = bool; - using Iterator = IteratorImpl; - using ConstIterator = IteratorImpl; + using Iterator = TIteratorImpl; + using ConstIterator = TIteratorImpl; using ReverseIterator = TReverseIterator< Iterator>; using ConstReverseIterator = TReverseIterator; @@ -115,7 +115,7 @@ public: /** Move assignment operator. After the move, 'InValue' is guaranteed to be empty. */ FORCEINLINE constexpr TStaticBitset& operator=(TStaticBitset&&) = default; - + /** Compares the bits of two bitsets. */ NODISCARD friend constexpr bool operator==(const TStaticBitset& LHS, const TStaticBitset& RHS) { @@ -399,7 +399,7 @@ public: uint64 Result = 0; static_assert(sizeof(BlockType) <= sizeof(uint64), "The block width of TStaticBitset is unexpected"); - + if constexpr (sizeof(BlockType) == sizeof(uint8)) { if constexpr (N > 0) Result |= static_cast(Impl[0]) << 0; @@ -506,7 +506,7 @@ public: FORCEINLINE constexpr Reference& operator=(bool InValue) { Data = (Data & ~Mask) | (InValue ? Mask : 0); return *this; } - FORCEINLINE constexpr Reference& operator=(const Reference& InValue) { return *this = static_cast(InValue); } + FORCEINLINE constexpr Reference& operator=(const Reference& InValue) { *this = static_cast(InValue); return *this; } FORCEINLINE constexpr Reference& operator&=(bool InValue) { Data &= InValue ? -1 : ~Mask; return *this; } FORCEINLINE constexpr Reference& operator|=(bool InValue) { Data |= InValue ? Mask : 0; return *this; } @@ -532,55 +532,55 @@ public: private: template - class IteratorImpl + class TIteratorImpl { private: public: - using ElementType = TConditional; + using ElementType = bool; - FORCEINLINE constexpr IteratorImpl() = default; + FORCEINLINE constexpr TIteratorImpl() = default; # if DO_CHECK - FORCEINLINE constexpr IteratorImpl(const IteratorImpl& InValue) requires (bConst) - : Owner(InValue.Owner), Pointer(InValue.Pointer), Offset(InValue.Offset) + FORCEINLINE constexpr TIteratorImpl(const TIteratorImpl& InValue) requires (bConst) + : Owner(InValue.Owner), Pointer(InValue.Pointer), BitOffset(InValue.BitOffset) { } # else - FORCEINLINE constexpr IteratorImpl(const IteratorImpl& InValue) requires (bConst) - : Pointer(InValue.Pointer), Offset(InValue.Offset) + FORCEINLINE constexpr TIteratorImpl(const TIteratorImpl& InValue) requires (bConst) + : Pointer(InValue.Pointer), BitOffset(InValue.BitOffset) { } # endif - FORCEINLINE constexpr IteratorImpl(const IteratorImpl&) = default; - FORCEINLINE constexpr IteratorImpl(IteratorImpl&&) = default; - FORCEINLINE constexpr IteratorImpl& operator=(const IteratorImpl&) = default; - FORCEINLINE constexpr IteratorImpl& operator=(IteratorImpl&&) = default; + FORCEINLINE constexpr TIteratorImpl(const TIteratorImpl&) = default; + FORCEINLINE constexpr TIteratorImpl(TIteratorImpl&&) = default; + FORCEINLINE constexpr TIteratorImpl& operator=(const TIteratorImpl&) = default; + FORCEINLINE constexpr TIteratorImpl& operator=(TIteratorImpl&&) = default; - NODISCARD friend FORCEINLINE constexpr bool operator==(const IteratorImpl& LHS, const IteratorImpl& RHS) { check(LHS.Pointer == RHS.Pointer); return LHS.Offset == RHS.Offset; } + NODISCARD friend FORCEINLINE constexpr bool operator==(const TIteratorImpl& LHS, const TIteratorImpl& RHS) { check(LHS.Pointer == RHS.Pointer); return LHS.BitOffset == RHS.BitOffset; } - NODISCARD friend FORCEINLINE constexpr strong_ordering operator<=>(const IteratorImpl& LHS, const IteratorImpl& RHS) { check(LHS.Pointer == RHS.Pointer); return LHS.Offset <=> RHS.Offset; } + NODISCARD friend FORCEINLINE constexpr strong_ordering operator<=>(const TIteratorImpl& LHS, const TIteratorImpl& RHS) { check(LHS.Pointer == RHS.Pointer); return LHS.BitOffset <=> RHS.BitOffset; } - NODISCARD FORCEINLINE constexpr Reference operator*() const requires (!bConst) { CheckThis(true); return Reference(*(Pointer + Offset / BlockWidth), 1ull << Offset % BlockWidth); } - NODISCARD FORCEINLINE constexpr ConstReference operator*() const requires ( bConst) { CheckThis(true); return (*(Pointer + Offset / BlockWidth) & (1ull << Offset % BlockWidth)); } + NODISCARD FORCEINLINE constexpr Reference operator*() const requires (!bConst) { CheckThis(true); return Reference(*(Pointer + BitOffset / BlockWidth), 1ull << BitOffset % BlockWidth); } + NODISCARD FORCEINLINE constexpr ConstReference operator*() const requires ( bConst) { CheckThis(true); return (*(Pointer + BitOffset / BlockWidth) & (1ull << BitOffset % BlockWidth)); } - NODISCARD FORCEINLINE constexpr auto operator[](ptrdiff Index) const { IteratorImpl Temp = *this + Index; return *Temp; } + NODISCARD FORCEINLINE constexpr auto operator[](ptrdiff Index) const { TIteratorImpl Temp = *this + Index; return *Temp; } - FORCEINLINE constexpr IteratorImpl& operator++() { ++Offset; CheckThis(); return *this; } - FORCEINLINE constexpr IteratorImpl& operator--() { --Offset; CheckThis(); return *this; } + FORCEINLINE constexpr TIteratorImpl& operator++() { ++BitOffset; CheckThis(); return *this; } + FORCEINLINE constexpr TIteratorImpl& operator--() { --BitOffset; CheckThis(); return *this; } - FORCEINLINE constexpr IteratorImpl operator++(int) { IteratorImpl Temp = *this; ++*this; return Temp; } - FORCEINLINE constexpr IteratorImpl operator--(int) { IteratorImpl Temp = *this; --*this; return Temp; } + FORCEINLINE constexpr TIteratorImpl operator++(int) { TIteratorImpl Temp = *this; ++*this; return Temp; } + FORCEINLINE constexpr TIteratorImpl operator--(int) { TIteratorImpl Temp = *this; --*this; return Temp; } - FORCEINLINE constexpr IteratorImpl& operator+=(ptrdiff Offset) { this->Offset += Offset; CheckThis(); return *this; } - FORCEINLINE constexpr IteratorImpl& operator-=(ptrdiff Offset) { this->Offset -= Offset; CheckThis(); return *this; } + FORCEINLINE constexpr TIteratorImpl& operator+=(ptrdiff Offset) { BitOffset += Offset; CheckThis(); return *this; } + FORCEINLINE constexpr TIteratorImpl& operator-=(ptrdiff Offset) { BitOffset -= Offset; CheckThis(); return *this; } - NODISCARD friend FORCEINLINE constexpr IteratorImpl operator+(IteratorImpl Iter, ptrdiff Offset) { IteratorImpl Temp = Iter; Temp += Offset; return Temp; } - NODISCARD friend FORCEINLINE constexpr IteratorImpl operator+(ptrdiff Offset, IteratorImpl Iter) { IteratorImpl Temp = Iter; Temp += Offset; return Temp; } + NODISCARD friend FORCEINLINE constexpr TIteratorImpl operator+(TIteratorImpl Iter, ptrdiff Offset) { TIteratorImpl Temp = Iter; Temp += Offset; return Temp; } + NODISCARD friend FORCEINLINE constexpr TIteratorImpl operator+(ptrdiff Offset, TIteratorImpl Iter) { TIteratorImpl Temp = Iter; Temp += Offset; return Temp; } - NODISCARD FORCEINLINE constexpr IteratorImpl operator-(ptrdiff Offset) const { IteratorImpl Temp = *this; Temp -= Offset; return Temp; } + NODISCARD FORCEINLINE constexpr TIteratorImpl operator-(ptrdiff Offset) const { TIteratorImpl Temp = *this; Temp -= Offset; return Temp; } - NODISCARD friend FORCEINLINE constexpr ptrdiff operator-(const IteratorImpl& LHS, const IteratorImpl& RHS) { check(LHS.Pointer == RHS.Pointer); return LHS.Offset - RHS.Offset; } + NODISCARD friend FORCEINLINE constexpr ptrdiff operator-(const TIteratorImpl& LHS, const TIteratorImpl& RHS) { check(LHS.Pointer == RHS.Pointer); return LHS.BitOffset - RHS.BitOffset; } private: @@ -590,16 +590,16 @@ private: using BlockPtr = TConditional; - BlockPtr Pointer = nullptr; - size_t Offset = 0; + BlockPtr Pointer = nullptr; + size_t BitOffset = 0; # if DO_CHECK - FORCEINLINE constexpr IteratorImpl(const TStaticBitset* InContainer, BlockPtr InPointer, size_t InOffset) - : Owner(InContainer), Pointer(InPointer), Offset(InOffset) + FORCEINLINE constexpr TIteratorImpl(const TStaticBitset* InContainer, BlockPtr InPointer, size_t Offset) + : Owner(InContainer), Pointer(InPointer), BitOffset(Offset) { } # else - FORCEINLINE constexpr IteratorImpl(const TStaticBitset* InContainer, BlockPtr InPointer, size_t InOffset) - : Pointer(InPointer), Offset(InOffset) + FORCEINLINE constexpr TIteratorImpl(const TStaticBitset* InContainer, BlockPtr InPointer, size_t Offset) + : Pointer(InPointer), BitOffset(Offset) { } # endif @@ -609,7 +609,7 @@ private: checkf(!(bExceptEnd && Owner->End() == *this), TEXT("Read access violation. Please check IsValidIterator().")); } - template friend class IteratorImpl; + template friend class TIteratorImpl; friend TStaticBitset; diff --git a/Redcraft.Utility/Source/Public/Miscellaneous/ConstantIterator.h b/Redcraft.Utility/Source/Public/Miscellaneous/ConstantIterator.h index a587f94..1bd99ab 100644 --- a/Redcraft.Utility/Source/Public/Miscellaneous/ConstantIterator.h +++ b/Redcraft.Utility/Source/Public/Miscellaneous/ConstantIterator.h @@ -16,7 +16,7 @@ class TConstantIterator final { public: - using ElementType = T; + using ElementType = TRemoveCV; FORCEINLINE constexpr TConstantIterator() = default; @@ -68,7 +68,7 @@ class TConstantIterator final { public: - using ElementType = T; + using ElementType = TRemoveCV; FORCEINLINE constexpr TConstantIterator() = default; diff --git a/Redcraft.Utility/Source/Public/String/String.h b/Redcraft.Utility/Source/Public/String/String.h index 4e13316..322489c 100644 --- a/Redcraft.Utility/Source/Public/String/String.h +++ b/Redcraft.Utility/Source/Public/String/String.h @@ -1048,16 +1048,13 @@ private: }; -template -TString(size_t, T) -> TString; - template TString(const T*) -> TString; template TString(TStringView) -> TString; -template +template TString(I, S) -> TString>; template