refactor(*): replace the old with the new iterator and range library
This commit is contained in:
@ -1,16 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreTypes.h"
|
||||
#include "Range/Range.h"
|
||||
#include "Memory/Allocator.h"
|
||||
#include "Iterator/Iterator.h"
|
||||
#include "Templates/Utility.h"
|
||||
#include "Templates/TypeHash.h"
|
||||
#include "TypeTraits/TypeTraits.h"
|
||||
#include "Miscellaneous/Compare.h"
|
||||
#include "Memory/MemoryOperator.h"
|
||||
#include "Miscellaneous/Iterator.h"
|
||||
#include "Miscellaneous/Container.h"
|
||||
#include "Miscellaneous/AssertionMacros.h"
|
||||
#include "Miscellaneous/ConstantIterator.h"
|
||||
|
||||
NAMESPACE_REDCRAFT_BEGIN
|
||||
NAMESPACE_MODULE_BEGIN(Redcraft)
|
||||
@ -57,18 +56,24 @@ public:
|
||||
|
||||
/** Constructs the container with 'Count' copies of elements with 'InValue'. */
|
||||
TArray(size_t Count, const FElementType& InValue) requires (CCopyConstructible<FElementType>)
|
||||
: TArray(MakeCountedConstantIterator(InValue, Count), DefaultSentinel)
|
||||
: TArray(Range::Repeat(InValue, Count))
|
||||
{ }
|
||||
|
||||
/** Constructs the container with the contents of the range ['First', 'Last'). */
|
||||
template <CInputIterator I, CSentinelFor<I> S> requires (CConstructibleFrom<FElementType, TIteratorReferenceType<I>> && CMovable<FElementType>)
|
||||
template <CInputIterator I, CSentinelFor<I> S> requires (CConstructibleFrom<FElementType, TIteratorReference<I>> && CMovable<FElementType>)
|
||||
TArray(I First, S Last)
|
||||
{
|
||||
if constexpr (CForwardIterator<I>)
|
||||
{
|
||||
if constexpr (CSizedSentinelFor<S, I>) { checkf(First - Last <= 0, TEXT("Illegal range iterator. Please check First <= Last.")); }
|
||||
size_t Count = 0;
|
||||
|
||||
const size_t Count = Iteration::Distance(First, Last);
|
||||
if constexpr (CSizedSentinelFor<S, I>)
|
||||
{
|
||||
checkf(First - Last <= 0, TEXT("Illegal range iterator. Please check First <= Last."));
|
||||
|
||||
Count = Last - First;
|
||||
}
|
||||
else for (I Iter = First; Iter != Last; ++Iter) ++Count;
|
||||
|
||||
Impl.ArrayNum = Count;
|
||||
Impl.ArrayMax = Impl->CalculateSlackReserve(Num());
|
||||
@ -93,6 +98,10 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
/** Constructs the container with the contents of the range. */
|
||||
template <CInputRange R> requires (!CSameAs<TRemoveCVRef<R>, TArray> && CConstructibleFrom<FElementType, TRangeReference<R>> && CMovable<FElementType>)
|
||||
FORCEINLINE explicit TArray(R&& Range) : TArray(Range::Begin(Range), Range::End(Range)) { }
|
||||
|
||||
/** Copy constructor. Constructs the container with the copy of the contents of 'InValue'. */
|
||||
TArray(const TArray& InValue) requires (CCopyConstructible<FElementType>)
|
||||
{
|
||||
@ -129,7 +138,7 @@ public:
|
||||
}
|
||||
|
||||
/** Constructs the container with the contents of the initializer list. */
|
||||
FORCEINLINE TArray(initializer_list<FElementType> IL) requires (CCopyConstructible<FElementType>) : TArray(Iteration::Begin(IL), Iteration::End(IL)) { }
|
||||
FORCEINLINE TArray(initializer_list<FElementType> IL) requires (CCopyConstructible<FElementType>) : TArray(Range::Begin(IL), Range::End(IL)) { }
|
||||
|
||||
/** Destructs the array. The destructors of the elements are called and the used storage is deallocated. */
|
||||
~TArray()
|
||||
@ -243,38 +252,38 @@ public:
|
||||
/** Replaces the contents with those identified by initializer list. */
|
||||
TArray& operator=(initializer_list<FElementType> IL) requires (CCopyable<FElementType>)
|
||||
{
|
||||
size_t NumToAllocate = GetNum(IL);
|
||||
size_t NumToAllocate = Range::Num(IL);
|
||||
|
||||
NumToAllocate = NumToAllocate > Max() ? Impl->CalculateSlackGrow(GetNum(IL), Max()) : NumToAllocate;
|
||||
NumToAllocate = NumToAllocate < Max() ? Impl->CalculateSlackShrink(GetNum(IL), Max()) : NumToAllocate;
|
||||
NumToAllocate = NumToAllocate > Max() ? Impl->CalculateSlackGrow (Range::Num(IL), Max()) : NumToAllocate;
|
||||
NumToAllocate = NumToAllocate < Max() ? Impl->CalculateSlackShrink(Range::Num(IL), Max()) : NumToAllocate;
|
||||
|
||||
if (NumToAllocate != Max())
|
||||
{
|
||||
Memory::Destruct(Impl.Pointer, Num());
|
||||
Impl->Deallocate(Impl.Pointer);
|
||||
|
||||
Impl.ArrayNum = GetNum(IL);
|
||||
Impl.ArrayNum = Range::Num(IL);
|
||||
Impl.ArrayMax = NumToAllocate;
|
||||
Impl.Pointer = Impl->Allocate(Max());
|
||||
|
||||
Memory::CopyConstruct<FElementType>(Impl.Pointer, NAMESPACE_REDCRAFT::GetData(IL), Num());
|
||||
Memory::CopyConstruct<FElementType>(Impl.Pointer, Range::GetData(IL), Num());
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
if (GetNum(IL) <= Num())
|
||||
if (Range::Num(IL) <= Num())
|
||||
{
|
||||
Memory::CopyAssign(Impl.Pointer, NAMESPACE_REDCRAFT::GetData(IL), GetNum(IL));
|
||||
Memory::Destruct(Impl.Pointer + GetNum(IL), Num() - GetNum(IL));
|
||||
Memory::CopyAssign(Impl.Pointer, Range::GetData(IL), Range::Num(IL));
|
||||
Memory::Destruct(Impl.Pointer + Range::Num(IL), Num() - Range::Num(IL));
|
||||
}
|
||||
else if (GetNum(IL) <= Max())
|
||||
else if (Range::Num(IL) <= Max())
|
||||
{
|
||||
Memory::CopyAssign(Impl.Pointer, NAMESPACE_REDCRAFT::GetData(IL), Num());
|
||||
Memory::CopyConstruct<FElementType>(Impl.Pointer + Num(), NAMESPACE_REDCRAFT::GetData(IL) + Num(), GetNum(IL) - Num());
|
||||
Memory::CopyAssign(Impl.Pointer, Range::GetData(IL), Num());
|
||||
Memory::CopyConstruct<FElementType>(Impl.Pointer + Num(), Range::GetData(IL) + Num(), Range::Num(IL) - Num());
|
||||
}
|
||||
else check_no_entry();
|
||||
|
||||
Impl.ArrayNum = GetNum(IL);
|
||||
Impl.ArrayNum = Range::Num(IL);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@ -406,22 +415,29 @@ public:
|
||||
{
|
||||
checkf(IsValidIterator(Iter), TEXT("Read access violation. Please check IsValidIterator()."));
|
||||
|
||||
return Insert(Iter, MakeCountedConstantIterator(InValue, Count), DefaultSentinel);
|
||||
return Insert(Iter, Range::Repeat(InValue, Count));
|
||||
}
|
||||
|
||||
/** Inserts elements from range ['First', 'Last') before 'Iter'. */
|
||||
template <CInputIterator I, CSentinelFor<I> S> requires (CConstructibleFrom<FElementType, TIteratorReferenceType<I>>
|
||||
&& CAssignableFrom<FElementType&, TIteratorReferenceType<I>> && CMovable<FElementType>)
|
||||
template <CInputIterator I, CSentinelFor<I> S> requires (CConstructibleFrom<FElementType, TIteratorReference<I>>
|
||||
&& CAssignableFrom<FElementType&, TIteratorReference<I>> && CMovable<FElementType>)
|
||||
FIterator Insert(FConstIterator Iter, I First, S Last)
|
||||
{
|
||||
checkf(IsValidIterator(Iter), TEXT("Read access violation. Please check IsValidIterator()."));
|
||||
|
||||
if constexpr (CForwardIterator<I>)
|
||||
{
|
||||
if constexpr (CSizedSentinelFor<S, I>) { checkf(First - Last <= 0, TEXT("Illegal range iterator. Please check First <= Last.")); }
|
||||
|
||||
const size_t InsertIndex = Iter - Begin();
|
||||
const size_t Count = Iteration::Distance(First, Last);
|
||||
|
||||
size_t Count = 0;
|
||||
|
||||
if constexpr (CSizedSentinelFor<S, I>)
|
||||
{
|
||||
checkf(First - Last <= 0, TEXT("Illegal range iterator. Please check First <= Last."));
|
||||
|
||||
Count = Last - First;
|
||||
}
|
||||
else for (I Jter = First; Jter != Last; ++Jter) ++Count;
|
||||
|
||||
if (Count == 0) return FIterator(this, Impl.Pointer + InsertIndex);
|
||||
|
||||
@ -523,10 +539,18 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
/** Inserts elements from range before 'Iter'. */
|
||||
template <CInputRange R> requires (CConstructibleFrom<FElementType, TRangeReference<R>>
|
||||
&& CAssignableFrom<FElementType&, TRangeReference<R>> && CMovable<FElementType>)
|
||||
FORCEINLINE FIterator Insert(FConstIterator Iter, R&& Range)
|
||||
{
|
||||
return Insert(Iter, Range::Begin(Range), Range::End(Range));
|
||||
}
|
||||
|
||||
/** Inserts elements from initializer list before 'Iter' in the container. */
|
||||
FORCEINLINE FIterator Insert(FConstIterator Iter, initializer_list<FElementType> IL) requires (CCopyable<FElementType>)
|
||||
{
|
||||
return Insert(Iter, Iteration::Begin(IL), Iteration::End(IL));
|
||||
return Insert(Iter, Range::Begin(IL), Range::End(IL));
|
||||
}
|
||||
|
||||
/** Inserts a new element into the container directly before 'Iter'. */
|
||||
@ -1058,7 +1082,10 @@ private:
|
||||
};
|
||||
|
||||
template <typename I, typename S>
|
||||
TArray(I, S) -> TArray<TIteratorElementType<I>>;
|
||||
TArray(I, S) -> TArray<TIteratorElement<I>>;
|
||||
|
||||
template <typename R>
|
||||
TArray(R) -> TArray<TRangeElement<R>>;
|
||||
|
||||
template <typename T>
|
||||
TArray(initializer_list<T>) -> TArray<T>;
|
||||
|
@ -1,16 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreTypes.h"
|
||||
#include "Range/Range.h"
|
||||
#include "Memory/Address.h"
|
||||
#include "Memory/Allocator.h"
|
||||
#include "Containers/Array.h"
|
||||
#include "Iterator/Iterator.h"
|
||||
#include "Templates/Utility.h"
|
||||
#include "Templates/TypeHash.h"
|
||||
#include "Containers/StaticArray.h"
|
||||
#include "TypeTraits/TypeTraits.h"
|
||||
#include "Miscellaneous/Compare.h"
|
||||
#include "Miscellaneous/Iterator.h"
|
||||
#include "Miscellaneous/Container.h"
|
||||
#include "Miscellaneous/AssertionMacros.h"
|
||||
|
||||
NAMESPACE_REDCRAFT_BEGIN
|
||||
@ -29,7 +29,7 @@ class TArrayView
|
||||
{
|
||||
public:
|
||||
|
||||
using FElementType = T;
|
||||
using FElementType = TRemoveCV<T>;
|
||||
|
||||
using FReference = T&;
|
||||
|
||||
@ -53,7 +53,7 @@ public:
|
||||
}
|
||||
|
||||
/** Constructs an array view that is a view over the range ['InFirst', 'InFirst' + 'Count'). */
|
||||
template <CContiguousIterator I> requires (CConvertibleTo<TIteratorElementType<I>(*)[], FElementType(*)[]>)
|
||||
template <CContiguousIterator I> requires (CConvertibleTo<TIteratorReference<I>, T> && CSameAs<TRemoveCVRef<TIteratorReference<I>>, TRemoveCVRef<T>>)
|
||||
FORCEINLINE constexpr explicit (Extent != DynamicExtent) TArrayView(I InFirst, size_t InCount)
|
||||
{
|
||||
checkf(Extent == DynamicExtent || Extent == InCount, TEXT("Illegal range count. Please check InCount."));
|
||||
@ -67,7 +67,7 @@ public:
|
||||
}
|
||||
|
||||
/** Constructs an array view that is a view over the range ['InFirst', 'InLast'). */
|
||||
template <CContiguousIterator I, CSizedSentinelFor<I> S> requires (CConvertibleTo<TIteratorElementType<I>(*)[], FElementType(*)[]>)
|
||||
template <CContiguousIterator I, CSizedSentinelFor<I> S> requires (CConvertibleTo<TIteratorReference<I>, T> && CSameAs<TRemoveCVRef<TIteratorReference<I>>, TRemoveCVRef<T>>)
|
||||
FORCEINLINE constexpr explicit (Extent != DynamicExtent) TArrayView(I InFirst, S InLast)
|
||||
{
|
||||
checkf(Extent == DynamicExtent || Extent == InLast - InFirst, TEXT("Illegal range iterator. Please check InLast - InFirst."));
|
||||
@ -156,36 +156,36 @@ public:
|
||||
|
||||
/** Obtains an array view that is a view over the first 'Count' elements of this array view. */
|
||||
template <size_t Count> requires (Extent == DynamicExtent || Extent >= Count)
|
||||
NODISCARD FORCEINLINE constexpr TArrayView<FElementType, Count> First() const
|
||||
NODISCARD FORCEINLINE constexpr TArrayView<T, Count> First() const
|
||||
{
|
||||
checkf(Count <= Num(), TEXT("Illegal subview range. Please check Count."));
|
||||
|
||||
return TArrayView<FElementType, Count>(Begin(), Count);
|
||||
return TArrayView<T, Count>(Begin(), Count);
|
||||
}
|
||||
|
||||
/** Obtains an array view that is a view over the first 'Count' elements of this array view. */
|
||||
NODISCARD FORCEINLINE constexpr TArrayView<FElementType, DynamicExtent> First(size_t Count) const
|
||||
NODISCARD FORCEINLINE constexpr TArrayView<T, DynamicExtent> First(size_t Count) const
|
||||
{
|
||||
checkf(Count <= Num(), TEXT("Illegal subview range. Please check Count."));
|
||||
|
||||
return TArrayView<FElementType, DynamicExtent>(Begin(), Count);
|
||||
return TArrayView<T, DynamicExtent>(Begin(), Count);
|
||||
}
|
||||
|
||||
/** Obtains an array view that is a view over the last 'Count' elements of this array view. */
|
||||
template <size_t Count> requires (Extent == DynamicExtent || Extent >= Count)
|
||||
NODISCARD FORCEINLINE constexpr TArrayView<FElementType, Count> Last() const
|
||||
NODISCARD FORCEINLINE constexpr TArrayView<T, Count> Last() const
|
||||
{
|
||||
checkf(Count <= Num(), TEXT("Illegal subview range. Please check Count."));
|
||||
|
||||
return TArrayView<FElementType, Count>(End() - Count, Count);
|
||||
return TArrayView<T, Count>(End() - Count, Count);
|
||||
}
|
||||
|
||||
/** Obtains an array view that is a view over the last 'Count' elements of this array view. */
|
||||
NODISCARD FORCEINLINE constexpr TArrayView<FElementType, DynamicExtent> Last(size_t Count) const
|
||||
NODISCARD FORCEINLINE constexpr TArrayView<T, DynamicExtent> Last(size_t Count) const
|
||||
{
|
||||
checkf(Count <= Num(), TEXT("Illegal subview range. Please check Count."));
|
||||
|
||||
return TArrayView<FElementType, DynamicExtent>(End() - Count, Count);
|
||||
return TArrayView<T, DynamicExtent>(End() - Count, Count);
|
||||
}
|
||||
|
||||
/** Obtains an array view that is a view over the 'Count' elements of this array view starting at 'Offset'. */
|
||||
@ -198,11 +198,11 @@ public:
|
||||
|
||||
if constexpr (Count != DynamicExtent)
|
||||
{
|
||||
return TArrayView<FElementType, SubviewExtent>(Begin() + Offset, Count);
|
||||
return TArrayView<T, SubviewExtent>(Begin() + Offset, Count);
|
||||
}
|
||||
else
|
||||
{
|
||||
return TArrayView<FElementType, SubviewExtent>(Begin() + Offset, Num() - Offset);
|
||||
return TArrayView<T, SubviewExtent>(Begin() + Offset, Num() - Offset);
|
||||
}
|
||||
}
|
||||
|
||||
@ -213,11 +213,11 @@ public:
|
||||
|
||||
if (Count != DynamicExtent)
|
||||
{
|
||||
return TArrayView<FElementType, DynamicExtent>(Begin() + Offset, Count);
|
||||
return TArrayView<T, DynamicExtent>(Begin() + Offset, Count);
|
||||
}
|
||||
else
|
||||
{
|
||||
return TArrayView<FElementType, DynamicExtent>(Begin() + Offset, Num() - Offset);
|
||||
return TArrayView<T, DynamicExtent>(Begin() + Offset, Num() - Offset);
|
||||
}
|
||||
}
|
||||
|
||||
@ -245,7 +245,7 @@ public:
|
||||
}
|
||||
|
||||
/** @return The pointer to the underlying element storage. */
|
||||
NODISCARD FORCEINLINE constexpr FElementType* GetData() const { return Impl.Pointer; }
|
||||
NODISCARD FORCEINLINE constexpr T* GetData() const { return Impl.Pointer; }
|
||||
|
||||
/** @return The iterator to the first or end element. */
|
||||
NODISCARD FORCEINLINE constexpr FIterator Begin() const { return FIterator(this, Impl.Pointer); }
|
||||
@ -291,7 +291,7 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
struct FImplWithoutNum { FElementType* Pointer; };
|
||||
struct FImplWithoutNum { T* Pointer; };
|
||||
|
||||
struct FImplWithNum : FImplWithoutNum { size_t ArrayNum; };
|
||||
|
||||
@ -367,7 +367,7 @@ public:
|
||||
};
|
||||
|
||||
template <typename I, typename S>
|
||||
TArrayView(I, S) -> TArrayView<TRemoveReference<TIteratorReferenceType<I>>>;
|
||||
TArrayView(I, S) -> TArrayView<TRemoveReference<TIteratorReference<I>>>;
|
||||
|
||||
template <typename T, size_t N>
|
||||
TArrayView(T(&)[N]) -> TArrayView<T, N>;
|
||||
|
@ -1,16 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreTypes.h"
|
||||
#include "Range/Range.h"
|
||||
#include "Memory/Memory.h"
|
||||
#include "Memory/Allocator.h"
|
||||
#include "Iterator/Iterator.h"
|
||||
#include "Templates/Utility.h"
|
||||
#include "Templates/TypeHash.h"
|
||||
#include "Templates/Noncopyable.h"
|
||||
#include "TypeTraits/TypeTraits.h"
|
||||
#include "Miscellaneous/Compare.h"
|
||||
#include "Memory/MemoryOperator.h"
|
||||
#include "Miscellaneous/Iterator.h"
|
||||
#include "Miscellaneous/Container.h"
|
||||
#include "Miscellaneous/AssertionMacros.h"
|
||||
|
||||
NAMESPACE_REDCRAFT_BEGIN
|
||||
@ -101,16 +101,22 @@ public:
|
||||
}
|
||||
|
||||
/** Constructs the bitset with the bits of the range ['First', 'Last'). */
|
||||
template <CInputIterator I, CSentinelFor<I> S> requires (CConstructibleFrom<bool, TIteratorReferenceType<I>>)
|
||||
template <CInputIterator I, CSentinelFor<I> S> requires (CConstructibleFrom<bool, TIteratorReference<I>>)
|
||||
TBitset(I First, S Last)
|
||||
{
|
||||
if constexpr (CForwardIterator<I>)
|
||||
{
|
||||
if constexpr (CSizedSentinelFor<S, I>) { checkf(First - Last <= 0, TEXT("Illegal range iterator. Please check First <= Last.")); }
|
||||
size_t Count = 0;
|
||||
|
||||
const size_t InCount = Iteration::Distance(First, Last);
|
||||
if constexpr (CSizedSentinelFor<S, I>)
|
||||
{
|
||||
checkf(First - Last <= 0, TEXT("Illegal range iterator. Please check First <= Last."));
|
||||
|
||||
new (this) TBitset(InCount);
|
||||
Count = Last - First;
|
||||
}
|
||||
else for (I Iter = First; Iter != Last; ++Iter) ++Count;
|
||||
|
||||
new (this) TBitset(Count);
|
||||
|
||||
for (FReference Ref: *this) Ref = *First++;
|
||||
}
|
||||
@ -126,6 +132,10 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
/** Constructs the bitset with the bits of the range. */
|
||||
template <CInputRange R> requires (!CSameAs<TRemoveCVRef<R>, TBitset> && CConstructibleFrom<bool, TRangeReference<R>>)
|
||||
FORCEINLINE explicit TBitset(R&& Range) : TBitset(Range::Begin(Range), Range::End(Range)) { }
|
||||
|
||||
/** Copy constructor. Constructs the bitset with the copy of the bits of 'InValue'. */
|
||||
FORCEINLINE TBitset(const TBitset& InValue)
|
||||
{
|
||||
@ -160,7 +170,7 @@ public:
|
||||
}
|
||||
|
||||
/** Constructs the bitset with the bits of the initializer list. */
|
||||
FORCEINLINE TBitset(initializer_list<bool> IL) : TBitset(Iteration::Begin(IL), Iteration::End(IL)) { }
|
||||
FORCEINLINE TBitset(initializer_list<bool> IL) : TBitset(Range::Begin(IL), Range::End(IL)) { }
|
||||
|
||||
/** Destructs the bitset. The storage is deallocated. */
|
||||
~TBitset()
|
||||
@ -228,9 +238,9 @@ public:
|
||||
/** Replaces the bits with those identified by initializer list. */
|
||||
TBitset& operator=(initializer_list<bool> IL)
|
||||
{
|
||||
auto First = Iteration::Begin(IL);
|
||||
auto First = Range::Begin(IL);
|
||||
|
||||
const size_t BlocksCount = (GetNum(IL) + BlockWidth - 1) / BlockWidth;
|
||||
const size_t BlocksCount = (Range::Num(IL) + BlockWidth - 1) / BlockWidth;
|
||||
|
||||
size_t NumToAllocate = BlocksCount;
|
||||
|
||||
@ -241,7 +251,7 @@ public:
|
||||
{
|
||||
Impl->Deallocate(Impl.Pointer);
|
||||
|
||||
Impl.BitsetNum = GetNum(IL);
|
||||
Impl.BitsetNum = Range::Num(IL);
|
||||
Impl.BlocksMax = NumToAllocate;
|
||||
Impl.Pointer = Impl->Allocate(MaxBlocks());
|
||||
|
||||
@ -250,7 +260,7 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
Impl.BitsetNum = GetNum(IL);
|
||||
Impl.BitsetNum = Range::Num(IL);
|
||||
|
||||
for (FReference Ref : *this) Ref = *First++;
|
||||
|
||||
|
@ -1,16 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreTypes.h"
|
||||
#include "Range/Range.h"
|
||||
#include "Memory/Allocator.h"
|
||||
#include "Iterator/Iterator.h"
|
||||
#include "Templates/Utility.h"
|
||||
#include "Templates/TypeHash.h"
|
||||
#include "TypeTraits/TypeTraits.h"
|
||||
#include "Miscellaneous/Compare.h"
|
||||
#include "Memory/MemoryOperator.h"
|
||||
#include "Miscellaneous/Iterator.h"
|
||||
#include "Miscellaneous/Container.h"
|
||||
#include "Miscellaneous/AssertionMacros.h"
|
||||
#include "Miscellaneous/ConstantIterator.h"
|
||||
|
||||
NAMESPACE_REDCRAFT_BEGIN
|
||||
NAMESPACE_MODULE_BEGIN(Redcraft)
|
||||
@ -76,11 +75,11 @@ public:
|
||||
|
||||
/** Constructs the container with 'Count' copies of elements with 'InValue'. */
|
||||
TList(size_t Count, const FElementType& InValue) requires (CCopyable<FElementType>)
|
||||
: TList(MakeCountedConstantIterator(InValue, Count), DefaultSentinel)
|
||||
: TList(Range::Repeat(InValue, Count))
|
||||
{ }
|
||||
|
||||
/** Constructs the container with the contents of the range ['First', 'Last'). */
|
||||
template <CInputIterator I, CSentinelFor<I> S> requires (CConstructibleFrom<FElementType, TIteratorReferenceType<I>>)
|
||||
template <CInputIterator I, CSentinelFor<I> S> requires (CConstructibleFrom<FElementType, TIteratorReference<I>>)
|
||||
TList(I First, S Last) : TList()
|
||||
{
|
||||
FNode* EndNode = Impl.HeadNode->PrevNode;
|
||||
@ -101,6 +100,10 @@ public:
|
||||
Impl.HeadNode->PrevNode = EndNode;
|
||||
}
|
||||
|
||||
/** Constructs the container with the contents of the range. */
|
||||
template <CInputRange R> requires (!CSameAs<TRemoveCVRef<R>, TList> && CConstructibleFrom<FElementType, TRangeReference<R>>)
|
||||
FORCEINLINE explicit TList(R&& Range) : TList(Range::Begin(Range), Range::End(Range)) { }
|
||||
|
||||
/** Copy constructor. Constructs the container with the copy of the contents of 'InValue'. */
|
||||
FORCEINLINE TList(const TList& InValue) requires (CCopyConstructible<FElementType>) : TList(InValue.Begin(), InValue.End()) { }
|
||||
|
||||
@ -108,7 +111,7 @@ public:
|
||||
FORCEINLINE TList(TList&& InValue) : TList() { Swap(*this, InValue); }
|
||||
|
||||
/** Constructs the container with the contents of the initializer list. */
|
||||
FORCEINLINE TList(initializer_list<FElementType> IL) requires (CCopyConstructible<FElementType>) : TList(Iteration::Begin(IL), Iteration::End(IL)) { }
|
||||
FORCEINLINE TList(initializer_list<FElementType> IL) requires (CCopyConstructible<FElementType>) : TList(Range::Begin(IL), Range::End(IL)) { }
|
||||
|
||||
/** Destructs the list. The destructors of the elements are called and the used storage is deallocated. */
|
||||
~TList()
|
||||
@ -168,10 +171,10 @@ public:
|
||||
/** Replaces the contents with those identified by initializer list. */
|
||||
TList& operator=(initializer_list<FElementType> IL) requires (CCopyable<FElementType>)
|
||||
{
|
||||
FIterator ThisIter = Begin();
|
||||
const FElementType* OtherIter = Iteration::Begin(IL);
|
||||
FIterator ThisIter = Begin();
|
||||
const FElementType* OtherIter = Range::Begin(IL);
|
||||
|
||||
while (ThisIter != End() && OtherIter != Iteration::End(IL))
|
||||
while (ThisIter != End() && OtherIter != Range::End(IL))
|
||||
{
|
||||
*ThisIter = *OtherIter;
|
||||
|
||||
@ -181,18 +184,18 @@ public:
|
||||
|
||||
if (ThisIter == End())
|
||||
{
|
||||
while (OtherIter != Iteration::End(IL))
|
||||
while (OtherIter != Range::End(IL))
|
||||
{
|
||||
EmplaceBack(*OtherIter);
|
||||
++OtherIter;
|
||||
}
|
||||
}
|
||||
else if (OtherIter == Iteration::End(IL))
|
||||
else if (OtherIter == Range::End(IL))
|
||||
{
|
||||
Erase(ThisIter, End());
|
||||
}
|
||||
|
||||
Impl.ListNum = GetNum(IL);
|
||||
Impl.ListNum = Range::Num(IL);
|
||||
|
||||
return *this;
|
||||
}
|
||||
@ -244,11 +247,11 @@ public:
|
||||
/** Inserts 'Count' copies of the 'InValue' before 'Iter' in the container. */
|
||||
FIterator Insert(FConstIterator Iter, size_t Count, const FElementType& InValue) requires (CCopyConstructible<FElementType>)
|
||||
{
|
||||
return Insert(Iter, MakeCountedConstantIterator(InValue, Count), DefaultSentinel);
|
||||
return Insert(Iter, Range::Repeat(InValue, Count));
|
||||
}
|
||||
|
||||
/** Inserts elements from range ['First', 'Last') before 'Iter'. */
|
||||
template <CInputIterator I, CSentinelFor<I> S> requires (CConstructibleFrom<FElementType, TIteratorReferenceType<I>>)
|
||||
template <CInputIterator I, CSentinelFor<I> S> requires (CConstructibleFrom<FElementType, TIteratorReference<I>>)
|
||||
FIterator Insert(FConstIterator Iter, I First, S Last)
|
||||
{
|
||||
if (First == Last) return FIterator(Iter.Pointer);
|
||||
@ -282,8 +285,12 @@ public:
|
||||
return FIterator(FirstNode);
|
||||
}
|
||||
|
||||
/** Inserts elements from range ['First', 'Last') before 'Iter'. */
|
||||
template <CInputRange R> requires (CConstructibleFrom<FElementType, TRangeReference<R>>)
|
||||
FORCEINLINE FIterator Insert(FConstIterator Iter, R&& Range) { return Insert(Iter, Range::Begin(Range), Range::End(Range)); }
|
||||
|
||||
/** Inserts elements from initializer list before 'Iter' in the container. */
|
||||
FORCEINLINE FIterator Insert(FConstIterator Iter, initializer_list<FElementType> IL) requires (CCopyConstructible<FElementType>) { return Insert(Iter, Iteration::Begin(IL), Iteration::End(IL)); }
|
||||
FORCEINLINE FIterator Insert(FConstIterator Iter, initializer_list<FElementType> IL) requires (CCopyConstructible<FElementType>) { return Insert(Iter, Range::Begin(IL), Range::End(IL)); }
|
||||
|
||||
/** Inserts a new element into the container directly before 'Iter'. */
|
||||
template <typename... Ts> requires (CConstructibleFrom<FElementType, Ts...>)
|
||||
@ -381,7 +388,7 @@ public:
|
||||
{
|
||||
FIterator First = End();
|
||||
|
||||
Iteration::Advance(First, Count - Impl.ListNum);
|
||||
for (size_t Index = 0; Index != Impl.ListNum - Count; ++Index) --First;
|
||||
|
||||
Erase(First, End());
|
||||
|
||||
@ -417,7 +424,7 @@ public:
|
||||
{
|
||||
FIterator First = End();
|
||||
|
||||
Iteration::Advance(First, Count - Impl.ListNum);
|
||||
for (size_t Index = 0; Index != Impl.ListNum - Count; ++Index) --First;
|
||||
|
||||
Erase(First, End());
|
||||
|
||||
@ -598,7 +605,10 @@ private:
|
||||
};
|
||||
|
||||
template <typename I, typename S>
|
||||
TList(I, S) -> TList<TIteratorElementType<I>>;
|
||||
TList(I, S) -> TList<TIteratorElement<I>>;
|
||||
|
||||
template <typename R>
|
||||
TList(R) -> TList<TRangeElement<R>>;
|
||||
|
||||
template <typename T>
|
||||
TList(initializer_list<T>) -> TList<T>;
|
||||
|
@ -1,13 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreTypes.h"
|
||||
#include "Range/Range.h"
|
||||
#include "Templates/Meta.h"
|
||||
#include "Iterator/Iterator.h"
|
||||
#include "Templates/Utility.h"
|
||||
#include "Templates/TypeHash.h"
|
||||
#include "TypeTraits/TypeTraits.h"
|
||||
#include "Miscellaneous/Compare.h"
|
||||
#include "Miscellaneous/Iterator.h"
|
||||
#include "Miscellaneous/Container.h"
|
||||
#include "Miscellaneous/AssertionMacros.h"
|
||||
|
||||
NAMESPACE_REDCRAFT_BEGIN
|
||||
|
@ -1,14 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreTypes.h"
|
||||
#include "Range/Range.h"
|
||||
#include "Iterator/Iterator.h"
|
||||
#include "Templates/Utility.h"
|
||||
#include "Templates/TypeHash.h"
|
||||
#include "Templates/Noncopyable.h"
|
||||
#include "TypeTraits/TypeTraits.h"
|
||||
#include "Miscellaneous/Compare.h"
|
||||
#include "Memory/MemoryOperator.h"
|
||||
#include "Miscellaneous/Iterator.h"
|
||||
#include "Miscellaneous/Container.h"
|
||||
#include "Miscellaneous/AssertionMacros.h"
|
||||
|
||||
NAMESPACE_REDCRAFT_BEGIN
|
||||
|
Reference in New Issue
Block a user