Compare commits

...

2 Commits

6 changed files with 97 additions and 1 deletions

View File

@ -2297,6 +2297,29 @@ void TestMiscTemplates()
always_check(TestFunctionB(&ObjectA) == 1);
always_check(TestFunctionB(AddressOf(ObjectA)) == 0);
always_check(AddressOf(TestMiscTemplates) == &TestMiscTemplates);
always_check(!TPointerTraits<int64>::bIsPointer);
always_check(TPointerTraits<int64*>::bIsPointer);
always_check((CSameAs<TPointerTraits<int64*>::PointerType, int64*>));
always_check((CSameAs<TPointerTraits<int64*>::ElementType, int64>));
always_check(TPointerTraits<int64*>::ToAddress(nullptr) == nullptr);
always_check(TPointerTraits<int64(*)[]>::bIsPointer);
always_check((CSameAs<TPointerTraits<int64(*)[]>::PointerType, int64(*)[]>));
always_check((CSameAs<TPointerTraits<int64(*)[]>::ElementType, int64>));
always_check(TPointerTraits<int64*>::ToAddress(nullptr) == nullptr);
always_check(TPointerTraits<TSharedPtr<int64>>::bIsPointer);
always_check((CSameAs<TPointerTraits<TSharedPtr<int64>>::PointerType, TSharedPtr<int64>>));
always_check((CSameAs<TPointerTraits<TSharedPtr<int64>>::ElementType, int64>));
always_check(TPointerTraits<TSharedPtr<int64>>::ToAddress(nullptr) == nullptr);
always_check(TPointerTraits<TSharedPtr<int64[]>>::bIsPointer);
always_check((CSameAs<TPointerTraits<TSharedPtr<int64[]>>::PointerType, TSharedPtr<int64[]>>));
always_check((CSameAs<TPointerTraits<TSharedPtr<int64[]>>::ElementType, int64>));
always_check(TPointerTraits<TSharedPtr<int64[]>>::ToAddress(nullptr) == nullptr);
}
NAMESPACE_END(Testing)

View File

@ -299,7 +299,7 @@ NAMESPACE_REDCRAFT_END
// The global overload operators new/delete do not cross .dll boundaries, and the macros should be placed in the .cpp of each module.
#define REPLACEMENT_OPERATOR_NEW_AND_DELETE \
NODISCARD void* operator new(std::size_t Count) { return NAMESPACE_REDCRAFT::Memory::Malloc(Count); } \
NODISCARD void* operator new(std::size_t Count) { return NAMESPACE_REDCRAFT::Memory::Malloc(Count, __STDCPP_DEFAULT_NEW_ALIGNMENT__); } \
NODISCARD void* operator new(std::size_t Count, std::align_val_t Alignment) { return NAMESPACE_REDCRAFT::Memory::Malloc(Count, static_cast<NAMESPACE_REDCRAFT::size_t>(Alignment)); } \
void operator delete(void* Ptr) noexcept { NAMESPACE_REDCRAFT::Memory::Free(Ptr); } \
void operator delete(void* Ptr, std::align_val_t Alignment) noexcept { NAMESPACE_REDCRAFT::Memory::Free(Ptr); }

View File

@ -0,0 +1,64 @@
#pragma once
#include "CoreTypes.h"
NAMESPACE_REDCRAFT_BEGIN
NAMESPACE_MODULE_BEGIN(Redcraft)
NAMESPACE_MODULE_BEGIN(Utility)
/** The class template provides the standardized way to access certain properties of pointer-like types. */
template <typename T>
struct TPointerTraits
{
static constexpr bool bIsPointer = false;
};
/** A specialization of TPointerTraits is provided for pointer types T*. */
template <typename T>
struct TPointerTraits<T*>
{
static constexpr bool bIsPointer = true;
using PointerType = T*;
using ElementType = T;
static FORCEINLINE constexpr ElementType* ToAddress(PointerType InPtr)
{
return InPtr;
}
};
/** A specialization of TPointerTraits is provided for array pointer types T(*)[]. */
template <typename T>
struct TPointerTraits<T(*)[]>
{
static constexpr bool bIsPointer = true;
using PointerType = T(*)[];
using ElementType = T;
static FORCEINLINE constexpr ElementType* ToAddress(PointerType InPtr)
{
return InPtr;
}
};
/** A specialization of TPointerTraits is provided for pointer-like type. */
#define DEFINE_TPointerTraits(TPtr) \
template <typename T> \
struct TPointerTraits<TPtr<T>> \
{ \
static constexpr bool bIsPointer = true; \
\
using PointerType = TPtr<T>; \
using ElementType = TPtr<T>::ElementType; \
\
static FORCEINLINE constexpr ElementType* ToAddress(const PointerType& InPtr) \
{ \
return InPtr.Get(); \
} \
};
NAMESPACE_MODULE_END(Utility)
NAMESPACE_MODULE_END(Redcraft)
NAMESPACE_REDCRAFT_END

View File

@ -8,6 +8,7 @@
#include "Memory/MemoryOperator.h"
#include "Templates/Noncopyable.h"
#include "TypeTraits/PrimaryType.h"
#include "Templates/PointerTraits.h"
#include "Templates/UniquePointer.h"
#include "TypeTraits/Miscellaneous.h"
#include "TypeTraits/TypeProperties.h"
@ -1896,6 +1897,9 @@ NODISCARD FORCEINLINE TSharedPtr<T> ReinterpretCast(TSharedPtr<U>&& InValue)
return TSharedPtr<T>(MoveTemp(InValue), reinterpret_cast<T*>(InValue.Get()));
}
DEFINE_TPointerTraits(TSharedRef);
DEFINE_TPointerTraits(TSharedPtr);
NAMESPACE_MODULE_END(Utility)
NAMESPACE_MODULE_END(Redcraft)
NAMESPACE_REDCRAFT_END

View File

@ -15,5 +15,6 @@
#include "Templates/Function.h"
#include "Templates/Atomic.h"
#include "Templates/ScopeHelper.h"
#include "Templates/PointerTraits.h"
#include "Templates/UniquePointer.h"
#include "Templates/SharedPointer.h"

View File

@ -5,6 +5,7 @@
#include "Templates/Utility.h"
#include "Templates/Noncopyable.h"
#include "TypeTraits/PrimaryType.h"
#include "Templates/PointerTraits.h"
#include "TypeTraits/Miscellaneous.h"
#include "TypeTraits/TypeProperties.h"
#include "TypeTraits/SupportedOperations.h"
@ -682,6 +683,9 @@ void MakeUnique(Ts&&...) = delete;
static_assert(sizeof(TUniqueRef<int32>) == sizeof(int32*), "The byte size of TUniqueRef is unexpected");
static_assert(sizeof(TUniquePtr<int32>) == sizeof(int32*), "The byte size of TUniquePtr is unexpected");
DEFINE_TPointerTraits(TUniqueRef);
DEFINE_TPointerTraits(TUniquePtr);
NAMESPACE_MODULE_END(Utility)
NAMESPACE_MODULE_END(Redcraft)
NAMESPACE_REDCRAFT_END