Compare commits
10 Commits
f54386d102
...
85199119b3
Author | SHA1 | Date | |
---|---|---|---|
85199119b3 | |||
78d4955e03 | |||
8f36410346 | |||
87e48e5ca1 | |||
93b3a17f06 | |||
6ea768781d | |||
dff6050a3b | |||
ae964ebd0a | |||
8be89d0bbc | |||
80238de712 |
@ -1,14 +1,18 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CoreTypes.h"
|
#include "CoreTypes.h"
|
||||||
#include "Range/Range.h"
|
#include "TypeTraits/TypeTraits.h"
|
||||||
#include "Memory/Allocator.h"
|
|
||||||
#include "Iterator/Iterator.h"
|
|
||||||
#include "Templates/Utility.h"
|
#include "Templates/Utility.h"
|
||||||
#include "Templates/TypeHash.h"
|
#include "Templates/TypeHash.h"
|
||||||
#include "TypeTraits/TypeTraits.h"
|
#include "Memory/Allocator.h"
|
||||||
#include "Miscellaneous/Compare.h"
|
|
||||||
#include "Memory/MemoryOperator.h"
|
#include "Memory/MemoryOperator.h"
|
||||||
|
#include "Iterator/Utility.h"
|
||||||
|
#include "Iterator/BasicIterator.h"
|
||||||
|
#include "Iterator/Sentinel.h"
|
||||||
|
#include "Iterator/ReverseIterator.h"
|
||||||
|
#include "Range/Utility.h"
|
||||||
|
#include "Range/Factory.h"
|
||||||
|
#include "Miscellaneous/Compare.h"
|
||||||
#include "Miscellaneous/AssertionMacros.h"
|
#include "Miscellaneous/AssertionMacros.h"
|
||||||
|
|
||||||
NAMESPACE_REDCRAFT_BEGIN
|
NAMESPACE_REDCRAFT_BEGIN
|
||||||
@ -45,7 +49,7 @@ public:
|
|||||||
FORCEINLINE TArray() : TArray(0) { }
|
FORCEINLINE TArray() : TArray(0) { }
|
||||||
|
|
||||||
/** Constructs the container with 'Count' default instances of T. */
|
/** Constructs the container with 'Count' default instances of T. */
|
||||||
explicit TArray(size_t Count) requires (CDefaultConstructible<FElementType>)
|
explicit TArray(size_t Count) requires (CDefaultConstructible<T>)
|
||||||
{
|
{
|
||||||
Impl.ArrayNum = Count;
|
Impl.ArrayNum = Count;
|
||||||
Impl.ArrayMax = Impl->CalculateSlackReserve(Num());
|
Impl.ArrayMax = Impl->CalculateSlackReserve(Num());
|
||||||
@ -55,13 +59,13 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Constructs the container with 'Count' copies of elements with 'InValue'. */
|
/** Constructs the container with 'Count' copies of elements with 'InValue'. */
|
||||||
TArray(size_t Count, const FElementType& InValue) requires (CCopyConstructible<FElementType>)
|
FORCEINLINE explicit TArray(size_t Count, const FElementType& InValue) requires (CCopyConstructible<T>)
|
||||||
: TArray(Range::Repeat(InValue, Count))
|
: TArray(Range::Repeat(InValue, Count))
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
/** Constructs the container with the contents of the range ['First', 'Last'). */
|
/** Constructs the container with the contents of the range ['First', 'Last'). */
|
||||||
template <CInputIterator I, CSentinelFor<I> S> requires (CConstructibleFrom<FElementType, TIteratorReference<I>> && CMovable<FElementType>)
|
template <CInputIterator I, CSentinelFor<I> S> requires (CConstructibleFrom<T, TIteratorReference<I>> && CMovable<T>)
|
||||||
TArray(I First, S Last)
|
explicit TArray(I First, S Last)
|
||||||
{
|
{
|
||||||
if constexpr (CForwardIterator<I>)
|
if constexpr (CForwardIterator<I>)
|
||||||
{
|
{
|
||||||
@ -99,11 +103,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Constructs the container with the contents of the range. */
|
/** Constructs the container with the contents of the range. */
|
||||||
template <CInputRange R> requires (!CSameAs<TRemoveCVRef<R>, TArray> && CConstructibleFrom<FElementType, TRangeReference<R>> && CMovable<FElementType>)
|
template <CInputRange R> requires (!CSameAs<TRemoveCVRef<R>, TArray> && CConstructibleFrom<T, TRangeReference<R>> && CMovable<T>)
|
||||||
FORCEINLINE explicit TArray(R&& Range) : TArray(Range::Begin(Range), Range::End(Range)) { }
|
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'. */
|
/** Copy constructor. Constructs the container with the copy of the contents of 'InValue'. */
|
||||||
TArray(const TArray& InValue) requires (CCopyConstructible<FElementType>)
|
TArray(const TArray& InValue) requires (CCopyConstructible<T>)
|
||||||
{
|
{
|
||||||
Impl.ArrayNum = InValue.Num();
|
Impl.ArrayNum = InValue.Num();
|
||||||
Impl.ArrayMax = Impl->CalculateSlackReserve(Num());
|
Impl.ArrayMax = Impl->CalculateSlackReserve(Num());
|
||||||
@ -113,7 +117,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Move constructor. After the move, 'InValue' is guaranteed to be empty. */
|
/** Move constructor. After the move, 'InValue' is guaranteed to be empty. */
|
||||||
TArray(TArray&& InValue) requires (CMoveConstructible<FElementType>)
|
TArray(TArray&& InValue) requires (CMoveConstructible<T>)
|
||||||
{
|
{
|
||||||
Impl.ArrayNum = InValue.Num();
|
Impl.ArrayNum = InValue.Num();
|
||||||
|
|
||||||
@ -138,7 +142,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Constructs the container with the contents of the initializer list. */
|
/** Constructs the container with the contents of the initializer list. */
|
||||||
FORCEINLINE TArray(initializer_list<FElementType> IL) requires (CCopyConstructible<FElementType>) : TArray(Range::Begin(IL), Range::End(IL)) { }
|
FORCEINLINE TArray(initializer_list<FElementType> IL) requires (CCopyConstructible<T>) : TArray(Range::Begin(IL), Range::End(IL)) { }
|
||||||
|
|
||||||
/** Destructs the array. The destructors of the elements are called and the used storage is deallocated. */
|
/** Destructs the array. The destructors of the elements are called and the used storage is deallocated. */
|
||||||
~TArray()
|
~TArray()
|
||||||
@ -148,7 +152,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Copy assignment operator. Replaces the contents with a copy of the contents of 'InValue'. */
|
/** Copy assignment operator. Replaces the contents with a copy of the contents of 'InValue'. */
|
||||||
TArray& operator=(const TArray& InValue) requires (CCopyable<FElementType>)
|
TArray& operator=(const TArray& InValue) requires (CCopyable<T>)
|
||||||
{
|
{
|
||||||
if (&InValue == this) UNLIKELY return *this;
|
if (&InValue == this) UNLIKELY return *this;
|
||||||
|
|
||||||
@ -189,7 +193,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Move assignment operator. After the move, 'InValue' is guaranteed to be empty. */
|
/** Move assignment operator. After the move, 'InValue' is guaranteed to be empty. */
|
||||||
TArray& operator=(TArray&& InValue) requires (CMovable<FElementType>)
|
TArray& operator=(TArray&& InValue) requires (CMovable<T>)
|
||||||
{
|
{
|
||||||
if (&InValue == this) UNLIKELY return *this;
|
if (&InValue == this) UNLIKELY return *this;
|
||||||
|
|
||||||
@ -250,7 +254,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Replaces the contents with those identified by initializer list. */
|
/** Replaces the contents with those identified by initializer list. */
|
||||||
TArray& operator=(initializer_list<FElementType> IL) requires (CCopyable<FElementType>)
|
TArray& operator=(initializer_list<FElementType> IL) requires (CCopyable<T>)
|
||||||
{
|
{
|
||||||
size_t NumToAllocate = Range::Num(IL);
|
size_t NumToAllocate = Range::Num(IL);
|
||||||
|
|
||||||
@ -289,7 +293,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Compares the contents of two arrays. */
|
/** Compares the contents of two arrays. */
|
||||||
NODISCARD friend bool operator==(const TArray& LHS, const TArray& RHS) requires (CWeaklyEqualityComparable<FElementType>)
|
NODISCARD friend bool operator==(const TArray& LHS, const TArray& RHS) requires (CWeaklyEqualityComparable<T>)
|
||||||
{
|
{
|
||||||
if (LHS.Num() != RHS.Num()) return false;
|
if (LHS.Num() != RHS.Num()) return false;
|
||||||
|
|
||||||
@ -302,7 +306,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Compares the contents of 'LHS' and 'RHS' lexicographically. */
|
/** Compares the contents of 'LHS' and 'RHS' lexicographically. */
|
||||||
NODISCARD friend auto operator<=>(const TArray& LHS, const TArray& RHS) requires (CSynthThreeWayComparable<FElementType>)
|
NODISCARD friend auto operator<=>(const TArray& LHS, const TArray& RHS) requires (CSynthThreeWayComparable<T>)
|
||||||
{
|
{
|
||||||
const size_t NumToCompare = LHS.Num() < RHS.Num() ? LHS.Num() : RHS.Num();
|
const size_t NumToCompare = LHS.Num() < RHS.Num() ? LHS.Num() : RHS.Num();
|
||||||
|
|
||||||
@ -315,7 +319,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Inserts 'InValue' before 'Iter' in the container. */
|
/** Inserts 'InValue' before 'Iter' in the container. */
|
||||||
FIterator Insert(FConstIterator Iter, const FElementType& InValue) requires (CCopyable<FElementType>)
|
FIterator Insert(FConstIterator Iter, const FElementType& InValue) requires (CCopyable<T>)
|
||||||
{
|
{
|
||||||
checkf(IsValidIterator(Iter), TEXT("Read access violation. Please check IsValidIterator()."));
|
checkf(IsValidIterator(Iter), TEXT("Read access violation. Please check IsValidIterator()."));
|
||||||
|
|
||||||
@ -363,7 +367,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Inserts 'InValue' before 'Iter' in the container. */
|
/** Inserts 'InValue' before 'Iter' in the container. */
|
||||||
FIterator Insert(FConstIterator Iter, FElementType&& InValue) requires (CMovable<FElementType>)
|
FIterator Insert(FConstIterator Iter, FElementType&& InValue) requires (CMovable<T>)
|
||||||
{
|
{
|
||||||
checkf(IsValidIterator(Iter), TEXT("Read access violation. Please check IsValidIterator()."));
|
checkf(IsValidIterator(Iter), TEXT("Read access violation. Please check IsValidIterator()."));
|
||||||
|
|
||||||
@ -411,7 +415,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Inserts 'Count' copies of the 'InValue' before 'Iter' in the container. */
|
/** Inserts 'Count' copies of the 'InValue' before 'Iter' in the container. */
|
||||||
FIterator Insert(FConstIterator Iter, size_t Count, const FElementType& InValue) requires (CCopyable<FElementType>)
|
FIterator Insert(FConstIterator Iter, size_t Count, const FElementType& InValue) requires (CCopyable<T>)
|
||||||
{
|
{
|
||||||
checkf(IsValidIterator(Iter), TEXT("Read access violation. Please check IsValidIterator()."));
|
checkf(IsValidIterator(Iter), TEXT("Read access violation. Please check IsValidIterator()."));
|
||||||
|
|
||||||
@ -419,8 +423,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Inserts elements from range ['First', 'Last') before 'Iter'. */
|
/** Inserts elements from range ['First', 'Last') before 'Iter'. */
|
||||||
template <CInputIterator I, CSentinelFor<I> S> requires (CConstructibleFrom<FElementType, TIteratorReference<I>>
|
template <CInputIterator I, CSentinelFor<I> S> requires (CConstructibleFrom<T, TIteratorReference<I>> && CAssignableFrom<T&, TIteratorReference<I>> && CMovable<T>)
|
||||||
&& CAssignableFrom<FElementType&, TIteratorReference<I>> && CMovable<FElementType>)
|
|
||||||
FIterator Insert(FConstIterator Iter, I First, S Last)
|
FIterator Insert(FConstIterator Iter, I First, S Last)
|
||||||
{
|
{
|
||||||
checkf(IsValidIterator(Iter), TEXT("Read access violation. Please check IsValidIterator()."));
|
checkf(IsValidIterator(Iter), TEXT("Read access violation. Please check IsValidIterator()."));
|
||||||
@ -540,21 +543,20 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Inserts elements from range before 'Iter'. */
|
/** Inserts elements from range before 'Iter'. */
|
||||||
template <CInputRange R> requires (CConstructibleFrom<FElementType, TRangeReference<R>>
|
template <CInputRange R> requires (CConstructibleFrom<T, TRangeReference<R>> && CAssignableFrom<T&, TRangeReference<R>> && CMovable<T>)
|
||||||
&& CAssignableFrom<FElementType&, TRangeReference<R>> && CMovable<FElementType>)
|
|
||||||
FORCEINLINE FIterator Insert(FConstIterator Iter, R&& Range)
|
FORCEINLINE FIterator Insert(FConstIterator Iter, R&& Range)
|
||||||
{
|
{
|
||||||
return Insert(Iter, Range::Begin(Range), Range::End(Range));
|
return Insert(Iter, Range::Begin(Range), Range::End(Range));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Inserts elements from initializer list before 'Iter' in the container. */
|
/** Inserts elements from initializer list before 'Iter' in the container. */
|
||||||
FORCEINLINE FIterator Insert(FConstIterator Iter, initializer_list<FElementType> IL) requires (CCopyable<FElementType>)
|
FORCEINLINE FIterator Insert(FConstIterator Iter, initializer_list<FElementType> IL) requires (CCopyable<T>)
|
||||||
{
|
{
|
||||||
return Insert(Iter, Range::Begin(IL), Range::End(IL));
|
return Insert(Iter, Range::Begin(IL), Range::End(IL));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Inserts a new element into the container directly before 'Iter'. */
|
/** Inserts a new element into the container directly before 'Iter'. */
|
||||||
template <typename... Ts> requires (CConstructibleFrom<FElementType, Ts...> && CMovable<FElementType>)
|
template <typename... Ts> requires (CConstructibleFrom<T, Ts...> && CMovable<T>)
|
||||||
FIterator Emplace(FConstIterator Iter, Ts&&... Args)
|
FIterator Emplace(FConstIterator Iter, Ts&&... Args)
|
||||||
{
|
{
|
||||||
checkf(IsValidIterator(Iter), TEXT("Read access violation. Please check IsValidIterator()."));
|
checkf(IsValidIterator(Iter), TEXT("Read access violation. Please check IsValidIterator()."));
|
||||||
@ -603,7 +605,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Removes the element at 'Iter' in the container. Without changing the order of elements. */
|
/** Removes the element at 'Iter' in the container. Without changing the order of elements. */
|
||||||
FORCEINLINE FIterator StableErase(FConstIterator Iter, bool bAllowShrinking = true) requires (CMovable<FElementType>)
|
FORCEINLINE FIterator StableErase(FConstIterator Iter, bool bAllowShrinking = true) requires (CMovable<T>)
|
||||||
{
|
{
|
||||||
checkf(IsValidIterator(Iter) && Iter != End(), TEXT("Read access violation. Please check IsValidIterator()."));
|
checkf(IsValidIterator(Iter) && Iter != End(), TEXT("Read access violation. Please check IsValidIterator()."));
|
||||||
|
|
||||||
@ -611,7 +613,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Removes the elements in the range ['First', 'Last') in the container. Without changing the order of elements. */
|
/** Removes the elements in the range ['First', 'Last') in the container. Without changing the order of elements. */
|
||||||
FIterator StableErase(FConstIterator First, FConstIterator Last, bool bAllowShrinking = true) requires (CMovable<FElementType>)
|
FIterator StableErase(FConstIterator First, FConstIterator Last, bool bAllowShrinking = true) requires (CMovable<T>)
|
||||||
{
|
{
|
||||||
checkf(IsValidIterator(First) && IsValidIterator(Last) && First <= Last, TEXT("Read access violation. Please check IsValidIterator()."));
|
checkf(IsValidIterator(First) && IsValidIterator(Last) && First <= Last, TEXT("Read access violation. Please check IsValidIterator()."));
|
||||||
|
|
||||||
@ -653,7 +655,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Removes the element at 'Iter' in the container. But it may change the order of elements. */
|
/** Removes the element at 'Iter' in the container. But it may change the order of elements. */
|
||||||
FORCEINLINE FIterator Erase(FConstIterator Iter, bool bAllowShrinking = true) requires (CMovable<FElementType>)
|
FORCEINLINE FIterator Erase(FConstIterator Iter, bool bAllowShrinking = true) requires (CMovable<T>)
|
||||||
{
|
{
|
||||||
checkf(IsValidIterator(Iter) && Iter != End(), TEXT("Read access violation. Please check IsValidIterator()."));
|
checkf(IsValidIterator(Iter) && Iter != End(), TEXT("Read access violation. Please check IsValidIterator()."));
|
||||||
|
|
||||||
@ -661,7 +663,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Removes the elements in the range ['First', 'Last') in the container. But it may change the order of elements. */
|
/** Removes the elements in the range ['First', 'Last') in the container. But it may change the order of elements. */
|
||||||
FIterator Erase(FConstIterator First, FConstIterator Last, bool bAllowShrinking = true) requires (CMovable<FElementType>)
|
FIterator Erase(FConstIterator First, FConstIterator Last, bool bAllowShrinking = true) requires (CMovable<T>)
|
||||||
{
|
{
|
||||||
checkf(IsValidIterator(First) && IsValidIterator(Last) && First <= Last, TEXT("Read access violation. Please check IsValidIterator()."));
|
checkf(IsValidIterator(First) && IsValidIterator(Last) && First <= Last, TEXT("Read access violation. Please check IsValidIterator()."));
|
||||||
|
|
||||||
@ -705,19 +707,19 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Appends the given element value to the end of the container. */
|
/** Appends the given element value to the end of the container. */
|
||||||
FORCEINLINE void PushBack(const FElementType& InValue) requires (CCopyable<FElementType>)
|
FORCEINLINE void PushBack(const FElementType& InValue) requires (CCopyable<T>)
|
||||||
{
|
{
|
||||||
EmplaceBack(InValue);
|
EmplaceBack(InValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Appends the given element value to the end of the container. */
|
/** Appends the given element value to the end of the container. */
|
||||||
FORCEINLINE void PushBack(FElementType&& InValue) requires (CMovable<FElementType>)
|
FORCEINLINE void PushBack(FElementType&& InValue) requires (CMovable<T>)
|
||||||
{
|
{
|
||||||
EmplaceBack(MoveTemp(InValue));
|
EmplaceBack(MoveTemp(InValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Appends a new element to the end of the container. */
|
/** Appends a new element to the end of the container. */
|
||||||
template <typename... Ts> requires (CConstructibleFrom<FElementType, Ts...> && CMovable<FElementType>)
|
template <typename... Ts> requires (CConstructibleFrom<T, Ts...> && CMovable<T>)
|
||||||
FElementType& EmplaceBack(Ts&&... Args)
|
FElementType& EmplaceBack(Ts&&... Args)
|
||||||
{
|
{
|
||||||
const size_t NumToAllocate = Num() + 1 > Max() ? Impl->CalculateSlackGrow(Num() + 1, Max()) : Max();
|
const size_t NumToAllocate = Num() + 1 > Max() ? Impl->CalculateSlackGrow(Num() + 1, Max()) : Max();
|
||||||
@ -750,13 +752,13 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Removes the last element of the container. The array cannot be empty. */
|
/** Removes the last element of the container. The array cannot be empty. */
|
||||||
FORCEINLINE void PopBack(bool bAllowShrinking = true) requires (CMovable<FElementType>)
|
FORCEINLINE void PopBack(bool bAllowShrinking = true) requires (CMovable<T>)
|
||||||
{
|
{
|
||||||
Erase(End() - 1, bAllowShrinking);
|
Erase(End() - 1, bAllowShrinking);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Resizes the container to contain 'Count' elements. Additional default elements are appended. */
|
/** Resizes the container to contain 'Count' elements. Additional default elements are appended. */
|
||||||
void SetNum(size_t Count, bool bAllowShrinking = true) requires (CDefaultConstructible<FElementType> && CMovable<FElementType>)
|
void SetNum(size_t Count, bool bAllowShrinking = true) requires (CDefaultConstructible<T> && CMovable<T>)
|
||||||
{
|
{
|
||||||
size_t NumToAllocate = Count;
|
size_t NumToAllocate = Count;
|
||||||
|
|
||||||
@ -802,7 +804,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Resizes the container to contain 'Count' elements. Additional copies of 'InValue' are appended. */
|
/** Resizes the container to contain 'Count' elements. Additional copies of 'InValue' are appended. */
|
||||||
void SetNum(size_t Count, const FElementType& InValue, bool bAllowShrinking = true) requires (CCopyConstructible<FElementType> && CMovable<FElementType>)
|
void SetNum(size_t Count, const FElementType& InValue, bool bAllowShrinking = true) requires (CCopyConstructible<T> && CMovable<T>)
|
||||||
{
|
{
|
||||||
size_t NumToAllocate = Count;
|
size_t NumToAllocate = Count;
|
||||||
|
|
||||||
@ -855,7 +857,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Increase the max capacity of the array to a value that's greater or equal to 'Count'. */
|
/** Increase the max capacity of the array to a value that's greater or equal to 'Count'. */
|
||||||
void Reserve(size_t Count) requires (CMovable<FElementType>)
|
void Reserve(size_t Count) requires (CMovable<T>)
|
||||||
{
|
{
|
||||||
if (Count <= Max()) return;
|
if (Count <= Max()) return;
|
||||||
|
|
||||||
@ -953,7 +955,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Overloads the GetTypeHash algorithm for TArray. */
|
/** Overloads the GetTypeHash algorithm for TArray. */
|
||||||
NODISCARD friend FORCEINLINE size_t GetTypeHash(const TArray& A) requires (CHashable<FElementType>)
|
NODISCARD friend FORCEINLINE size_t GetTypeHash(const TArray& A) requires (CHashable<T>)
|
||||||
{
|
{
|
||||||
size_t Result = 0;
|
size_t Result = 0;
|
||||||
|
|
||||||
@ -966,7 +968,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Overloads the Swap algorithm for TArray. */
|
/** Overloads the Swap algorithm for TArray. */
|
||||||
friend void Swap(TArray& A, TArray& B) requires (CMovable<FElementType>)
|
friend void Swap(TArray& A, TArray& B) requires (CMovable<T>)
|
||||||
{
|
{
|
||||||
const bool bIsTransferable =
|
const bool bIsTransferable =
|
||||||
A.Impl->IsTransferable(A.Impl.Pointer) &&
|
A.Impl->IsTransferable(A.Impl.Pointer) &&
|
||||||
@ -1005,7 +1007,7 @@ private:
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
using FElementType = TRemoveCV<T>;
|
using FElementType = T;
|
||||||
|
|
||||||
FORCEINLINE TIteratorImpl() = default;
|
FORCEINLINE TIteratorImpl() = default;
|
||||||
|
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CoreTypes.h"
|
#include "CoreTypes.h"
|
||||||
#include "Range/Range.h"
|
#include "TypeTraits/TypeTraits.h"
|
||||||
#include "Memory/Address.h"
|
|
||||||
#include "Memory/Allocator.h"
|
|
||||||
#include "Containers/Array.h"
|
|
||||||
#include "Iterator/Iterator.h"
|
|
||||||
#include "Templates/Utility.h"
|
#include "Templates/Utility.h"
|
||||||
#include "Templates/TypeHash.h"
|
#include "Templates/TypeHash.h"
|
||||||
|
#include "Iterator/Utility.h"
|
||||||
|
#include "Iterator/BasicIterator.h"
|
||||||
|
#include "Iterator/Sentinel.h"
|
||||||
|
#include "Iterator/ReverseIterator.h"
|
||||||
|
#include "Containers/Array.h"
|
||||||
#include "Containers/StaticArray.h"
|
#include "Containers/StaticArray.h"
|
||||||
#include "TypeTraits/TypeTraits.h"
|
|
||||||
#include "Miscellaneous/Compare.h"
|
#include "Miscellaneous/Compare.h"
|
||||||
#include "Miscellaneous/AssertionMacros.h"
|
#include "Miscellaneous/AssertionMacros.h"
|
||||||
|
|
||||||
|
@ -1,16 +1,17 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CoreTypes.h"
|
#include "CoreTypes.h"
|
||||||
#include "Range/Range.h"
|
#include "TypeTraits/TypeTraits.h"
|
||||||
#include "Memory/Memory.h"
|
|
||||||
#include "Memory/Allocator.h"
|
|
||||||
#include "Iterator/Iterator.h"
|
|
||||||
#include "Templates/Utility.h"
|
#include "Templates/Utility.h"
|
||||||
#include "Templates/TypeHash.h"
|
#include "Templates/TypeHash.h"
|
||||||
#include "Templates/Noncopyable.h"
|
#include "Templates/Noncopyable.h"
|
||||||
#include "TypeTraits/TypeTraits.h"
|
#include "Memory/Allocator.h"
|
||||||
|
#include "Iterator/Utility.h"
|
||||||
|
#include "Iterator/BasicIterator.h"
|
||||||
|
#include "Iterator/Sentinel.h"
|
||||||
|
#include "Iterator/ReverseIterator.h"
|
||||||
|
#include "Range/Utility.h"
|
||||||
#include "Miscellaneous/Compare.h"
|
#include "Miscellaneous/Compare.h"
|
||||||
#include "Memory/MemoryOperator.h"
|
|
||||||
#include "Miscellaneous/AssertionMacros.h"
|
#include "Miscellaneous/AssertionMacros.h"
|
||||||
|
|
||||||
NAMESPACE_REDCRAFT_BEGIN
|
NAMESPACE_REDCRAFT_BEGIN
|
||||||
@ -20,7 +21,7 @@ NAMESPACE_MODULE_BEGIN(Utility)
|
|||||||
template <CUnsignedIntegral InBlockType> requires (!CSameAs<InBlockType, bool>)
|
template <CUnsignedIntegral InBlockType> requires (!CSameAs<InBlockType, bool>)
|
||||||
using TDefaultBitsetAllocator = TInlineAllocator<(40 - 3 * sizeof(size_t)) / sizeof(InBlockType)>;
|
using TDefaultBitsetAllocator = TInlineAllocator<(40 - 3 * sizeof(size_t)) / sizeof(InBlockType)>;
|
||||||
|
|
||||||
template <CUnsignedIntegral InBlockType, CAllocator<InBlockType> Allocator = TDefaultBitsetAllocator<InBlockType>> requires (!CSameAs<InBlockType, bool>)
|
template <CUnsignedIntegral InBlockType, CAllocator<InBlockType> Allocator = TDefaultBitsetAllocator<InBlockType>> requires (CAllocatableObject<InBlockType> && !CSameAs<InBlockType, bool>)
|
||||||
class TBitset
|
class TBitset
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
@ -1,14 +1,18 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CoreTypes.h"
|
#include "CoreTypes.h"
|
||||||
#include "Range/Range.h"
|
#include "TypeTraits/TypeTraits.h"
|
||||||
#include "Memory/Allocator.h"
|
|
||||||
#include "Iterator/Iterator.h"
|
|
||||||
#include "Templates/Utility.h"
|
#include "Templates/Utility.h"
|
||||||
#include "Templates/TypeHash.h"
|
#include "Templates/TypeHash.h"
|
||||||
#include "TypeTraits/TypeTraits.h"
|
#include "Memory/Allocator.h"
|
||||||
#include "Miscellaneous/Compare.h"
|
|
||||||
#include "Memory/MemoryOperator.h"
|
#include "Memory/MemoryOperator.h"
|
||||||
|
#include "Iterator/Utility.h"
|
||||||
|
#include "Iterator/BasicIterator.h"
|
||||||
|
#include "Iterator/Sentinel.h"
|
||||||
|
#include "Iterator/ReverseIterator.h"
|
||||||
|
#include "Range/Utility.h"
|
||||||
|
#include "Range/Factory.h"
|
||||||
|
#include "Miscellaneous/Compare.h"
|
||||||
#include "Miscellaneous/AssertionMacros.h"
|
#include "Miscellaneous/AssertionMacros.h"
|
||||||
|
|
||||||
NAMESPACE_REDCRAFT_BEGIN
|
NAMESPACE_REDCRAFT_BEGIN
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CoreTypes.h"
|
#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 "TypeTraits/TypeTraits.h"
|
||||||
|
#include "Templates/Utility.h"
|
||||||
|
#include "Templates/Meta.h"
|
||||||
|
#include "Templates/TypeHash.h"
|
||||||
|
#include "Iterator/Utility.h"
|
||||||
|
#include "Iterator/BasicIterator.h"
|
||||||
|
#include "Iterator/ReverseIterator.h"
|
||||||
#include "Miscellaneous/Compare.h"
|
#include "Miscellaneous/Compare.h"
|
||||||
#include "Miscellaneous/AssertionMacros.h"
|
#include "Miscellaneous/AssertionMacros.h"
|
||||||
|
|
||||||
@ -15,7 +16,7 @@ NAMESPACE_MODULE_BEGIN(Redcraft)
|
|||||||
NAMESPACE_MODULE_BEGIN(Utility)
|
NAMESPACE_MODULE_BEGIN(Utility)
|
||||||
|
|
||||||
/** TStaticArray is a container that encapsulates fixed size arrays. */
|
/** TStaticArray is a container that encapsulates fixed size arrays. */
|
||||||
template <CObject T, size_t N>
|
template <CObject T, size_t N> requires (!CConst<T> && !CVolatile<T>)
|
||||||
struct TStaticArray
|
struct TStaticArray
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CoreTypes.h"
|
#include "CoreTypes.h"
|
||||||
#include "Range/Range.h"
|
#include "TypeTraits/TypeTraits.h"
|
||||||
#include "Iterator/Iterator.h"
|
|
||||||
#include "Templates/Utility.h"
|
#include "Templates/Utility.h"
|
||||||
#include "Templates/TypeHash.h"
|
#include "Templates/TypeHash.h"
|
||||||
#include "Templates/Noncopyable.h"
|
#include "Templates/Noncopyable.h"
|
||||||
#include "TypeTraits/TypeTraits.h"
|
#include "Iterator/Utility.h"
|
||||||
|
#include "Iterator/BasicIterator.h"
|
||||||
|
#include "Iterator/ReverseIterator.h"
|
||||||
#include "Miscellaneous/Compare.h"
|
#include "Miscellaneous/Compare.h"
|
||||||
#include "Memory/MemoryOperator.h"
|
|
||||||
#include "Miscellaneous/AssertionMacros.h"
|
#include "Miscellaneous/AssertionMacros.h"
|
||||||
|
|
||||||
NAMESPACE_REDCRAFT_BEGIN
|
NAMESPACE_REDCRAFT_BEGIN
|
||||||
@ -25,9 +25,7 @@ using TDefaultBitsetBlockType =
|
|||||||
|
|
||||||
NAMESPACE_PRIVATE_END
|
NAMESPACE_PRIVATE_END
|
||||||
|
|
||||||
#if 1
|
template <size_t N, CUnsignedIntegral InBlockType = NAMESPACE_PRIVATE::TDefaultBitsetBlockType<N>> requires (!CConst<InBlockType> && !CVolatile<InBlockType> && !CSameAs<InBlockType, bool>)
|
||||||
|
|
||||||
template <size_t N, CUnsignedIntegral InBlockType = NAMESPACE_PRIVATE::TDefaultBitsetBlockType<N>> requires (!CSameAs<InBlockType, bool>)
|
|
||||||
class TStaticBitset
|
class TStaticBitset
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
@ -617,8 +615,6 @@ private:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
NAMESPACE_MODULE_END(Utility)
|
NAMESPACE_MODULE_END(Utility)
|
||||||
NAMESPACE_MODULE_END(Redcraft)
|
NAMESPACE_MODULE_END(Redcraft)
|
||||||
NAMESPACE_REDCRAFT_END
|
NAMESPACE_REDCRAFT_END
|
||||||
|
250
Redcraft.Utility/Source/Public/Iterator/BasicIterator.h
Normal file
250
Redcraft.Utility/Source/Public/Iterator/BasicIterator.h
Normal file
@ -0,0 +1,250 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreTypes.h"
|
||||||
|
#include "Memory/Address.h"
|
||||||
|
#include "Iterator/Utility.h"
|
||||||
|
#include "Iterator/Sentinel.h"
|
||||||
|
#include "Miscellaneous/Compare.h"
|
||||||
|
#include "TypeTraits/TypeTraits.h"
|
||||||
|
|
||||||
|
NAMESPACE_REDCRAFT_BEGIN
|
||||||
|
NAMESPACE_MODULE_BEGIN(Redcraft)
|
||||||
|
NAMESPACE_MODULE_BEGIN(Utility)
|
||||||
|
|
||||||
|
#if PLATFORM_COMPILER_GCC
|
||||||
|
# pragma GCC diagnostic push
|
||||||
|
# pragma GCC diagnostic ignored "-Wnon-template-friend"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/** A concept specifies a type is an input iterator. It is input iterator, incrementable, and sentinel for itself. */
|
||||||
|
template <typename I>
|
||||||
|
concept CForwardIterator = CInputIterator<I> && CIncrementable<I> && CSentinelFor<I, I>;
|
||||||
|
|
||||||
|
/** This is an example of a forward iterator, indicate the traits that define a forward iterator. */
|
||||||
|
template <CReferenceable T>
|
||||||
|
struct IForwardIterator /* : IInputIterator<T>, IIncrementable, ISentinelFor<IForwardIterator> */
|
||||||
|
{
|
||||||
|
// ~Begin CInputIterator.
|
||||||
|
|
||||||
|
using FElementType = TRemoveCVRef<T>;
|
||||||
|
|
||||||
|
// ~End CInputIterator.
|
||||||
|
|
||||||
|
// ~Begin CIncrementable and CSentinelFor<IForwardIterator>.
|
||||||
|
|
||||||
|
IForwardIterator();
|
||||||
|
IForwardIterator(const IForwardIterator&);
|
||||||
|
IForwardIterator(IForwardIterator&&); // Also satisfies IInputIterator.
|
||||||
|
IForwardIterator* operator=(const IForwardIterator&);
|
||||||
|
IForwardIterator* operator=(IForwardIterator&&); // Also satisfies IInputIterator.
|
||||||
|
|
||||||
|
friend bool operator==(const IForwardIterator&, const IForwardIterator&);
|
||||||
|
|
||||||
|
// ~End CIncrementable and CSentinelFor<IForwardIterator>.
|
||||||
|
|
||||||
|
// ~Begin CInputIterator.
|
||||||
|
|
||||||
|
T operator*() const; // Optional satisfies CIndirectlyWritable.
|
||||||
|
|
||||||
|
IForwardIterator& operator++(); // Also satisfies CIncrementable.
|
||||||
|
|
||||||
|
IForwardIterator operator++(int); // Also satisfies CIncrementable.
|
||||||
|
|
||||||
|
// ~End CInputIterator.
|
||||||
|
};
|
||||||
|
|
||||||
|
// Use IForwardIterator<int> represents a forward iterator.
|
||||||
|
static_assert(CForwardIterator<IForwardIterator<int&>>);
|
||||||
|
static_assert( COutputIterator<IForwardIterator<int&>, int>);
|
||||||
|
|
||||||
|
/** A concept specifies a type is a bidirectional iterator. Add the decrement operator to the forward iterator. */
|
||||||
|
template <typename I>
|
||||||
|
concept CBidirectionalIterator = CForwardIterator<I>
|
||||||
|
&& requires(I Iter) {
|
||||||
|
{ --Iter } -> CSameAs<I&>;
|
||||||
|
{ Iter-- } -> CSameAs<I >;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is an example of a bidirectional iterator, indicate the traits that define a bidirectional iterator.
|
||||||
|
* Regardless of the order in which the increment and decrement operators are applied,
|
||||||
|
* the result is always the same if both operations are performed the same number of times.
|
||||||
|
*/
|
||||||
|
template <CReferenceable T>
|
||||||
|
struct IBidirectionalIterator /* : IForwardIterator<T> */
|
||||||
|
{
|
||||||
|
// ~Begin CForwardIterator.
|
||||||
|
|
||||||
|
using FElementType = TRemoveCVRef<T>;
|
||||||
|
|
||||||
|
IBidirectionalIterator();
|
||||||
|
IBidirectionalIterator(const IBidirectionalIterator&);
|
||||||
|
IBidirectionalIterator(IBidirectionalIterator&&);
|
||||||
|
IBidirectionalIterator* operator=(const IBidirectionalIterator&);
|
||||||
|
IBidirectionalIterator* operator=(IBidirectionalIterator&&);
|
||||||
|
|
||||||
|
friend bool operator==(const IBidirectionalIterator&, const IBidirectionalIterator&);
|
||||||
|
|
||||||
|
T operator*() const;
|
||||||
|
|
||||||
|
// ~End CForwardIterator.
|
||||||
|
|
||||||
|
IBidirectionalIterator& operator++(); // Also satisfies CForwardIterator.
|
||||||
|
IBidirectionalIterator& operator--();
|
||||||
|
|
||||||
|
IBidirectionalIterator operator++(int); // Also satisfies CForwardIterator.
|
||||||
|
IBidirectionalIterator operator--(int);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Use IBidirectionalIterator<int> represents a bidirectional iterator.
|
||||||
|
static_assert(CBidirectionalIterator<IBidirectionalIterator<int&>>);
|
||||||
|
static_assert( COutputIterator<IBidirectionalIterator<int&>, int>);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A concept specifies a type is a random access iterator.
|
||||||
|
* Add the three-way comparison, addition, subtraction and subscript operators to the bidirectional iterator.
|
||||||
|
*/
|
||||||
|
template <typename I>
|
||||||
|
concept CRandomAccessIterator = CBidirectionalIterator<I> && CTotallyOrdered<I> && CSizedSentinelFor<I, I>
|
||||||
|
&& requires(I Iter, const I Jter, const ptrdiff N) {
|
||||||
|
{ Iter += N } -> CSameAs<I&>;
|
||||||
|
{ Jter + N } -> CSameAs<I >;
|
||||||
|
{ N + Jter } -> CSameAs<I >;
|
||||||
|
{ Iter -= N } -> CSameAs<I&>;
|
||||||
|
{ Jter - N } -> CSameAs<I >;
|
||||||
|
{ Jter[N] } -> CSameAs<TIteratorReference<I>>;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** This is an example of a random access iterator, indicate the traits that define a random access iterator. */
|
||||||
|
template <CReferenceable T>
|
||||||
|
struct IRandomAccessIterator /* : IBidirectionalIterator<T>, ISizedSentinelFor<IRandomAccessIterator> */
|
||||||
|
{
|
||||||
|
// ~Begin CBidirectionalIterator.
|
||||||
|
|
||||||
|
using FElementType = TRemoveCVRef<T>;
|
||||||
|
|
||||||
|
// ~End CBidirectionalIterator.
|
||||||
|
|
||||||
|
// ~Begin CBidirectionalIterator and CSizedSentinelFor<IRandomAccessIterator>.
|
||||||
|
|
||||||
|
IRandomAccessIterator();
|
||||||
|
IRandomAccessIterator(const IRandomAccessIterator&);
|
||||||
|
IRandomAccessIterator(IRandomAccessIterator&&);
|
||||||
|
IRandomAccessIterator* operator=(const IRandomAccessIterator&);
|
||||||
|
IRandomAccessIterator* operator=(IRandomAccessIterator&&);
|
||||||
|
|
||||||
|
friend bool operator==(const IRandomAccessIterator&, const IRandomAccessIterator&);
|
||||||
|
|
||||||
|
// ~End CBidirectionalIterator and CSizedSentinelFor<IRandomAccessIterator>.
|
||||||
|
|
||||||
|
friend strong_ordering operator<=>(const IRandomAccessIterator&, const IRandomAccessIterator&);
|
||||||
|
|
||||||
|
T operator*() const; // Also satisfies CBidirectionalIterator.
|
||||||
|
|
||||||
|
T operator[](ptrdiff) const;
|
||||||
|
|
||||||
|
// ~Begin CBidirectionalIterator.
|
||||||
|
|
||||||
|
IRandomAccessIterator& operator++();
|
||||||
|
IRandomAccessIterator& operator--();
|
||||||
|
|
||||||
|
IRandomAccessIterator operator++(int);
|
||||||
|
IRandomAccessIterator operator--(int);
|
||||||
|
|
||||||
|
// ~End CBidirectionalIterator.
|
||||||
|
|
||||||
|
IRandomAccessIterator& operator+=(ptrdiff);
|
||||||
|
IRandomAccessIterator& operator-=(ptrdiff);
|
||||||
|
|
||||||
|
IRandomAccessIterator operator+(ptrdiff) const;
|
||||||
|
IRandomAccessIterator operator-(ptrdiff) const;
|
||||||
|
|
||||||
|
friend IRandomAccessIterator operator+(ptrdiff, const IRandomAccessIterator&);
|
||||||
|
|
||||||
|
friend ptrdiff operator-(const IRandomAccessIterator&, const IRandomAccessIterator&); // Also satisfies CSizedSentinelFor<IRandomAccessIterator>.
|
||||||
|
};
|
||||||
|
|
||||||
|
// Use IRandomAccessIterator<int> represents a random access iterator
|
||||||
|
static_assert(CRandomAccessIterator<IRandomAccessIterator<int&>>);
|
||||||
|
static_assert( COutputIterator<IRandomAccessIterator<int&>, int>);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A concept specifies a type is a contiguous iterator.
|
||||||
|
* Add the operator-> to the random access iterator and requires the operator* returns a true reference type.
|
||||||
|
*/
|
||||||
|
template <typename I>
|
||||||
|
concept CContiguousIterator = CRandomAccessIterator<I> && CLValueReference<TIteratorReference<I>>
|
||||||
|
&& CSameAs<TIteratorElement<I>, TRemoveCVRef<TIteratorReference<I>>>
|
||||||
|
&& CSameAs<TIteratorPointer<I>, TAddPointer<TIteratorReference<I>>>
|
||||||
|
&& requires(I& Iter)
|
||||||
|
{
|
||||||
|
{ ToAddress(Iter) } -> CSameAs<TAddPointer<TIteratorReference<I>>>;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** This is an example of a contiguous iterator, indicate the traits that define a contiguous iterator. */
|
||||||
|
template <CLValueReference T>
|
||||||
|
struct IContiguousIterator /* : IRandomAccessIterator<T> */
|
||||||
|
{
|
||||||
|
// ~Begin CRandomAccessIterator.
|
||||||
|
|
||||||
|
using FElementType = TRemoveCVRef<T>;
|
||||||
|
|
||||||
|
IContiguousIterator();
|
||||||
|
IContiguousIterator(const IContiguousIterator&);
|
||||||
|
IContiguousIterator(IContiguousIterator&&);
|
||||||
|
IContiguousIterator* operator=(const IContiguousIterator&);
|
||||||
|
IContiguousIterator* operator=(IContiguousIterator&&);
|
||||||
|
|
||||||
|
friend bool operator==(const IContiguousIterator&, const IContiguousIterator&);
|
||||||
|
|
||||||
|
friend strong_ordering operator<=>(const IContiguousIterator&, const IContiguousIterator&);
|
||||||
|
|
||||||
|
// ~End CRandomAccessIterator.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dereference operator. See IForwardIterator.
|
||||||
|
* Specify, the return type must be a true reference type and refer to an element of a contiguous sequence, not a proxy class.
|
||||||
|
* Also satisfies CRandomAccessIterator.
|
||||||
|
*/
|
||||||
|
T operator*() const;
|
||||||
|
|
||||||
|
/** Indirection operator. Return the address of the element that the iterator is pointing to. */
|
||||||
|
TAddPointer<T> operator->() const;
|
||||||
|
|
||||||
|
// ~Begin CRandomAccessIterator.
|
||||||
|
|
||||||
|
T operator[](ptrdiff) const;
|
||||||
|
|
||||||
|
IContiguousIterator& operator++();
|
||||||
|
IContiguousIterator& operator--();
|
||||||
|
|
||||||
|
IContiguousIterator operator++(int);
|
||||||
|
IContiguousIterator operator--(int);
|
||||||
|
|
||||||
|
IContiguousIterator& operator+=(ptrdiff);
|
||||||
|
IContiguousIterator& operator-=(ptrdiff);
|
||||||
|
|
||||||
|
IContiguousIterator operator+(ptrdiff) const;
|
||||||
|
IContiguousIterator operator-(ptrdiff) const;
|
||||||
|
|
||||||
|
friend IContiguousIterator operator+(ptrdiff, const IContiguousIterator&);
|
||||||
|
|
||||||
|
friend ptrdiff operator-(const IContiguousIterator&, const IContiguousIterator&);
|
||||||
|
|
||||||
|
// ~End CRandomAccessIterator.
|
||||||
|
};
|
||||||
|
|
||||||
|
// Use IContiguousIterator<int> represents a contiguous iterator
|
||||||
|
static_assert(CContiguousIterator<IContiguousIterator<int&>>);
|
||||||
|
static_assert( COutputIterator<IContiguousIterator<int&>, int>);
|
||||||
|
|
||||||
|
// The int* is the most typical example of a contiguous iterator
|
||||||
|
static_assert(CContiguousIterator<int*>);
|
||||||
|
|
||||||
|
#if PLATFORM_COMPILER_GCC
|
||||||
|
# pragma GCC diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
|
NAMESPACE_MODULE_END(Utility)
|
||||||
|
NAMESPACE_MODULE_END(Redcraft)
|
||||||
|
NAMESPACE_REDCRAFT_END
|
@ -1,67 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "CoreTypes.h"
|
|
||||||
#include "Iterator/Utility.h"
|
|
||||||
#include "Iterator/Sentinel.h"
|
|
||||||
#include "Iterator/ForwardIterator.h"
|
|
||||||
#include "TypeTraits/TypeTraits.h"
|
|
||||||
|
|
||||||
NAMESPACE_REDCRAFT_BEGIN
|
|
||||||
NAMESPACE_MODULE_BEGIN(Redcraft)
|
|
||||||
NAMESPACE_MODULE_BEGIN(Utility)
|
|
||||||
|
|
||||||
#if PLATFORM_COMPILER_GCC
|
|
||||||
# pragma GCC diagnostic push
|
|
||||||
# pragma GCC diagnostic ignored "-Wnon-template-friend"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** A concept specifies a type is a bidirectional iterator. Add the decrement operator to the forward iterator. */
|
|
||||||
template <typename I>
|
|
||||||
concept CBidirectionalIterator = CForwardIterator<I>
|
|
||||||
&& requires(I Iter) {
|
|
||||||
{ --Iter } -> CSameAs<I&>;
|
|
||||||
{ Iter-- } -> CSameAs<I >;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is an example of a bidirectional iterator, indicate the traits that define a bidirectional iterator.
|
|
||||||
* Regardless of the order in which the increment and decrement operators are applied,
|
|
||||||
* the result is always the same if both operations are performed the same number of times.
|
|
||||||
*/
|
|
||||||
template <CReferenceable T>
|
|
||||||
struct IBidirectionalIterator /* : IForwardIterator<T> */
|
|
||||||
{
|
|
||||||
// ~Begin CForwardIterator.
|
|
||||||
|
|
||||||
using FElementType = TRemoveCVRef<T>;
|
|
||||||
|
|
||||||
IBidirectionalIterator();
|
|
||||||
IBidirectionalIterator(const IBidirectionalIterator&);
|
|
||||||
IBidirectionalIterator(IBidirectionalIterator&&);
|
|
||||||
IBidirectionalIterator* operator=(const IBidirectionalIterator&);
|
|
||||||
IBidirectionalIterator* operator=(IBidirectionalIterator&&);
|
|
||||||
|
|
||||||
friend bool operator==(const IBidirectionalIterator&, const IBidirectionalIterator&);
|
|
||||||
|
|
||||||
T operator*() const;
|
|
||||||
|
|
||||||
// ~End CForwardIterator.
|
|
||||||
|
|
||||||
IBidirectionalIterator& operator++(); // Also satisfies CForwardIterator.
|
|
||||||
IBidirectionalIterator& operator--();
|
|
||||||
|
|
||||||
IBidirectionalIterator operator++(int); // Also satisfies CForwardIterator.
|
|
||||||
IBidirectionalIterator operator--(int);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Use IBidirectionalIterator<int> represents a bidirectional iterator.
|
|
||||||
static_assert(CBidirectionalIterator<IBidirectionalIterator<int&>>);
|
|
||||||
static_assert( COutputIterator<IBidirectionalIterator<int&>, int>);
|
|
||||||
|
|
||||||
#if PLATFORM_COMPILER_GCC
|
|
||||||
# pragma GCC diagnostic pop
|
|
||||||
#endif
|
|
||||||
|
|
||||||
NAMESPACE_MODULE_END(Utility)
|
|
||||||
NAMESPACE_MODULE_END(Redcraft)
|
|
||||||
NAMESPACE_REDCRAFT_END
|
|
@ -1,98 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "CoreTypes.h"
|
|
||||||
#include "Iterator/Utility.h"
|
|
||||||
#include "Iterator/Sentinel.h"
|
|
||||||
#include "Iterator/RandomAccessIterator.h"
|
|
||||||
#include "TypeTraits/TypeTraits.h"
|
|
||||||
#include "Memory/Address.h"
|
|
||||||
|
|
||||||
NAMESPACE_REDCRAFT_BEGIN
|
|
||||||
NAMESPACE_MODULE_BEGIN(Redcraft)
|
|
||||||
NAMESPACE_MODULE_BEGIN(Utility)
|
|
||||||
|
|
||||||
#if PLATFORM_COMPILER_GCC
|
|
||||||
# pragma GCC diagnostic push
|
|
||||||
# pragma GCC diagnostic ignored "-Wnon-template-friend"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A concept specifies a type is a contiguous iterator.
|
|
||||||
* Add the operator-> to the random access iterator and requires the operator* returns a true reference type.
|
|
||||||
*/
|
|
||||||
template <typename I>
|
|
||||||
concept CContiguousIterator = CRandomAccessIterator<I> && CLValueReference<TIteratorReference<I>>
|
|
||||||
&& CSameAs<TIteratorElement<I>, TRemoveCVRef<TIteratorReference<I>>>
|
|
||||||
&& CSameAs<TIteratorPointer<I>, TAddPointer<TIteratorReference<I>>>
|
|
||||||
&& requires(I& Iter)
|
|
||||||
{
|
|
||||||
{ ToAddress(Iter) } -> CSameAs<TAddPointer<TIteratorReference<I>>>;
|
|
||||||
};
|
|
||||||
|
|
||||||
/** This is an example of a contiguous iterator, indicate the traits that define a contiguous iterator. */
|
|
||||||
template <CLValueReference T>
|
|
||||||
struct IContiguousIterator /* : IRandomAccessIterator<T> */
|
|
||||||
{
|
|
||||||
// ~Begin CRandomAccessIterator.
|
|
||||||
|
|
||||||
using FElementType = TRemoveCVRef<T>;
|
|
||||||
|
|
||||||
IContiguousIterator();
|
|
||||||
IContiguousIterator(const IContiguousIterator&);
|
|
||||||
IContiguousIterator(IContiguousIterator&&);
|
|
||||||
IContiguousIterator* operator=(const IContiguousIterator&);
|
|
||||||
IContiguousIterator* operator=(IContiguousIterator&&);
|
|
||||||
|
|
||||||
friend bool operator==(const IContiguousIterator&, const IContiguousIterator&);
|
|
||||||
|
|
||||||
friend strong_ordering operator<=>(const IContiguousIterator&, const IContiguousIterator&);
|
|
||||||
|
|
||||||
// ~End CRandomAccessIterator.
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Dereference operator. See IForwardIterator.
|
|
||||||
* Specify, the return type must be a true reference type and refer to an element of a contiguous sequence, not a proxy class.
|
|
||||||
* Also satisfies CRandomAccessIterator.
|
|
||||||
*/
|
|
||||||
T operator*() const;
|
|
||||||
|
|
||||||
/** Indirection operator. Return the address of the element that the iterator is pointing to. */
|
|
||||||
TAddPointer<T> operator->() const;
|
|
||||||
|
|
||||||
// ~Begin CRandomAccessIterator.
|
|
||||||
|
|
||||||
T operator[](ptrdiff) const;
|
|
||||||
|
|
||||||
IContiguousIterator& operator++();
|
|
||||||
IContiguousIterator& operator--();
|
|
||||||
|
|
||||||
IContiguousIterator operator++(int);
|
|
||||||
IContiguousIterator operator--(int);
|
|
||||||
|
|
||||||
IContiguousIterator& operator+=(ptrdiff);
|
|
||||||
IContiguousIterator& operator-=(ptrdiff);
|
|
||||||
|
|
||||||
IContiguousIterator operator+(ptrdiff) const;
|
|
||||||
IContiguousIterator operator-(ptrdiff) const;
|
|
||||||
|
|
||||||
friend IContiguousIterator operator+(ptrdiff, const IContiguousIterator&);
|
|
||||||
|
|
||||||
friend ptrdiff operator-(const IContiguousIterator&, const IContiguousIterator&);
|
|
||||||
|
|
||||||
// ~End CRandomAccessIterator.
|
|
||||||
};
|
|
||||||
|
|
||||||
// Use IContiguousIterator<int> represents a contiguous iterator
|
|
||||||
static_assert(CContiguousIterator<IContiguousIterator<int&>>);
|
|
||||||
static_assert( COutputIterator<IContiguousIterator<int&>, int>);
|
|
||||||
|
|
||||||
// The int* is the most typical example of a contiguous iterator
|
|
||||||
static_assert(CContiguousIterator<int*>);
|
|
||||||
|
|
||||||
#if PLATFORM_COMPILER_GCC
|
|
||||||
# pragma GCC diagnostic pop
|
|
||||||
#endif
|
|
||||||
|
|
||||||
NAMESPACE_MODULE_END(Utility)
|
|
||||||
NAMESPACE_MODULE_END(Redcraft)
|
|
||||||
NAMESPACE_REDCRAFT_END
|
|
@ -3,9 +3,7 @@
|
|||||||
#include "CoreTypes.h"
|
#include "CoreTypes.h"
|
||||||
#include "Iterator/Utility.h"
|
#include "Iterator/Utility.h"
|
||||||
#include "Iterator/Sentinel.h"
|
#include "Iterator/Sentinel.h"
|
||||||
#include "Iterator/BidirectionalIterator.h"
|
#include "Iterator/BasicIterator.h"
|
||||||
#include "Iterator/RandomAccessIterator.h"
|
|
||||||
#include "Iterator/ContiguousIterator.h"
|
|
||||||
#include "Miscellaneous/AssertionMacros.h"
|
#include "Miscellaneous/AssertionMacros.h"
|
||||||
#include "Miscellaneous/Compare.h"
|
#include "Miscellaneous/Compare.h"
|
||||||
#include "TypeTraits/TypeTraits.h"
|
#include "TypeTraits/TypeTraits.h"
|
||||||
@ -48,7 +46,7 @@ public:
|
|||||||
FORCEINLINE constexpr TCountedIterator& operator=(TCountedIterator&&) = default;
|
FORCEINLINE constexpr TCountedIterator& operator=(TCountedIterator&&) = default;
|
||||||
FORCEINLINE constexpr ~TCountedIterator() = default;
|
FORCEINLINE constexpr ~TCountedIterator() = default;
|
||||||
|
|
||||||
FORCEINLINE constexpr explicit TCountedIterator(FIteratorType InValue, ptrdiff N) : Current(MoveTemp(InValue)) { check_code({ MaxLength = N; }); }
|
FORCEINLINE constexpr explicit TCountedIterator(FIteratorType InValue, ptrdiff N) : Current(MoveTemp(InValue)), Length(N) { check_code({ MaxLength = N; }); }
|
||||||
|
|
||||||
template <CInputOrOutputIterator J> requires (!CSameAs<I, J> && CConstructibleFrom<I, const J&>)
|
template <CInputOrOutputIterator J> requires (!CSameAs<I, J> && CConstructibleFrom<I, const J&>)
|
||||||
FORCEINLINE constexpr explicit (!CConvertibleTo<const J&, I>) TCountedIterator(const TCountedIterator<J>& InValue)
|
FORCEINLINE constexpr explicit (!CConvertibleTo<const J&, I>) TCountedIterator(const TCountedIterator<J>& InValue)
|
||||||
@ -136,7 +134,7 @@ static_assert(CBidirectionalIterator<TCountedIterator<IBidirectionalIterator<int
|
|||||||
static_assert( CRandomAccessIterator<TCountedIterator< IRandomAccessIterator<int&>>>);
|
static_assert( CRandomAccessIterator<TCountedIterator< IRandomAccessIterator<int&>>>);
|
||||||
static_assert( CContiguousIterator<TCountedIterator< IContiguousIterator<int&>>>);
|
static_assert( CContiguousIterator<TCountedIterator< IContiguousIterator<int&>>>);
|
||||||
|
|
||||||
//static_assert(COutputIterator<TCountedIterator<IOutputIterator<int&>>, int>);
|
static_assert(COutputIterator<TCountedIterator<IOutputIterator<int&>>, int>);
|
||||||
|
|
||||||
static_assert(CSizedSentinelFor<TCountedIterator<IForwardIterator<int>>, TCountedIterator<IForwardIterator<int>>>);
|
static_assert(CSizedSentinelFor<TCountedIterator<IForwardIterator<int>>, TCountedIterator<IForwardIterator<int>>>);
|
||||||
|
|
||||||
|
@ -1,64 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "CoreTypes.h"
|
|
||||||
#include "Iterator/Utility.h"
|
|
||||||
#include "Iterator/Sentinel.h"
|
|
||||||
#include "TypeTraits/TypeTraits.h"
|
|
||||||
|
|
||||||
NAMESPACE_REDCRAFT_BEGIN
|
|
||||||
NAMESPACE_MODULE_BEGIN(Redcraft)
|
|
||||||
NAMESPACE_MODULE_BEGIN(Utility)
|
|
||||||
|
|
||||||
#if PLATFORM_COMPILER_GCC
|
|
||||||
# pragma GCC diagnostic push
|
|
||||||
# pragma GCC diagnostic ignored "-Wnon-template-friend"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/** A concept specifies a type is an input iterator. It is input iterator, incrementable, and sentinel for itself. */
|
|
||||||
template <typename I>
|
|
||||||
concept CForwardIterator = CInputIterator<I> && CIncrementable<I> && CSentinelFor<I, I>;
|
|
||||||
|
|
||||||
/** This is an example of a forward iterator, indicate the traits that define a forward iterator. */
|
|
||||||
template <CReferenceable T>
|
|
||||||
struct IForwardIterator /* : IInputIterator<T>, IIncrementable, ISentinelFor<IForwardIterator> */
|
|
||||||
{
|
|
||||||
// ~Begin CInputIterator.
|
|
||||||
|
|
||||||
using FElementType = TRemoveCVRef<T>;
|
|
||||||
|
|
||||||
// ~End CInputIterator.
|
|
||||||
|
|
||||||
// ~Begin CIncrementable and CSentinelFor<IForwardIterator>.
|
|
||||||
|
|
||||||
IForwardIterator();
|
|
||||||
IForwardIterator(const IForwardIterator&);
|
|
||||||
IForwardIterator(IForwardIterator&&); // Also satisfies IInputIterator.
|
|
||||||
IForwardIterator* operator=(const IForwardIterator&);
|
|
||||||
IForwardIterator* operator=(IForwardIterator&&); // Also satisfies IInputIterator.
|
|
||||||
|
|
||||||
friend bool operator==(const IForwardIterator&, const IForwardIterator&);
|
|
||||||
|
|
||||||
// ~End CIncrementable and CSentinelFor<IForwardIterator>.
|
|
||||||
|
|
||||||
// ~Begin CInputIterator.
|
|
||||||
|
|
||||||
T operator*() const; // Optional satisfies CIndirectlyWritable.
|
|
||||||
|
|
||||||
IForwardIterator& operator++(); // Also satisfies CIncrementable.
|
|
||||||
|
|
||||||
IForwardIterator operator++(int); // Also satisfies CIncrementable.
|
|
||||||
|
|
||||||
// ~End CInputIterator.
|
|
||||||
};
|
|
||||||
|
|
||||||
// Use IForwardIterator<int> represents a forward iterator.
|
|
||||||
static_assert(CForwardIterator<IForwardIterator<int&>>);
|
|
||||||
static_assert( COutputIterator<IForwardIterator<int&>, int>);
|
|
||||||
|
|
||||||
#if PLATFORM_COMPILER_GCC
|
|
||||||
# pragma GCC diagnostic pop
|
|
||||||
#endif
|
|
||||||
|
|
||||||
NAMESPACE_MODULE_END(Utility)
|
|
||||||
NAMESPACE_MODULE_END(Redcraft)
|
|
||||||
NAMESPACE_REDCRAFT_END
|
|
@ -3,10 +3,7 @@
|
|||||||
#include "CoreTypes.h"
|
#include "CoreTypes.h"
|
||||||
#include "Iterator/Utility.h"
|
#include "Iterator/Utility.h"
|
||||||
#include "Iterator/Sentinel.h"
|
#include "Iterator/Sentinel.h"
|
||||||
#include "Iterator/ForwardIterator.h"
|
#include "Iterator/BasicIterator.h"
|
||||||
#include "Iterator/BidirectionalIterator.h"
|
|
||||||
#include "Iterator/RandomAccessIterator.h"
|
|
||||||
#include "Iterator/ContiguousIterator.h"
|
|
||||||
#include "Iterator/ReverseIterator.h"
|
#include "Iterator/ReverseIterator.h"
|
||||||
#include "Iterator/MoveIterator.h"
|
#include "Iterator/MoveIterator.h"
|
||||||
#include "Iterator/CountedIterator.h"
|
#include "Iterator/CountedIterator.h"
|
||||||
|
@ -3,10 +3,7 @@
|
|||||||
#include "CoreTypes.h"
|
#include "CoreTypes.h"
|
||||||
#include "Iterator/Utility.h"
|
#include "Iterator/Utility.h"
|
||||||
#include "Iterator/Sentinel.h"
|
#include "Iterator/Sentinel.h"
|
||||||
#include "Iterator/ForwardIterator.h"
|
#include "Iterator/BasicIterator.h"
|
||||||
#include "Iterator/BidirectionalIterator.h"
|
|
||||||
#include "Iterator/RandomAccessIterator.h"
|
|
||||||
#include "Iterator/ContiguousIterator.h"
|
|
||||||
#include "Miscellaneous/Compare.h"
|
#include "Miscellaneous/Compare.h"
|
||||||
#include "TypeTraits/TypeTraits.h"
|
#include "TypeTraits/TypeTraits.h"
|
||||||
#include "Templates/Utility.h"
|
#include "Templates/Utility.h"
|
||||||
|
@ -1,93 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "CoreTypes.h"
|
|
||||||
#include "Iterator/Utility.h"
|
|
||||||
#include "Iterator/Sentinel.h"
|
|
||||||
#include "Iterator/BidirectionalIterator.h"
|
|
||||||
#include "Miscellaneous/Compare.h"
|
|
||||||
#include "TypeTraits/TypeTraits.h"
|
|
||||||
|
|
||||||
NAMESPACE_REDCRAFT_BEGIN
|
|
||||||
NAMESPACE_MODULE_BEGIN(Redcraft)
|
|
||||||
NAMESPACE_MODULE_BEGIN(Utility)
|
|
||||||
|
|
||||||
#if PLATFORM_COMPILER_GCC
|
|
||||||
# pragma GCC diagnostic push
|
|
||||||
# pragma GCC diagnostic ignored "-Wnon-template-friend"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A concept specifies a type is a random access iterator.
|
|
||||||
* Add the three-way comparison, addition, subtraction and subscript operators to the bidirectional iterator.
|
|
||||||
*/
|
|
||||||
template <typename I>
|
|
||||||
concept CRandomAccessIterator = CBidirectionalIterator<I> && CTotallyOrdered<I> && CSizedSentinelFor<I, I>
|
|
||||||
&& requires(I Iter, const I Jter, const ptrdiff N) {
|
|
||||||
{ Iter += N } -> CSameAs<I&>;
|
|
||||||
{ Jter + N } -> CSameAs<I >;
|
|
||||||
{ N + Jter } -> CSameAs<I >;
|
|
||||||
{ Iter -= N } -> CSameAs<I&>;
|
|
||||||
{ Jter - N } -> CSameAs<I >;
|
|
||||||
{ Jter[N] } -> CSameAs<TIteratorReference<I>>;
|
|
||||||
};
|
|
||||||
|
|
||||||
/** This is an example of a random access iterator, indicate the traits that define a random access iterator. */
|
|
||||||
template <CReferenceable T>
|
|
||||||
struct IRandomAccessIterator /* : IBidirectionalIterator<T>, ISizedSentinelFor<IRandomAccessIterator> */
|
|
||||||
{
|
|
||||||
// ~Begin CBidirectionalIterator.
|
|
||||||
|
|
||||||
using FElementType = TRemoveCVRef<T>;
|
|
||||||
|
|
||||||
// ~End CBidirectionalIterator.
|
|
||||||
|
|
||||||
// ~Begin CBidirectionalIterator and CSizedSentinelFor<IRandomAccessIterator>.
|
|
||||||
|
|
||||||
IRandomAccessIterator();
|
|
||||||
IRandomAccessIterator(const IRandomAccessIterator&);
|
|
||||||
IRandomAccessIterator(IRandomAccessIterator&&);
|
|
||||||
IRandomAccessIterator* operator=(const IRandomAccessIterator&);
|
|
||||||
IRandomAccessIterator* operator=(IRandomAccessIterator&&);
|
|
||||||
|
|
||||||
friend bool operator==(const IRandomAccessIterator&, const IRandomAccessIterator&);
|
|
||||||
|
|
||||||
// ~End CBidirectionalIterator and CSizedSentinelFor<IRandomAccessIterator>.
|
|
||||||
|
|
||||||
friend strong_ordering operator<=>(const IRandomAccessIterator&, const IRandomAccessIterator&);
|
|
||||||
|
|
||||||
T operator*() const; // Also satisfies CBidirectionalIterator.
|
|
||||||
|
|
||||||
T operator[](ptrdiff) const;
|
|
||||||
|
|
||||||
// ~Begin CBidirectionalIterator.
|
|
||||||
|
|
||||||
IRandomAccessIterator& operator++();
|
|
||||||
IRandomAccessIterator& operator--();
|
|
||||||
|
|
||||||
IRandomAccessIterator operator++(int);
|
|
||||||
IRandomAccessIterator operator--(int);
|
|
||||||
|
|
||||||
// ~End CBidirectionalIterator.
|
|
||||||
|
|
||||||
IRandomAccessIterator& operator+=(ptrdiff);
|
|
||||||
IRandomAccessIterator& operator-=(ptrdiff);
|
|
||||||
|
|
||||||
IRandomAccessIterator operator+(ptrdiff) const;
|
|
||||||
IRandomAccessIterator operator-(ptrdiff) const;
|
|
||||||
|
|
||||||
friend IRandomAccessIterator operator+(ptrdiff, const IRandomAccessIterator&);
|
|
||||||
|
|
||||||
friend ptrdiff operator-(const IRandomAccessIterator&, const IRandomAccessIterator&); // Also satisfies CSizedSentinelFor<IRandomAccessIterator>.
|
|
||||||
};
|
|
||||||
|
|
||||||
// Use IRandomAccessIterator<int> represents a random access iterator
|
|
||||||
static_assert(CRandomAccessIterator<IRandomAccessIterator<int&>>);
|
|
||||||
static_assert( COutputIterator<IRandomAccessIterator<int&>, int>);
|
|
||||||
|
|
||||||
#if PLATFORM_COMPILER_GCC
|
|
||||||
# pragma GCC diagnostic pop
|
|
||||||
#endif
|
|
||||||
|
|
||||||
NAMESPACE_MODULE_END(Utility)
|
|
||||||
NAMESPACE_MODULE_END(Redcraft)
|
|
||||||
NAMESPACE_REDCRAFT_END
|
|
@ -3,9 +3,7 @@
|
|||||||
#include "CoreTypes.h"
|
#include "CoreTypes.h"
|
||||||
#include "Iterator/Utility.h"
|
#include "Iterator/Utility.h"
|
||||||
#include "Iterator/Sentinel.h"
|
#include "Iterator/Sentinel.h"
|
||||||
#include "Iterator/BidirectionalIterator.h"
|
#include "Iterator/BasicIterator.h"
|
||||||
#include "Iterator/RandomAccessIterator.h"
|
|
||||||
#include "Iterator/ContiguousIterator.h"
|
|
||||||
#include "Miscellaneous/Compare.h"
|
#include "Miscellaneous/Compare.h"
|
||||||
#include "TypeTraits/TypeTraits.h"
|
#include "TypeTraits/TypeTraits.h"
|
||||||
#include "Templates/Utility.h"
|
#include "Templates/Utility.h"
|
||||||
|
@ -1,15 +1,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CoreTypes.h"
|
#include "CoreTypes.h"
|
||||||
#include "Range/View.h"
|
|
||||||
#include "Range/Pipe.h"
|
|
||||||
#include "Range/Utility.h"
|
|
||||||
#include "Range/AllView.h"
|
|
||||||
#include "Memory/Address.h"
|
|
||||||
#include "Templates/Invoke.h"
|
|
||||||
#include "Iterator/Iterator.h"
|
|
||||||
#include "Templates/Utility.h"
|
|
||||||
#include "TypeTraits/TypeTraits.h"
|
#include "TypeTraits/TypeTraits.h"
|
||||||
|
#include "Templates/Utility.h"
|
||||||
|
#include "Templates/Invoke.h"
|
||||||
|
#include "Iterator/Utility.h"
|
||||||
|
#include "Iterator/BasicIterator.h"
|
||||||
|
#include "Memory/Address.h"
|
||||||
|
#include "Range/Utility.h"
|
||||||
|
#include "Range/Pipe.h"
|
||||||
|
#include "Range/View.h"
|
||||||
|
#include "Range/AllView.h"
|
||||||
|
|
||||||
NAMESPACE_REDCRAFT_BEGIN
|
NAMESPACE_REDCRAFT_BEGIN
|
||||||
NAMESPACE_MODULE_BEGIN(Redcraft)
|
NAMESPACE_MODULE_BEGIN(Redcraft)
|
||||||
@ -20,7 +21,7 @@ NAMESPACE_BEGIN(Range)
|
|||||||
/**
|
/**
|
||||||
* A view adapter that consists of the elements of a range that satisfies a predicate.
|
* A view adapter that consists of the elements of a range that satisfies a predicate.
|
||||||
* When based on an input view, the filter view satisfies at least an input view up to a bidirectional view.
|
* When based on an input view, the filter view satisfies at least an input view up to a bidirectional view.
|
||||||
* When based on a common view, the counted iterator satisfies a common view.
|
* When based on a common view, the filter view satisfies a common view.
|
||||||
*/
|
*/
|
||||||
template <CInputRange V, CPredicate<TRangeReference<V>> Pred> requires (CView<V> && CObject<Pred> && CMoveConstructible<Pred>)
|
template <CInputRange V, CPredicate<TRangeReference<V>> Pred> requires (CView<V> && CObject<Pred> && CMoveConstructible<Pred>)
|
||||||
class TFilterView : public IBasicViewInterface<TFilterView<V, Pred>>
|
class TFilterView : public IBasicViewInterface<TFilterView<V, Pred>>
|
||||||
@ -135,8 +136,7 @@ private:
|
|||||||
|
|
||||||
NODISCARD FORCEINLINE constexpr bool operator==(const FIteratorImpl& InValue) const& { return Current == InValue.Current; }
|
NODISCARD FORCEINLINE constexpr bool operator==(const FIteratorImpl& InValue) const& { return Current == InValue.Current; }
|
||||||
|
|
||||||
NODISCARD FORCEINLINE constexpr const TRangeSentinel<V>& GetBase() const& { return Current; }
|
NODISCARD FORCEINLINE constexpr TRangeSentinel<V> GetBase() const { return Current; }
|
||||||
NODISCARD FORCEINLINE constexpr TRangeSentinel<V> GetBase() && { return MoveTemp(Current); }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
112
Redcraft.Utility/Source/Public/Range/MoveView.h
Normal file
112
Redcraft.Utility/Source/Public/Range/MoveView.h
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreTypes.h"
|
||||||
|
#include "TypeTraits/TypeTraits.h"
|
||||||
|
#include "Templates/Utility.h"
|
||||||
|
#include "Iterator/Utility.h"
|
||||||
|
#include "Iterator/BasicIterator.h"
|
||||||
|
#include "Iterator/MoveIterator.h"
|
||||||
|
#include "Range/Utility.h"
|
||||||
|
#include "Range/Pipe.h"
|
||||||
|
#include "Range/View.h"
|
||||||
|
#include "Range/AllView.h"
|
||||||
|
|
||||||
|
NAMESPACE_REDCRAFT_BEGIN
|
||||||
|
NAMESPACE_MODULE_BEGIN(Redcraft)
|
||||||
|
NAMESPACE_MODULE_BEGIN(Utility)
|
||||||
|
|
||||||
|
NAMESPACE_BEGIN(Range)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A view adapter which dereferences to a rvalue reference.
|
||||||
|
* When based on an input view, the move view satisfies at least an input view up to a random access view.
|
||||||
|
* When based on a common view, the move view satisfies a common view.
|
||||||
|
*/
|
||||||
|
template <CInputRange V> requires (CView<V>)
|
||||||
|
class TMoveView : public IBasicViewInterface<TMoveView<V>>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
using FElementType = TRangeElement<V>;
|
||||||
|
using FReference = TRangeRValueReference<V>;
|
||||||
|
|
||||||
|
FORCEINLINE constexpr TMoveView() requires (CDefaultConstructible<V>) = default;
|
||||||
|
|
||||||
|
FORCEINLINE constexpr explicit TMoveView(V InBase) : Base(MoveTemp(InBase)) { }
|
||||||
|
|
||||||
|
NODISCARD FORCEINLINE constexpr auto Begin() { return MakeMoveIterator(Range::Begin(Base)); }
|
||||||
|
|
||||||
|
NODISCARD FORCEINLINE constexpr auto End()
|
||||||
|
{
|
||||||
|
if constexpr (CCommonRange<V>)
|
||||||
|
{
|
||||||
|
return MakeMoveIterator(Range::End(Base));
|
||||||
|
}
|
||||||
|
else return MakeMoveSentinel(Range::End(Base));
|
||||||
|
}
|
||||||
|
|
||||||
|
NODISCARD FORCEINLINE constexpr auto Begin() const requires (CRange<const V>) { return MakeMoveIterator(Range::Begin(Base)); }
|
||||||
|
|
||||||
|
NODISCARD FORCEINLINE constexpr auto End() const requires (CRange<const V>)
|
||||||
|
{
|
||||||
|
if constexpr (CCommonRange<V>)
|
||||||
|
{
|
||||||
|
return MakeMoveIterator(Range::End(Base));
|
||||||
|
}
|
||||||
|
else return MakeMoveSentinel(Range::End(Base));
|
||||||
|
}
|
||||||
|
|
||||||
|
NODISCARD FORCEINLINE constexpr size_t Num() requires (CSizedRange< V>) { return Range::Num(Base); }
|
||||||
|
NODISCARD FORCEINLINE constexpr size_t Num() const requires (CSizedRange<const V>) { return Range::Num(Base); }
|
||||||
|
|
||||||
|
NODISCARD FORCEINLINE constexpr V GetBase() const& requires (CCopyConstructible<V>) { return Base; }
|
||||||
|
NODISCARD FORCEINLINE constexpr V GetBase() && { return MoveTemp(Base); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
NO_UNIQUE_ADDRESS V Base;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename R>
|
||||||
|
TMoveView(R&&) -> TMoveView<TAllView<R>>;
|
||||||
|
|
||||||
|
static_assert( CInputRange<TMoveView<TAllView<IRange< IInputIterator<int&>>>>>);
|
||||||
|
static_assert( CForwardRange<TMoveView<TAllView<IRange< IForwardIterator<int&>>>>>);
|
||||||
|
static_assert(CBidirectionalRange<TMoveView<TAllView<IRange<IBidirectionalIterator<int&>>>>>);
|
||||||
|
static_assert( CRandomAccessRange<TMoveView<TAllView<IRange< IRandomAccessIterator<int&>>>>>);
|
||||||
|
static_assert( CRandomAccessRange<TMoveView<TAllView<IRange< IContiguousIterator<int&>>>>>);
|
||||||
|
|
||||||
|
static_assert(CCommonRange<TMoveView<TAllView<ICommonRange<IForwardIterator<int>>>>>);
|
||||||
|
static_assert( CView<TMoveView<TAllView< IRange< IInputIterator<int>>>>>);
|
||||||
|
|
||||||
|
NAMESPACE_END(Range)
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr bool bEnableBorrowedRange<Range::TMoveView<T>> = bEnableBorrowedRange<T>;
|
||||||
|
|
||||||
|
NAMESPACE_BEGIN(Range)
|
||||||
|
|
||||||
|
/** Creates A view adapter that dereferences to a rvalue reference. */
|
||||||
|
template <CViewableRange R> requires (requires { TMoveView(DeclVal<R>()); })
|
||||||
|
NODISCARD FORCEINLINE constexpr auto Move(R&& Base)
|
||||||
|
{
|
||||||
|
return TMoveView(Forward<R>(Base));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Creates A view adapter that dereferences to a rvalue reference. */
|
||||||
|
NODISCARD FORCEINLINE constexpr auto Move()
|
||||||
|
{
|
||||||
|
using FClosure = decltype([]<CViewableRange R> requires (requires { Range::Move(DeclVal<R>()); }) (R&& Base)
|
||||||
|
{
|
||||||
|
return Range::Move(Forward<R>(Base));
|
||||||
|
});
|
||||||
|
|
||||||
|
return TAdaptorClosure<FClosure>();
|
||||||
|
}
|
||||||
|
|
||||||
|
NAMESPACE_END(Range)
|
||||||
|
|
||||||
|
NAMESPACE_MODULE_END(Utility)
|
||||||
|
NAMESPACE_MODULE_END(Redcraft)
|
||||||
|
NAMESPACE_REDCRAFT_END
|
@ -7,5 +7,7 @@
|
|||||||
#include "Range/Factory.h"
|
#include "Range/Factory.h"
|
||||||
#include "Range/Pipe.h"
|
#include "Range/Pipe.h"
|
||||||
#include "Range/AllView.h"
|
#include "Range/AllView.h"
|
||||||
|
#include "Range/MoveView.h"
|
||||||
#include "Range/FilterView.h"
|
#include "Range/FilterView.h"
|
||||||
#include "Range/TransformView.h"
|
#include "Range/TransformView.h"
|
||||||
|
#include "Range/TakeView.h"
|
||||||
|
186
Redcraft.Utility/Source/Public/Range/TakeView.h
Normal file
186
Redcraft.Utility/Source/Public/Range/TakeView.h
Normal file
@ -0,0 +1,186 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreTypes.h"
|
||||||
|
#include "TypeTraits/TypeTraits.h"
|
||||||
|
#include "Templates/Utility.h"
|
||||||
|
#include "Iterator/Utility.h"
|
||||||
|
#include "Iterator/BasicIterator.h"
|
||||||
|
#include "Iterator/CountedIterator.h"
|
||||||
|
#include "Numeric/Math.h"
|
||||||
|
#include "Range/Utility.h"
|
||||||
|
#include "Range/Pipe.h"
|
||||||
|
#include "Range/View.h"
|
||||||
|
#include "Range/AllView.h"
|
||||||
|
|
||||||
|
NAMESPACE_REDCRAFT_BEGIN
|
||||||
|
NAMESPACE_MODULE_BEGIN(Redcraft)
|
||||||
|
NAMESPACE_MODULE_BEGIN(Utility)
|
||||||
|
|
||||||
|
NAMESPACE_BEGIN(Range)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A view adapter that includes a specified number of elements from the beginning of a range.
|
||||||
|
* When based on any view, the take view satisfies the corresponding any view.
|
||||||
|
* When based on a random access and sized view, the take view satisfies a common view.
|
||||||
|
*/
|
||||||
|
template <CView V>
|
||||||
|
class TTakeView : public IBasicViewInterface<TTakeView<V>>
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
|
||||||
|
template <bool bConst> class FSentinelImpl;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
FORCEINLINE constexpr TTakeView() requires (CDefaultConstructible<V>) = default;
|
||||||
|
|
||||||
|
FORCEINLINE constexpr TTakeView(V InBase, size_t InCount) : Base(MoveTemp(InBase)), Count(InCount) { }
|
||||||
|
|
||||||
|
NODISCARD FORCEINLINE constexpr auto Begin()
|
||||||
|
{
|
||||||
|
if constexpr (CSizedRange<V>)
|
||||||
|
{
|
||||||
|
if constexpr (CRandomAccessRange<V>)
|
||||||
|
{
|
||||||
|
return Range::Begin(Base);
|
||||||
|
}
|
||||||
|
else return MakeCountedIterator(Range::Begin(Base), Num());
|
||||||
|
}
|
||||||
|
else return MakeCountedIterator(Range::Begin(Base), Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
NODISCARD FORCEINLINE constexpr auto Begin() const requires (CRange<const V>)
|
||||||
|
{
|
||||||
|
if constexpr (CSizedRange<const V>)
|
||||||
|
{
|
||||||
|
if constexpr (CRandomAccessRange<const V>)
|
||||||
|
{
|
||||||
|
return Range::Begin(Base);
|
||||||
|
}
|
||||||
|
else return MakeCountedIterator(Range::Begin(Base), Num());
|
||||||
|
}
|
||||||
|
else return MakeCountedIterator(Range::Begin(Base), Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
NODISCARD FORCEINLINE constexpr auto End()
|
||||||
|
{
|
||||||
|
if constexpr (CSizedRange<V>)
|
||||||
|
{
|
||||||
|
if constexpr (CRandomAccessRange<V>)
|
||||||
|
{
|
||||||
|
return Range::Begin(Base) + Num();
|
||||||
|
}
|
||||||
|
else return DefaultSentinel;
|
||||||
|
}
|
||||||
|
else return FSentinelImpl<false>(Range::End(Base));
|
||||||
|
}
|
||||||
|
|
||||||
|
NODISCARD FORCEINLINE constexpr auto End() const requires (CRange<const V>)
|
||||||
|
{
|
||||||
|
if constexpr (CSizedRange<const V>)
|
||||||
|
{
|
||||||
|
if constexpr (CRandomAccessRange<const V>)
|
||||||
|
{
|
||||||
|
return Range::Begin(Base) + Num();
|
||||||
|
}
|
||||||
|
else return DefaultSentinel;
|
||||||
|
}
|
||||||
|
else return FSentinelImpl<true>(Range::End(Base));
|
||||||
|
}
|
||||||
|
|
||||||
|
NODISCARD FORCEINLINE constexpr size_t Num() requires (CSizedRange< V>) { return Math::Min(Range::Num(Base), Count); }
|
||||||
|
NODISCARD FORCEINLINE constexpr size_t Num() const requires (CSizedRange<const V>) { return Math::Min(Range::Num(Base), Count); }
|
||||||
|
|
||||||
|
NODISCARD FORCEINLINE constexpr V GetBase() const& requires (CCopyConstructible<V>) { return Base; }
|
||||||
|
NODISCARD FORCEINLINE constexpr V GetBase() && { return MoveTemp(Base); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
NO_UNIQUE_ADDRESS V Base;
|
||||||
|
|
||||||
|
size_t Count;
|
||||||
|
|
||||||
|
template <bool bConst>
|
||||||
|
class FSentinelImpl final
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
|
||||||
|
using FBase = TConditional<bConst, const V, V>;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
FORCEINLINE constexpr FSentinelImpl() = default;
|
||||||
|
|
||||||
|
FORCEINLINE constexpr FSentinelImpl(FSentinelImpl<!bConst> Sentinel) requires (bConst && CConvertibleTo<TRangeSentinel<V>, TRangeSentinel<FBase>>)
|
||||||
|
: Current(Sentinel.Current)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
NODISCARD FORCEINLINE constexpr bool operator==(const TCountedIterator<TRangeIterator<FBase>>& InValue) const&
|
||||||
|
{
|
||||||
|
return InValue.Num() == 0 || InValue.GetBase() == Current;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <bool bOther = !bConst> requires (CSentinelFor<TRangeSentinel<FBase>, TRangeIterator<TConditional<bOther, const V, V>>>)
|
||||||
|
NODISCARD FORCEINLINE constexpr bool operator==(const TCountedIterator<TRangeIterator<TConditional<bOther, const V, V>>>& InValue)
|
||||||
|
{
|
||||||
|
return InValue.Num() == 0 || InValue.GetBase() == Current;
|
||||||
|
}
|
||||||
|
|
||||||
|
NODISCARD FORCEINLINE constexpr TRangeSentinel<FBase> GetBase() const { return Current; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
NO_UNIQUE_ADDRESS TRangeSentinel<FBase> Current;
|
||||||
|
|
||||||
|
FORCEINLINE constexpr FSentinelImpl(TRangeSentinel<FBase> InCurrent) : Current(InCurrent) { }
|
||||||
|
|
||||||
|
friend TTakeView;
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename R>
|
||||||
|
TTakeView(R&&, size_t) -> TTakeView<TAllView<R>>;
|
||||||
|
|
||||||
|
static_assert( CInputRange<TTakeView<TAllView<IRange< IInputIterator<int&>>>>>);
|
||||||
|
static_assert( CForwardRange<TTakeView<TAllView<IRange< IForwardIterator<int&>>>>>);
|
||||||
|
static_assert(CBidirectionalRange<TTakeView<TAllView<IRange<IBidirectionalIterator<int&>>>>>);
|
||||||
|
static_assert( CRandomAccessRange<TTakeView<TAllView<IRange< IRandomAccessIterator<int&>>>>>);
|
||||||
|
static_assert( CContiguousRange<TTakeView<TAllView<IRange< IContiguousIterator<int&>>>>>);
|
||||||
|
|
||||||
|
static_assert(CCommonRange<TTakeView<TAllView<ISizedRange< IRandomAccessIterator<int>>>>>);
|
||||||
|
static_assert( CSizedRange<TTakeView<TAllView<ISizedRange<IInputOrOutputIterator<int>>>>>);
|
||||||
|
static_assert( CView<TTakeView<TAllView< IRange<IInputOrOutputIterator<int>>>>>);
|
||||||
|
|
||||||
|
static_assert(COutputRange<TTakeView<TAllView<IRange<IOutputIterator<int&>>>>, int>);
|
||||||
|
|
||||||
|
NAMESPACE_END(Range)
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr bool bEnableBorrowedRange<Range::TTakeView<T>> = bEnableBorrowedRange<T>;
|
||||||
|
|
||||||
|
NAMESPACE_BEGIN(Range)
|
||||||
|
|
||||||
|
/** Creates A view adapter that includes a specified number of elements from the beginning of a range. */
|
||||||
|
template <CViewableRange R> requires (requires { TTakeView(DeclVal<R>(), DeclVal<size_t>()); })
|
||||||
|
NODISCARD FORCEINLINE constexpr auto Take(R&& Base, size_t Count)
|
||||||
|
{
|
||||||
|
return TTakeView(Forward<R>(Base), Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Creates A view adapter that includes a specified number of elements from the beginning of a range. */
|
||||||
|
NODISCARD FORCEINLINE constexpr auto Take(size_t Count)
|
||||||
|
{
|
||||||
|
using FClosure = decltype([]<CViewableRange R> requires (requires { Range::Take(DeclVal<R>(), DeclVal<size_t>()); }) (R&& Base, size_t Count)
|
||||||
|
{
|
||||||
|
return Range::Take(Forward<R>(Base), Count);
|
||||||
|
});
|
||||||
|
|
||||||
|
return TAdaptorClosure<FClosure, size_t>(Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
NAMESPACE_END(Range)
|
||||||
|
|
||||||
|
NAMESPACE_MODULE_END(Utility)
|
||||||
|
NAMESPACE_MODULE_END(Redcraft)
|
||||||
|
NAMESPACE_REDCRAFT_END
|
@ -18,8 +18,8 @@ NAMESPACE_BEGIN(Range)
|
|||||||
/**
|
/**
|
||||||
* A view adapter of a sequence that applies a transformation function to each element.
|
* A view adapter of a sequence that applies a transformation function to each element.
|
||||||
* When based on an input view, the transform view satisfies at least an input view up to a random access view.
|
* When based on an input view, the transform view satisfies at least an input view up to a random access view.
|
||||||
* When based on a common view, the counted iterator satisfies a common view. When based on a sized view,
|
* When based on a common view, the transform view satisfies a common view. When based on a sized view,
|
||||||
* the counted iterator satisfies a sized view. When based on a forward view and the function return
|
* the transform view satisfies a sized view. When based on a forward view and the function return
|
||||||
* an assignable value, the transform view satisfies an output view.
|
* an assignable value, the transform view satisfies an output view.
|
||||||
*/
|
*/
|
||||||
template <CInputRange V, CMoveConstructible F> requires (CView<V> && CObject<F>
|
template <CInputRange V, CMoveConstructible F> requires (CView<V> && CObject<F>
|
||||||
@ -178,8 +178,7 @@ private:
|
|||||||
return RHS.GetBase() - LHS.GetBase();
|
return RHS.GetBase() - LHS.GetBase();
|
||||||
}
|
}
|
||||||
|
|
||||||
NODISCARD FORCEINLINE constexpr const TRangeIterator<FBase>& GetBase() const& { return Current; }
|
NODISCARD FORCEINLINE constexpr TRangeSentinel<FBase> GetBase() const { return Current; }
|
||||||
NODISCARD FORCEINLINE constexpr TRangeIterator<FBase> GetBase() && { return MoveTemp(Current); }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CoreTypes.h"
|
#include "CoreTypes.h"
|
||||||
#include "Templates/Utility.h"
|
|
||||||
#include "Iterator/Iterator.h"
|
|
||||||
#include "TypeTraits/TypeTraits.h"
|
#include "TypeTraits/TypeTraits.h"
|
||||||
|
#include "Templates/Utility.h"
|
||||||
|
#include "Iterator/Utility.h"
|
||||||
|
#include "Iterator/BasicIterator.h"
|
||||||
|
#include "Iterator/Sentinel.h"
|
||||||
|
#include "Iterator/ReverseIterator.h"
|
||||||
|
|
||||||
NAMESPACE_REDCRAFT_BEGIN
|
NAMESPACE_REDCRAFT_BEGIN
|
||||||
NAMESPACE_MODULE_BEGIN(Redcraft)
|
NAMESPACE_MODULE_BEGIN(Redcraft)
|
||||||
@ -274,12 +277,12 @@ concept CSizedRange = CRange<R>
|
|||||||
template <CInputOrOutputIterator I, CSizedSentinelFor<I> S = ISizedSentinelFor<I>>
|
template <CInputOrOutputIterator I, CSizedSentinelFor<I> S = ISizedSentinelFor<I>>
|
||||||
struct ISizedRange /* : IRange<I, S> */
|
struct ISizedRange /* : IRange<I, S> */
|
||||||
{
|
{
|
||||||
// ~Begin CRange
|
// ~Begin CRange.
|
||||||
|
|
||||||
I Begin() /* const */;
|
I Begin() /* const */;
|
||||||
S End() /* const */;
|
S End() /* const */;
|
||||||
|
|
||||||
// ~End CRange
|
// ~End CRange.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the number of elements in the range.
|
* Get the number of elements in the range.
|
||||||
@ -341,12 +344,12 @@ concept CContiguousRange = CRandomAccessRange<R> && CContiguousIterator<TRangeIt
|
|||||||
template <CContiguousIterator I, CSentinelFor<I> S = ISentinelFor<I>>
|
template <CContiguousIterator I, CSentinelFor<I> S = ISentinelFor<I>>
|
||||||
struct IContiguousRange /* : IRange<I, S> */
|
struct IContiguousRange /* : IRange<I, S> */
|
||||||
{
|
{
|
||||||
// ~Begin CRange
|
// ~Begin CRange.
|
||||||
|
|
||||||
I Begin() /* const */;
|
I Begin() /* const */;
|
||||||
S End() /* const */;
|
S End() /* const */;
|
||||||
|
|
||||||
// ~End CRange
|
// ~End CRange.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the pointer to the container element storage.
|
* Get the pointer to the container element storage.
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CoreTypes.h"
|
#include "CoreTypes.h"
|
||||||
#include "Range/Utility.h"
|
|
||||||
#include "Iterator/Iterator.h"
|
|
||||||
#include "Templates/Utility.h"
|
|
||||||
#include "TypeTraits/TypeTraits.h"
|
#include "TypeTraits/TypeTraits.h"
|
||||||
|
#include "Templates/Utility.h"
|
||||||
|
#include "Iterator/Utility.h"
|
||||||
|
#include "Iterator/Sentinel.h"
|
||||||
|
#include "Iterator/BasicIterator.h"
|
||||||
|
#include "Iterator/ReverseIterator.h"
|
||||||
|
#include "Memory/Address.h"
|
||||||
|
#include "Range/Utility.h"
|
||||||
|
|
||||||
NAMESPACE_REDCRAFT_BEGIN
|
NAMESPACE_REDCRAFT_BEGIN
|
||||||
NAMESPACE_MODULE_BEGIN(Redcraft)
|
NAMESPACE_MODULE_BEGIN(Redcraft)
|
||||||
@ -19,32 +23,26 @@ class IBasicViewInterface
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
/** @return The pointer to the underlying element storage. */
|
/** @return The pointer to the underlying element storage. */
|
||||||
NODISCARD FORCEINLINE constexpr auto GetData() requires (CContiguousRange< T>) { return Range::GetData(static_cast< T&>(*this)); }
|
NODISCARD FORCEINLINE constexpr auto GetData() requires (CContiguousIterator<TRangeIterator< T>>) { return ToAddress(Range::Begin(static_cast< T&>(*this))); }
|
||||||
NODISCARD FORCEINLINE constexpr auto GetData() const requires (CContiguousRange<const T>) { return Range::GetData(static_cast<const T&>(*this)); }
|
NODISCARD FORCEINLINE constexpr auto GetData() const requires (CContiguousIterator<TRangeIterator<const T>>) { return ToAddress(Range::Begin(static_cast<const T&>(*this))); }
|
||||||
|
|
||||||
/** @return The reverse iterator to the first or end element. */
|
/** @return The reverse iterator to the first or end element. */
|
||||||
NODISCARD FORCEINLINE constexpr auto Begin() requires (CRange< T>) { return Range::Begin(static_cast< T&>(*this)); }
|
NODISCARD FORCEINLINE constexpr auto RBegin() requires (CBidirectionalRange< T> && CCommonRange< T>) { return MakeReverseIterator(Range::End (static_cast< T&>(*this))); }
|
||||||
NODISCARD FORCEINLINE constexpr auto End() requires (CRange< T>) { return Range::End (static_cast< T&>(*this)); }
|
NODISCARD FORCEINLINE constexpr auto REnd() requires (CBidirectionalRange< T> && CCommonRange< T>) { return MakeReverseIterator(Range::Begin(static_cast< T&>(*this))); }
|
||||||
NODISCARD FORCEINLINE constexpr auto Begin() const requires (CRange<const T>) { return Range::Begin(static_cast<const T&>(*this)); }
|
NODISCARD FORCEINLINE constexpr auto RBegin() const requires (CBidirectionalRange<const T> && CCommonRange<const T>) { return MakeReverseIterator(Range::End (static_cast<const T&>(*this))); }
|
||||||
NODISCARD FORCEINLINE constexpr auto End() const requires (CRange<const T>) { return Range::End (static_cast<const T&>(*this)); }
|
NODISCARD FORCEINLINE constexpr auto REnd() const requires (CBidirectionalRange<const T> && CCommonRange<const T>) { return MakeReverseIterator(Range::Begin(static_cast<const T&>(*this))); }
|
||||||
|
|
||||||
/** @return The reverse iterator to the first or end element. */
|
|
||||||
NODISCARD FORCEINLINE constexpr auto RBegin() requires (CBidirectionalRange< T> && CCommonRange< T>) { return Range::RBegin(static_cast< T&>(*this)); }
|
|
||||||
NODISCARD FORCEINLINE constexpr auto REnd() requires (CBidirectionalRange< T> && CCommonRange< T>) { return Range::REnd (static_cast< T&>(*this)); }
|
|
||||||
NODISCARD FORCEINLINE constexpr auto RBegin() const requires (CBidirectionalRange<const T> && CCommonRange<const T>) { return Range::RBegin(static_cast<const T&>(*this)); }
|
|
||||||
NODISCARD FORCEINLINE constexpr auto REnd() const requires (CBidirectionalRange<const T> && CCommonRange<const T>) { return Range::REnd (static_cast<const T&>(*this)); }
|
|
||||||
|
|
||||||
/** @return The number of elements in the container. */
|
/** @return The number of elements in the container. */
|
||||||
NODISCARD FORCEINLINE constexpr size_t Num() requires (CSizedRange< T>) { return Range::Num(static_cast< T&>(*this)); }
|
NODISCARD FORCEINLINE constexpr size_t Num() requires (CForwardRange< T> && CSizedSentinelFor<TRangeSentinel< T>, TRangeIterator< T>>) { T& Derived = static_cast< T&>(*this); return Range::End(Derived) - Range::Begin(Derived); }
|
||||||
NODISCARD FORCEINLINE constexpr size_t Num() const requires (CSizedRange<const T>) { return Range::Num(static_cast<const T&>(*this)); }
|
NODISCARD FORCEINLINE constexpr size_t Num() const requires (CForwardRange<const T> && CSizedSentinelFor<TRangeSentinel<const T>, TRangeIterator<const T>>) { const T& Derived = static_cast<const T&>(*this); return Range::End(Derived) - Range::Begin(Derived); }
|
||||||
|
|
||||||
/** @return true if the container is empty, false otherwise. */
|
/** @return true if the container is empty, false otherwise. */
|
||||||
NODISCARD FORCEINLINE constexpr bool IsEmpty() requires (CSizedRange< T> || CForwardRange< T>) { return Range::IsEmpty(static_cast< T&>(*this)); }
|
NODISCARD FORCEINLINE constexpr bool IsEmpty() requires (CSizedRange< T> || CForwardRange< T>) { T& Derived = static_cast< T&>(*this); if constexpr (CSizedRange< T>) return Range::Num(Derived) == 0; else return Range::Begin(Derived) == Range::End(Derived); }
|
||||||
NODISCARD FORCEINLINE constexpr bool IsEmpty() const requires (CSizedRange<const T> || CForwardRange<const T>) { return Range::IsEmpty(static_cast<const T&>(*this)); }
|
NODISCARD FORCEINLINE constexpr bool IsEmpty() const requires (CSizedRange<const T> || CForwardRange<const T>) { const T& Derived = static_cast<const T&>(*this); if constexpr (CSizedRange<const T>) return Range::Num(Derived) == 0; else return Range::Begin(Derived) == Range::End(Derived); }
|
||||||
|
|
||||||
/** @return true if the container is empty, false otherwise. */
|
/** @return true if the container is empty, false otherwise. */
|
||||||
NODISCARD FORCEINLINE constexpr explicit operator bool() requires (CSizedRange< T> || CForwardRange< T>) { return !Range::IsEmpty(static_cast< T&>(*this)); }
|
NODISCARD FORCEINLINE constexpr explicit operator bool() requires (requires { Range::IsEmpty(DeclVal< T&>()); }) { return !Range::IsEmpty(static_cast< T&>(*this)); }
|
||||||
NODISCARD FORCEINLINE constexpr explicit operator bool() const requires (CSizedRange<const T> || CForwardRange<const T>) { return !Range::IsEmpty(static_cast<const T&>(*this)); }
|
NODISCARD FORCEINLINE constexpr explicit operator bool() const requires (requires { Range::IsEmpty(DeclVal<const T&>()); }) { return !Range::IsEmpty(static_cast<const T&>(*this)); }
|
||||||
|
|
||||||
/** @return The reference to the requested element. */
|
/** @return The reference to the requested element. */
|
||||||
NODISCARD FORCEINLINE constexpr decltype(auto) operator[](size_t Index) requires (CRandomAccessRange< T>) { return Range::Begin(static_cast< T&>(*this))[Index]; }
|
NODISCARD FORCEINLINE constexpr decltype(auto) operator[](size_t Index) requires (CRandomAccessRange< T>) { return Range::Begin(static_cast< T&>(*this))[Index]; }
|
||||||
@ -56,7 +54,14 @@ public:
|
|||||||
NODISCARD FORCEINLINE constexpr decltype(auto) Back() requires (CBidirectionalRange< T> && CCommonRange< T>) { return *Range::RBegin(static_cast< T&>(*this)); }
|
NODISCARD FORCEINLINE constexpr decltype(auto) Back() requires (CBidirectionalRange< T> && CCommonRange< T>) { return *Range::RBegin(static_cast< T&>(*this)); }
|
||||||
NODISCARD FORCEINLINE constexpr decltype(auto) Back() const requires (CBidirectionalRange<const T> && CCommonRange<const T>) { return *Range::RBegin(static_cast<const T&>(*this)); }
|
NODISCARD FORCEINLINE constexpr decltype(auto) Back() const requires (CBidirectionalRange<const T> && CCommonRange<const T>) { return *Range::RBegin(static_cast<const T&>(*this)); }
|
||||||
|
|
||||||
ENABLE_RANGE_BASED_FOR_LOOP_SUPPORT
|
// ~Begin ENABLE_RANGE_BASED_FOR_LOOP_SUPPORT.
|
||||||
|
|
||||||
|
NODISCARD FORCEINLINE constexpr auto begin() requires (CRange< T>) { return Range::Begin(static_cast< T&>(*this)); }
|
||||||
|
NODISCARD FORCEINLINE constexpr auto end() requires (CRange< T>) { return Range::End (static_cast< T&>(*this)); }
|
||||||
|
NODISCARD FORCEINLINE constexpr auto begin() const requires (CRange<const T>) { return Range::Begin(static_cast<const T&>(*this)); }
|
||||||
|
NODISCARD FORCEINLINE constexpr auto end() const requires (CRange<const T>) { return Range::End (static_cast<const T&>(*this)); }
|
||||||
|
|
||||||
|
// ~End ENABLE_RANGE_BASED_FOR_LOOP_SUPPORT.
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -1,17 +1,24 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CoreTypes.h"
|
#include "CoreTypes.h"
|
||||||
#include "Range/Range.h"
|
|
||||||
#include "String/Char.h"
|
|
||||||
#include "Containers/Array.h"
|
|
||||||
#include "String/StringView.h"
|
|
||||||
#include "Iterator/Iterator.h"
|
|
||||||
#include "Templates/Utility.h"
|
|
||||||
#include "Templates/Optional.h"
|
|
||||||
#include "TypeTraits/TypeTraits.h"
|
#include "TypeTraits/TypeTraits.h"
|
||||||
#include "Templates/Noncopyable.h"
|
#include "Templates/Utility.h"
|
||||||
|
#include "Templates/TypeHash.h"
|
||||||
|
#include "Templates/Optional.h"
|
||||||
|
#include "Memory/Allocator.h"
|
||||||
|
#include "Containers/Array.h"
|
||||||
|
#include "Containers/ArrayView.h"
|
||||||
|
#include "Iterator/Utility.h"
|
||||||
|
#include "Iterator/BasicIterator.h"
|
||||||
|
#include "Iterator/Sentinel.h"
|
||||||
|
#include "Range/Utility.h"
|
||||||
|
#include "Range/Factory.h"
|
||||||
|
#include "String/Char.h"
|
||||||
|
#include "String/StringView.h"
|
||||||
#include "Miscellaneous/AssertionMacros.h"
|
#include "Miscellaneous/AssertionMacros.h"
|
||||||
|
|
||||||
|
#include <locale>
|
||||||
|
|
||||||
NAMESPACE_REDCRAFT_BEGIN
|
NAMESPACE_REDCRAFT_BEGIN
|
||||||
NAMESPACE_MODULE_BEGIN(Redcraft)
|
NAMESPACE_MODULE_BEGIN(Redcraft)
|
||||||
NAMESPACE_MODULE_BEGIN(Utility)
|
NAMESPACE_MODULE_BEGIN(Utility)
|
||||||
|
@ -1,15 +1,17 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CoreTypes.h"
|
#include "CoreTypes.h"
|
||||||
#include "Range/Range.h"
|
#include "TypeTraits/TypeTraits.h"
|
||||||
#include "String/Char.h"
|
|
||||||
#include "Memory/Allocator.h"
|
|
||||||
#include "Iterator/Iterator.h"
|
|
||||||
#include "Templates/Utility.h"
|
#include "Templates/Utility.h"
|
||||||
#include "Templates/TypeHash.h"
|
#include "Templates/TypeHash.h"
|
||||||
#include "Containers/ArrayView.h"
|
#include "Templates/Noncopyable.h"
|
||||||
#include "TypeTraits/TypeTraits.h"
|
#include "Memory/Allocator.h"
|
||||||
#include "Memory/MemoryOperator.h"
|
#include "Memory/MemoryOperator.h"
|
||||||
|
#include "Containers/ArrayView.h"
|
||||||
|
#include "Iterator/Utility.h"
|
||||||
|
#include "Iterator/BasicIterator.h"
|
||||||
|
#include "Iterator/Sentinel.h"
|
||||||
|
#include "String/Char.h"
|
||||||
#include "Miscellaneous/AssertionMacros.h"
|
#include "Miscellaneous/AssertionMacros.h"
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
@ -85,7 +87,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
using FElementType = TRemoveCV<T>;
|
using FElementType = T;
|
||||||
|
|
||||||
using FReference = typename FSuper::FReference;
|
using FReference = typename FSuper::FReference;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user