refactor(*): replace the old with the new iterator and range library
This commit is contained in:
@ -12,6 +12,20 @@ NAMESPACE_REDCRAFT_BEGIN
|
||||
NAMESPACE_MODULE_BEGIN(Redcraft)
|
||||
NAMESPACE_MODULE_BEGIN(Utility)
|
||||
|
||||
// NOTE: In the STL, use std::from_range_t as a disambiguation tag that resolves ambiguity
|
||||
// introduced by the list-initialization. For example, for the following code:
|
||||
//
|
||||
// R RangeOfInts = /* ... */;
|
||||
// static_assert(CRange<R> and CSameAs<TRangeElement<R>, int>);
|
||||
//
|
||||
// TArray Arr(RangeOfInts);
|
||||
// TArray Brr{RangeOfInts};
|
||||
//
|
||||
// If R is TArray<int> than decltype(Arr) is TArray<int> and decltype(Brr) is TArray<int>,
|
||||
// otherwise, decltype(Arr) is TArray<int> and decltype(Brr) is TArray<R>.
|
||||
//
|
||||
// But Redcraft can't use the std::from_range_t tag because list-initialization is discouraged.
|
||||
|
||||
/** A concept specifies a container that can reserve size. */
|
||||
template <typename C>
|
||||
concept CReservableContainer = CSizedRange<C>
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "Range/AllView.h"
|
||||
#include "Memory/Address.h"
|
||||
#include "Templates/Invoke.h"
|
||||
#include "Iterator/Iterator.h"
|
||||
#include "Templates/Utility.h"
|
||||
#include "TypeTraits/TypeTraits.h"
|
||||
|
||||
@ -79,7 +80,7 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
using FElementType = TIteratorElementType<TRangeIterator<V>>;
|
||||
using FElementType = TIteratorElement<TRangeIterator<V>>;
|
||||
|
||||
FORCEINLINE constexpr FIteratorImpl() requires (CDefaultConstructible<TRangeIterator<V>>) { } // Use '{ }' instead of '= default;' to avoid MSVC bug.
|
||||
|
||||
|
@ -37,7 +37,7 @@ NODISCARD FORCEINLINE constexpr auto Begin(T&& Container)
|
||||
|
||||
/** Overloads the Begin algorithm for initializer_list. */
|
||||
template <typename T>
|
||||
NODISCARD FORCEINLINE constexpr auto Begin(initializer_list<T>& Container)
|
||||
NODISCARD FORCEINLINE constexpr const T* Begin(initializer_list<T>& Container)
|
||||
{
|
||||
return Container.begin();
|
||||
}
|
||||
@ -67,7 +67,7 @@ NODISCARD FORCEINLINE constexpr auto End(T&& Container)
|
||||
|
||||
/** Overloads the End algorithm for initializer_list. */
|
||||
template <typename T>
|
||||
NODISCARD FORCEINLINE constexpr auto End(initializer_list<T>& Container)
|
||||
NODISCARD FORCEINLINE constexpr const T* End(initializer_list<T>& Container)
|
||||
{
|
||||
return Container.end();
|
||||
}
|
||||
@ -180,6 +180,13 @@ NODISCARD FORCEINLINE constexpr size_t Num(T&& Container)
|
||||
return Range::End(Forward<T>(Container)) - Range::Begin(Forward<T>(Container));
|
||||
}
|
||||
|
||||
/** Overloads the Num algorithm for initializer_list. */
|
||||
template <typename T>
|
||||
NODISCARD FORCEINLINE constexpr size_t Num(initializer_list<T>& Container)
|
||||
{
|
||||
return Container.size();
|
||||
}
|
||||
|
||||
/** @return true if the container is empty, false otherwise. */
|
||||
template <typename T> requires (requires(T&& Container) { { Container.IsEmpty() } -> CBooleanTestable; })
|
||||
NODISCARD FORCEINLINE constexpr bool IsEmpty(T&& Container)
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include "CoreTypes.h"
|
||||
#include "Range/Utility.h"
|
||||
#include "Iterator/Iterator.h"
|
||||
#include "Templates/Utility.h"
|
||||
#include "TypeTraits/TypeTraits.h"
|
||||
|
||||
@ -100,7 +101,7 @@ class TRangeView : public IBasicViewInterface<TRangeView<I, S>>
|
||||
{
|
||||
public:
|
||||
|
||||
using FElementType = TIteratorElementType<I>;
|
||||
using FElementType = TIteratorElement<I>;
|
||||
|
||||
FORCEINLINE constexpr TRangeView() requires (CDefaultConstructible<I>) = default;
|
||||
|
||||
|
Reference in New Issue
Block a user