diff --git a/Redcraft.Utility/Source/Private/Testing/TemplatesTesting.cpp b/Redcraft.Utility/Source/Private/Testing/TemplatesTesting.cpp index bf14baf..8ec28a6 100644 --- a/Redcraft.Utility/Source/Private/Testing/TemplatesTesting.cpp +++ b/Redcraft.Utility/Source/Private/Testing/TemplatesTesting.cpp @@ -9,6 +9,7 @@ NAMESPACE_MODULE_BEGIN(Utility) void TestTemplates() { TestInvoke(); + TestMiscellaneous(); } NAMESPACE_UNNAMED_BEGIN @@ -44,6 +45,41 @@ void TestInvoke() always_check(TempE == 123); } +NAMESPACE_UNNAMED_BEGIN + +template +struct TTestStructA +{ + T* Pad; + T* Data; + + TTestStructA(T* InData) : Pad(nullptr), Data(InData) { } + ~TTestStructA() { delete Data; } + T** operator&() { return &Data; } +}; + +template +int32 TestFunctionB(TTestStructA* Ptr) +{ + return 0; +} + +template +int32 TestFunctionB(T** Ptr) +{ + return 1; +} + +NAMESPACE_UNNAMED_END + +void TestMiscellaneous() +{ + TTestStructA ObjectA(new int32(3)); + always_check(TestFunctionB(&ObjectA) == 1); + always_check(TestFunctionB(AddressOf(ObjectA)) == 0); + always_check(AddressOf(TestMiscellaneous) == &TestMiscellaneous); +} + NAMESPACE_MODULE_END(Utility) NAMESPACE_MODULE_END(Redcraft) NAMESPACE_REDCRAFT_END diff --git a/Redcraft.Utility/Source/Public/Templates/Utility.h b/Redcraft.Utility/Source/Public/Templates/Utility.h index 24234a7..b596782 100644 --- a/Redcraft.Utility/Source/Public/Templates/Utility.h +++ b/Redcraft.Utility/Source/Public/Templates/Utility.h @@ -82,6 +82,18 @@ constexpr T Exchange(T& A, U&& B) template T&& DeclVal(); +template requires TIsObject::Value +constexpr T* AddressOf(T& Object) +{ + return reinterpret_cast(&const_cast(reinterpret_cast(Object))); +} + +template requires !TIsObject::Value +constexpr T* AddressOf(T& Object) +{ + return &Object; +} + NAMESPACE_MODULE_END(Utility) NAMESPACE_MODULE_END(Redcraft) NAMESPACE_REDCRAFT_END diff --git a/Redcraft.Utility/Source/Public/Testing/TemplatesTesting.h b/Redcraft.Utility/Source/Public/Testing/TemplatesTesting.h index 025f903..6c0963b 100644 --- a/Redcraft.Utility/Source/Public/Testing/TemplatesTesting.h +++ b/Redcraft.Utility/Source/Public/Testing/TemplatesTesting.h @@ -8,6 +8,7 @@ NAMESPACE_MODULE_BEGIN(Utility) void REDCRAFTUTILITY_API TestTemplates(); void REDCRAFTUTILITY_API TestInvoke(); +void REDCRAFTUTILITY_API TestMiscellaneous(); NAMESPACE_MODULE_END(Utility) NAMESPACE_MODULE_END(Redcraft)