From caabc5180319d2f476b348210debca977dd82843 Mon Sep 17 00:00:00 2001 From: _Redstone_c_ Date: Thu, 12 Jan 2023 22:06:10 +0800 Subject: [PATCH] feat(templates): add CTUniquePtr and CTSharedPtr etc --- .../Source/Public/Templates/SharedPointer.h | 22 ++++++++++++++++ .../Source/Public/Templates/UniquePointer.h | 26 +++++++++++++++++-- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/Redcraft.Utility/Source/Public/Templates/SharedPointer.h b/Redcraft.Utility/Source/Public/Templates/SharedPointer.h index 167a507..94718bb 100644 --- a/Redcraft.Utility/Source/Public/Templates/SharedPointer.h +++ b/Redcraft.Utility/Source/Public/Templates/SharedPointer.h @@ -31,6 +31,28 @@ class TWeakPtr; NAMESPACE_PRIVATE_BEGIN +template struct TIsTSharedRef : FFalse { }; +template struct TIsTSharedRef> : FTrue { }; + +template struct TIsTSharedPtr : FFalse { }; +template struct TIsTSharedPtr> : FTrue { }; + +template struct TIsTWeakPtr : FFalse { }; +template struct TIsTWeakPtr> : FTrue { }; + +NAMESPACE_PRIVATE_END + +template +concept CTSharedRef = NAMESPACE_PRIVATE::TIsTSharedRef>::Value; + +template +concept CTSharedPtr = NAMESPACE_PRIVATE::TIsTSharedPtr>::Value; + +template +concept CTWeakPtr = NAMESPACE_PRIVATE::TIsTWeakPtr>::Value; + +NAMESPACE_PRIVATE_BEGIN + // This is the base object for TSharedPtr and uses constructive interference alignment for performance. class alignas(Memory::ConstructiveInterference) FSharedController : private FSingleton { diff --git a/Redcraft.Utility/Source/Public/Templates/UniquePointer.h b/Redcraft.Utility/Source/Public/Templates/UniquePointer.h index b35baae..1a0e5fd 100644 --- a/Redcraft.Utility/Source/Public/Templates/UniquePointer.h +++ b/Redcraft.Utility/Source/Public/Templates/UniquePointer.h @@ -123,8 +123,30 @@ struct TDefaultDelete }; -/** This is essentially a reference version of TUniquePtr. */ template *> E = TDefaultDelete> requires (CObject && !CBoundedArray && (CDestructible || CLValueReference)) +class TUniqueRef; + +template *> E = TDefaultDelete> requires (CObject && !CBoundedArray && (CDestructible || CLValueReference)) +class TUniquePtr; + +NAMESPACE_PRIVATE_BEGIN + +template struct TIsTUniqueRef : FFalse { }; +template struct TIsTUniqueRef> : FTrue { }; + +template struct TIsTUniquePtr : FFalse { }; +template struct TIsTUniquePtr> : FTrue { }; + +NAMESPACE_PRIVATE_END + +template +concept CTUniqueRef = NAMESPACE_PRIVATE::TIsTUniqueRef>::Value; + +template +concept CTUniquePtr = NAMESPACE_PRIVATE::TIsTUniquePtr>::Value; + +/** This is essentially a reference version of TUniquePtr. */ +template *> E> requires (CObject && !CBoundedArray && (CDestructible || CLValueReference)) class TUniqueRef final : private FSingleton { public: @@ -364,7 +386,7 @@ private: }; /** Single-ownership smart pointer. Use this when you need an object's lifetime to be strictly bound to the lifetime of a single smart pointer. */ -template *> E = TDefaultDelete> requires (CObject && !CBoundedArray && (CDestructible || CLValueReference)) +template *> E> requires (CObject && !CBoundedArray && (CDestructible || CLValueReference)) class TUniquePtr final : private FNoncopyable { public: