diff --git a/Redcraft.Utility/Source/Public/Containers/Array.h b/Redcraft.Utility/Source/Public/Containers/Array.h index 90b7d9f..ec36cf7 100644 --- a/Redcraft.Utility/Source/Public/Containers/Array.h +++ b/Redcraft.Utility/Source/Public/Containers/Array.h @@ -54,7 +54,7 @@ public: Memory::DefaultConstruct(Impl.Pointer, Num()); } - + /** Constructs the container with 'Count' copies of elements with 'InValue'. */ TArray(size_t Count, const ElementType& InValue) requires (CCopyConstructible) { @@ -158,7 +158,7 @@ public: { Memory::Destruct(Impl.Pointer, Num()); Impl->Deallocate(Impl.Pointer); - + Impl.ArrayNum = InValue.Num(); Impl.ArrayMax = NumToAllocate; Impl.Pointer = Impl->Allocate(Max()); @@ -213,13 +213,13 @@ public: { Memory::Destruct(Impl.Pointer, Num()); Impl->Deallocate(Impl.Pointer); - + Impl.ArrayNum = InValue.Num(); Impl.ArrayMax = NumToAllocate; Impl.Pointer = Impl->Allocate(Max()); Memory::MoveConstruct(Impl.Pointer, InValue.Impl.Pointer, Num()); - + InValue.Reset(); return *this; @@ -256,7 +256,7 @@ public: { Memory::Destruct(Impl.Pointer, Num()); Impl->Deallocate(Impl.Pointer); - + Impl.ArrayNum = GetNum(IL); Impl.ArrayMax = NumToAllocate; Impl.Pointer = Impl->Allocate(Max()); @@ -308,7 +308,7 @@ public: return LHS.Num() <=> RHS.Num(); } - + /** Inserts 'InValue' before 'Iter' in the container. */ Iterator Insert(ConstIterator Iter, const ElementType& InValue) requires (CCopyable) { @@ -399,7 +399,7 @@ public: Impl.Pointer[InsertIndex] = MoveTemp(InValue); } else new (Impl.Pointer + Num()) ElementType(MoveTemp(InValue)); - + Impl.ArrayNum = Num() + 1; return Iterator(this, Impl.Pointer + InsertIndex); @@ -443,12 +443,12 @@ public: } /* - * NO(XA) - No Operation + * NO(XA) - No Operation * IA(AB) - Insert Assignment * IC(BC) - Insert Construction * MA(CD) - Move Assignment * MC(DO) - Move Construction - * + * * IR(AC) - Insert Range * UI(UO) - Uninitialized * @@ -503,7 +503,7 @@ public: return Iterator(this, Impl.Pointer + InsertIndex); } - + /** Inserts elements from range ['First', 'Last') before 'Iter'. */ template S> requires (CConstructibleFrom> && CAssignableFrom> && CMovable) @@ -585,7 +585,7 @@ public: else { TArray Temp(MoveTemp(First), MoveTemp(Last)); - return Insert(Iter, TMoveIterator(Temp.Begin()), TMoveSentinel(Temp.End())); + return Insert(Iter, MakeMoveIterator(Temp.Begin()), MakeMoveSentinel(Temp.End())); } } @@ -706,7 +706,7 @@ public: Iterator Erase(ConstIterator First, ConstIterator Last, bool bAllowShrinking = true) requires (CMovable) { checkf(IsValidIterator(First) && IsValidIterator(Last) && First <= Last, TEXT("Read access violation. Please check IsValidIterator().")); - + const size_t EraseIndex = First - Begin(); const size_t EraseCount = Last - First; @@ -770,7 +770,7 @@ public: { ElementType* OldAllocation = Impl.Pointer; const size_t NumToDestruct = Num(); - + Impl.ArrayNum = Num() + 1; Impl.ArrayMax = NumToAllocate; Impl.Pointer = Impl->Allocate(Max()); @@ -801,7 +801,7 @@ public: void SetNum(size_t Count, bool bAllowShrinking = true) requires (CDefaultConstructible && CMovable) { size_t NumToAllocate = Count; - + NumToAllocate = NumToAllocate > Max() ? Impl->CalculateSlackGrow(Count, Max()) : NumToAllocate; NumToAllocate = NumToAllocate < Max() ? (bAllowShrinking ? Impl->CalculateSlackShrink(Count, Max()) : Max()) : NumToAllocate; @@ -829,7 +829,7 @@ public: return; } - + if (Count <= Num()) { Memory::Destruct(Impl.Pointer + Count, Num() - Count); @@ -847,7 +847,7 @@ public: void SetNum(size_t Count, const ElementType& InValue, bool bAllowShrinking = true) requires (CCopyConstructible && CMovable) { size_t NumToAllocate = Count; - + NumToAllocate = NumToAllocate > Max() ? Impl->CalculateSlackGrow(Count, Max()) : NumToAllocate; NumToAllocate = NumToAllocate < Max() ? (bAllowShrinking ? Impl->CalculateSlackShrink(Count, Max()) : Max()) : NumToAllocate; @@ -879,7 +879,7 @@ public: return; } - + if (Count <= Num()) { Memory::Destruct(Impl.Pointer + Count, Num() - Count); @@ -925,7 +925,7 @@ public: if (NumToAllocate == Max()) return; ElementType* OldAllocation = Impl.Pointer; - + Impl.ArrayMax = NumToAllocate; Impl.Pointer = Impl->Allocate(Max()); diff --git a/Redcraft.Utility/Source/Public/Containers/Iterator.h b/Redcraft.Utility/Source/Public/Containers/Iterator.h index 58f3292..808f818 100644 --- a/Redcraft.Utility/Source/Public/Containers/Iterator.h +++ b/Redcraft.Utility/Source/Public/Containers/Iterator.h @@ -3,7 +3,6 @@ #include "CoreTypes.h" #include "Templates/Invoke.h" #include "Templates/Utility.h" -#include "Templates/Optional.h" #include "Templates/Noncopyable.h" #include "TypeTraits/TypeTraits.h" #include "Miscellaneous/Compare.h" @@ -204,13 +203,10 @@ private: static_assert(CRandomAccessIterator>); -template -TReverseIterator(I) -> TReverseIterator; - template requires (!CSizedSentinelFor) inline constexpr bool bDisableSizedSentinelFor, TReverseIterator> = true; -/** An iterator adaptor which dereferences to an rvalue reference. */ +/** An iterator adaptor which dereferences to a rvalue reference. */ template class TMoveIterator final { @@ -281,9 +277,6 @@ private: static_assert(CRandomAccessIterator>); -template -TMoveIterator(I) -> TMoveIterator; - /** A sentinel adaptor for use with TMoveIterator. */ template class TMoveSentinel @@ -304,7 +297,7 @@ public: template requires (!CSameAs && CConstructibleFrom) FORCEINLINE constexpr explicit (!CConvertibleTo) TMoveSentinel(const TMoveSentinel& InValue) : Last(InValue.GetBase()) { } - + template requires (!CSameAs && CConstructibleFrom) FORCEINLINE constexpr explicit (!CConvertibleTo) TMoveSentinel(TMoveSentinel&& InValue) : Last(MoveTemp(InValue).GetBase()) { } @@ -316,7 +309,7 @@ public: template requires (CSentinelFor) NODISCARD FORCEINLINE constexpr bool operator==(const TMoveIterator& InValue) const& { return GetBase() == InValue.GetBase(); } - + template requires (CSizedSentinelFor) NODISCARD FORCEINLINE constexpr TCompareThreeWayResult operator<=>(const TMoveIterator& InValue) const& { return GetBase() <=> InValue.GetBase(); } @@ -337,9 +330,6 @@ private: static_assert(CSizedSentinelFor, TMoveIterator>); -template -TMoveSentinel(I) -> TMoveSentinel; - struct FDefaultSentinel { explicit FDefaultSentinel() = default; }; inline constexpr FDefaultSentinel DefaultSentinel{ }; @@ -456,47 +446,7 @@ private: static_assert(CContiguousIterator>); static_assert(CSizedSentinelFor>); -template -TCountedIterator(I, ptrdiff) -> TCountedIterator; - -/** An input iterator adapter that wraps a callable object. */ -template requires (CTOptional>> && CMoveConstructible - && CConstructibleFrom>, TInvokeResult> && CAssignableFrom>&, TInvokeResult>) -class TInputIterator final : private FNoncopyable -{ -public: - - using Inputer = F; - - using ElementType = typename TRemoveCVRef>::ValueType; - - FORCEINLINE constexpr TInputIterator() requires (CDefaultConstructible) : LookAhead(Invoke(Storage)) { }; - - template requires (!CSameAs> && CConstructibleFrom) - FORCEINLINE constexpr explicit TInputIterator(T&& InInputer) : Storage(Forward(InInputer)), LookAhead(Invoke(Storage)) { } - - NODISCARD FORCEINLINE constexpr bool operator==(FDefaultSentinel) const& { return !LookAhead.IsValid(); } - - NODISCARD FORCEINLINE constexpr const ElementType& operator*() const { return LookAhead.GetValue(); } - - FORCEINLINE constexpr TInputIterator& operator++() { LookAhead = Invoke(Storage); return *this; } - - FORCEINLINE constexpr void operator++(int) { LookAhead = Invoke(Storage); } - - NODISCARD FORCEINLINE constexpr const Inputer& GetInputer() const& { return Storage; } - NODISCARD FORCEINLINE constexpr Inputer GetInputer() && { return Storage; } - -private: - - Inputer Storage; - TOptional LookAhead; - -}; - -static_assert(CInputIterator(*)()>>); - -template -TInputIterator(F) -> TInputIterator; +NAMESPACE_PRIVATE_BEGIN /** An output iterator adapter that wraps a callable object. */ template @@ -572,7 +522,7 @@ private: public: FORCEINLINE constexpr TOutputIterator() requires (CDefaultConstructible) { check_code({ bIsProduced = false; }); } - + template requires (!CSameAs> && CConstructibleFrom) FORCEINLINE constexpr explicit TOutputIterator(T&& InOutputer) : Storage(Forward(InOutputer)) { check_code({ bIsProduced = false; }); } @@ -609,6 +559,8 @@ static_assert(COutputIterator, int32>); template TOutputIterator(F) -> TOutputIterator; +NAMESPACE_PRIVATE_END + /** Creates a TReverseIterator of type inferred from the argument. */ template requires (CBidirectionalIterator> && CConstructibleFrom, I>) NODISCARD FORCEINLINE constexpr auto MakeReverseIterator(I&& Iter) @@ -641,21 +593,21 @@ NODISCARD FORCEINLINE constexpr auto MakeCountedIterator(I&& Iter, ptrdiff N) template NODISCARD FORCEINLINE constexpr auto MakeFrontInserter(C& Container) { - return TOutputIterator([&Container](T&& A) { Container.PushFront(Forward(A)); }); + return NAMESPACE_PRIVATE::TOutputIterator([&Container](T&& A) { Container.PushFront(Forward(A)); }); } /** Creates an iterator adapter inserted in the back of the container. */ template NODISCARD FORCEINLINE constexpr auto MakeBackInserter(C& Container) { - return TOutputIterator([&Container](T&& A) { Container.PushBack(Forward(A)); }); + return NAMESPACE_PRIVATE::TOutputIterator([&Container](T&& A) { Container.PushBack(Forward(A)); }); } /** Creates an iterator adapter inserted in the container. */ template NODISCARD FORCEINLINE constexpr auto MakeInserter(C& Container, const typename C::ConstIterator& InIter) { - return TOutputIterator([&Container, Iter = InIter](T&& A) mutable { Iter = Container.Insert(Iter, Forward(A)); }); + return NAMESPACE_PRIVATE::TOutputIterator([&Container, Iter = InIter](T&& A) mutable { Iter = Container.Insert(Iter, Forward(A)); }); } NAMESPACE_BEGIN(Iteration) @@ -671,7 +623,7 @@ FORCEINLINE constexpr void Advance(I& Iter, ptrdiff N) else if constexpr (CBidirectionalIterator) { for (; N > 0; --N) ++Iter; - for (; N < 0; ++N) --Iter; + for (; N < 0; ++N) --Iter; } else {