feat(templates): add CTUniquePtr and CTSharedPtr etc

This commit is contained in:
_Redstone_c_ 2023-01-12 22:06:10 +08:00
parent 10b8e0fc45
commit caabc51803
2 changed files with 46 additions and 2 deletions

View File

@ -31,6 +31,28 @@ class TWeakPtr;
NAMESPACE_PRIVATE_BEGIN
template <typename T> struct TIsTSharedRef : FFalse { };
template <typename T> struct TIsTSharedRef<TSharedRef<T>> : FTrue { };
template <typename T> struct TIsTSharedPtr : FFalse { };
template <typename T> struct TIsTSharedPtr<TSharedPtr<T>> : FTrue { };
template <typename T> struct TIsTWeakPtr : FFalse { };
template <typename T> struct TIsTWeakPtr<TWeakPtr<T>> : FTrue { };
NAMESPACE_PRIVATE_END
template <typename T>
concept CTSharedRef = NAMESPACE_PRIVATE::TIsTSharedRef<TRemoveCV<T>>::Value;
template <typename T>
concept CTSharedPtr = NAMESPACE_PRIVATE::TIsTSharedPtr<TRemoveCV<T>>::Value;
template <typename T>
concept CTWeakPtr = NAMESPACE_PRIVATE::TIsTWeakPtr<TRemoveCV<T>>::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
{

View File

@ -123,8 +123,30 @@ struct TDefaultDelete<T[]>
};
/** This is essentially a reference version of TUniquePtr. */
template <typename T, CInvocable<TRemoveExtent<T>*> E = TDefaultDelete<T>> requires (CObject<T> && !CBoundedArray<T> && (CDestructible<E> || CLValueReference<E>))
class TUniqueRef;
template <typename T, CInvocable<TRemoveExtent<T>*> E = TDefaultDelete<T>> requires (CObject<T> && !CBoundedArray<T> && (CDestructible<E> || CLValueReference<E>))
class TUniquePtr;
NAMESPACE_PRIVATE_BEGIN
template <typename T> struct TIsTUniqueRef : FFalse { };
template <typename T> struct TIsTUniqueRef<TUniqueRef<T>> : FTrue { };
template <typename T> struct TIsTUniquePtr : FFalse { };
template <typename T> struct TIsTUniquePtr<TUniquePtr<T>> : FTrue { };
NAMESPACE_PRIVATE_END
template <typename T>
concept CTUniqueRef = NAMESPACE_PRIVATE::TIsTUniqueRef<TRemoveCV<T>>::Value;
template <typename T>
concept CTUniquePtr = NAMESPACE_PRIVATE::TIsTUniquePtr<TRemoveCV<T>>::Value;
/** This is essentially a reference version of TUniquePtr. */
template <typename T, CInvocable<TRemoveExtent<T>*> E> requires (CObject<T> && !CBoundedArray<T> && (CDestructible<E> || CLValueReference<E>))
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 <typename T, CInvocable<TRemoveExtent<T>*> E = TDefaultDelete<T>> requires (CObject<T> && !CBoundedArray<T> && (CDestructible<E> || CLValueReference<E>))
template <typename T, CInvocable<TRemoveExtent<T>*> E> requires (CObject<T> && !CBoundedArray<T> && (CDestructible<E> || CLValueReference<E>))
class TUniquePtr final : private FNoncopyable
{
public: