6#include "Templates/UnrealTemplate.h"
38
39
58 struct TPimplHeapObjectImpl;
80 using FDeleteFunc =
void(*)(
void*);
81 using FCopyFunc =
void*(*)(
void*);
84 struct TPimplHeapObjectImpl
89 template <
typename... ArgTypes>
91 : Val(Forward<ArgTypes>(Args)...)
94 static_assert(
STRUCT_OFFSET(TPimplHeapObjectImpl, Val) == RequiredAlignment,
95 "Unexpected alignment of T within the pimpl object");
98 template <
typename... ArgTypes>
100 : Copier(&CopyFunc<T>)
101 , Val(Forward<ArgTypes>(Args)...)
104 static_assert(
STRUCT_OFFSET(TPimplHeapObjectImpl, Val) == RequiredAlignment,
105 "Unexpected alignment of T within the pimpl object");
109 : Copier(&CopyFunc<T>)
118 alignas(RequiredAlignment) T
Val;
129 (*(
void(**)(
void*) )ThunkedPtr)(ThunkedPtr);
135 void* ThunkedPtr = (
char*)BasePtr +
sizeof(FDeleteFunc);
137 return (*(FCopyFunc*)ThunkedPtr)(Ptr);
298 using Super::IsValid;
299 using Super::operator
bool;
300 using Super::operator ->;
302 using Super::operator *;
312
313
314
315
316
317
321 using FHeapType = UE::Core::Private::PimplPtr::TPimplHeapObjectImpl<T>;
322 using FHeapConstructType =
typename std::conditional<Mode == EPimplPtrMode::NoCopy,
typename FHeapType::ENoCopyType,
323 typename FHeapType::EDeepCopyType>::type;
325 static_assert(Mode != EPimplPtrMode::DeepCopy ||
326 std::is_copy_constructible<T>::value,
"T must be a copyable type, to use with EPimplPtrMode::DeepCopy");
327 static_assert(
sizeof(T) > 0,
"T must be a complete type");
328 static_assert(
alignof(T) <= UE::Core::Private::PimplPtr::RequiredAlignment,
"T cannot be aligned more than 16 bytes");
330 return TPimplPtr<T, Mode>(
new FHeapType(FHeapConstructType::ConstructType, Forward<ArgTypes>(Args)...));
FORCEINLINE bool operator!=(TYPE_OF_NULLPTR, const TPimplPtr< T, Mode > &Ptr)
FORCEINLINE TPimplPtr< T, Mode > MakePimpl(ArgTypes &&... Args)
FORCEINLINE bool operator==(TYPE_OF_NULLPTR, const TPimplPtr< T, Mode > &Ptr)
#define STRUCT_OFFSET(struc, member)
constexpr SIZE_T RequiredAlignment
FORCEINLINE void * CallCopier(void *Ptr)
void DeleterFunc(void *Ptr)
static void * CopyFunc(void *A)
FORCEINLINE void CallDeleter(void *Ptr)
TPimplPtr(TPimplPtr &&)=default
TPimplPtr(const TPimplPtr &A)
TPimplPtr(TYPE_OF_NULLPTR)
FORCEINLINE TPimplPtr & operator=(TYPE_OF_NULLPTR A)
TPimplPtr & operator=(TPimplPtr &&)=default
TPimplPtr & operator=(const TPimplPtr &A)
friend TPimplPtr< U, M > MakePimpl(ArgTypes &&... Args)
FORCEINLINE bool operator==(TYPE_OF_NULLPTR)
TPimplPtr(const TPimplPtr &)=delete
TPimplPtr(UE::Core::Private::PimplPtr::TPimplHeapObjectImpl< T > *Impl)
TPimplPtr(TYPE_OF_NULLPTR)
TPimplPtr & operator=(TYPE_OF_NULLPTR)
TPimplPtr & operator=(TPimplPtr &&Other)
TPimplPtr & operator=(const TPimplPtr &)=delete
TPimplPtr(TPimplPtr &&Other)
FORCEINLINE bool operator!=(TYPE_OF_NULLPTR)
TPimplHeapObjectImpl(EDeepCopyType, ArgTypes &&... Args)
TPimplHeapObjectImpl(ENoCopyType, ArgTypes &&... Args)
TPimplHeapObjectImpl(void *InVal)