diff --git a/Redcraft.Utility/Source/Public/Containers/Array.h b/Redcraft.Utility/Source/Public/Containers/Array.h index e38b86a..5cda68a 100644 --- a/Redcraft.Utility/Source/Public/Containers/Array.h +++ b/Redcraft.Utility/Source/Public/Containers/Array.h @@ -176,7 +176,7 @@ private: NAMESPACE_PRIVATE_END /** Dynamic array. The elements are stored contiguously, which means that elements can be accessed not only through iterators, but also using offsets to regular pointers to elements. */ -template requires (!CConst && CDestructible && CInstantiableAllocator) +template requires (!CConst && CDestructible && CInstantiableAllocator) class TArray final { public: @@ -412,20 +412,20 @@ public: Storage.GetMax() = NumToAllocate; Storage.GetPointer() = Storage.GetAllocator().Allocate(Max()); - Memory::CopyConstruct(Storage.GetPointer(), NAMESPACE_REDCRAFT::GetData(IL), Num()); + Memory::CopyConstruct(Storage.GetPointer(), NAMESPACE_REDCRAFT::GetData(IL).Get(), Num()); return *this; } if (GetNum(IL) <= Num()) { - Memory::CopyAssign(Storage.GetPointer(), NAMESPACE_REDCRAFT::GetData(IL), GetNum(IL)); + Memory::CopyAssign(Storage.GetPointer(), NAMESPACE_REDCRAFT::GetData(IL).Get(), GetNum(IL)); Memory::Destruct(Storage.GetPointer() + GetNum(IL), Num() - GetNum(IL)); } else if (GetNum(IL) <= Max()) { - Memory::CopyAssign(Storage.GetPointer(), NAMESPACE_REDCRAFT::GetData(IL), Num()); - Memory::CopyConstruct(Storage.GetPointer() + Num(), NAMESPACE_REDCRAFT::GetData(IL) + Num(), GetNum(IL) - Num()); + Memory::CopyAssign(Storage.GetPointer(), NAMESPACE_REDCRAFT::GetData(IL).Get(), Num()); + Memory::CopyConstruct(Storage.GetPointer() + Num(), NAMESPACE_REDCRAFT::GetData(IL).Get() + Num(), GetNum(IL) - Num()); } else check_no_entry(); @@ -1208,6 +1208,12 @@ private: }; +template +TArray(I, S) -> TArray>; + +template +TArray(initializer_list) -> TArray; + NAMESPACE_MODULE_END(Utility) NAMESPACE_MODULE_END(Redcraft) NAMESPACE_REDCRAFT_END diff --git a/Redcraft.Utility/Source/Public/Memory/ObserverPointer.h b/Redcraft.Utility/Source/Public/Memory/ObserverPointer.h index e2b8088..a1e0b35 100644 --- a/Redcraft.Utility/Source/Public/Memory/ObserverPointer.h +++ b/Redcraft.Utility/Source/Public/Memory/ObserverPointer.h @@ -68,8 +68,7 @@ public: NODISCARD FORCEINLINE constexpr T& operator*() const { checkf(IsValid(), TEXT("Read access violation. Please check IsValid().")); return *Get(); } NODISCARD FORCEINLINE constexpr T* operator->() const { checkf(IsValid(), TEXT("Read access violation. Please check IsValid().")); return Get(); } - NODISCARD FORCEINLINE constexpr operator ElementType*() { return Get(); } - NODISCARD FORCEINLINE constexpr operator const ElementType*() const { return Get(); } + NODISCARD FORCEINLINE constexpr explicit operator ElementType*() const { return Get(); } NODISCARD friend FORCEINLINE constexpr size_t GetTypeHash(const TObserverPtr& A) { return GetTypeHash(A.Get()); } @@ -131,8 +130,7 @@ public: NODISCARD FORCEINLINE constexpr T& operator[](size_t Index) const { checkf(IsValid(), TEXT("Read access violation. Please check IsValid().")); return Get()[Index]; } - NODISCARD FORCEINLINE constexpr operator ElementType*() { return Get(); } - NODISCARD FORCEINLINE constexpr operator const ElementType*() const { return Get(); } + NODISCARD FORCEINLINE constexpr explicit operator ElementType*() const { return Get(); } NODISCARD friend FORCEINLINE constexpr size_t GetTypeHash(const TObserverPtr& A) { return GetTypeHash(A.Get()); } diff --git a/Redcraft.Utility/Source/Public/Templates/Container.h b/Redcraft.Utility/Source/Public/Templates/Container.h index 85b2393..a34a70d 100644 --- a/Redcraft.Utility/Source/Public/Templates/Container.h +++ b/Redcraft.Utility/Source/Public/Templates/Container.h @@ -3,36 +3,30 @@ #include "CoreTypes.h" #include "Templates/TypeHash.h" #include "TypeTraits/Swappable.h" +#include "Memory/ObserverPointer.h" NAMESPACE_REDCRAFT_BEGIN NAMESPACE_MODULE_BEGIN(Redcraft) NAMESPACE_MODULE_BEGIN(Utility) /** @return The pointer to the container element storage. */ -template requires (requires(T&& Container) { { Container.GetData() } -> CPointer; }) +template requires (requires(T&& Container) { { Container.GetData() } -> CTObserverPtr; }) FORCEINLINE constexpr decltype(auto) GetData(T&& Container) { return Container.GetData(); } /** Overloads the GetData algorithm for arrays. */ -template FORCEINLINE constexpr T* GetData( T(& Container)[N]) { return Container; } -template FORCEINLINE constexpr T* GetData( T(&& Container)[N]) { return Container; } -template FORCEINLINE constexpr const T* GetData(const T(& Container)[N]) { return Container; } -template FORCEINLINE constexpr const T* GetData(const T(&& Container)[N]) { return Container; } - -/** Overloads the GetData algorithm for T::data(). */ -template requires (requires(T&& Container) { { Container.data() } -> CPointer; }) -FORCEINLINE constexpr decltype(auto) GetData(T&& Container) -{ - return Container.data(); -} +template FORCEINLINE constexpr TObserverPtr< T[]> GetData( T(& Container)[N]) { return TObserverPtr< T[]>(Container); } +template FORCEINLINE constexpr TObserverPtr< T[]> GetData( T(&& Container)[N]) { return TObserverPtr< T[]>(Container); } +template FORCEINLINE constexpr TObserverPtr GetData(const T(& Container)[N]) { return TObserverPtr(Container); } +template FORCEINLINE constexpr TObserverPtr GetData(const T(&& Container)[N]) { return TObserverPtr(Container); } /** Overloads the GetData algorithm for initializer_list. */ template -FORCEINLINE constexpr const T* GetData(initializer_list Container) +FORCEINLINE constexpr TObserverPtr GetData(initializer_list Container) { - return Container.begin(); + return TObserverPtr(Container.begin()); } /** @return The number of elements in the container. */ @@ -48,13 +42,6 @@ template FORCEINLINE constexpr size_t GetNum( T(&& C template FORCEINLINE constexpr size_t GetNum(const T(& Container)[N]) { return N; } template FORCEINLINE constexpr size_t GetNum(const T(&& Container)[N]) { return N; } -/** Overloads the GetNum algorithm for T::size(). */ -template requires (requires(T&& Container) { { Container.size() } -> CConvertibleTo; }) -FORCEINLINE constexpr decltype(auto) GetNum(T&& Container) -{ - return Container.size(); -} - /** Overloads the GetNum algorithm for initializer_list. */ template FORCEINLINE constexpr size_t GetNum(initializer_list Container)