feat(templates): add AddressOf function and the corresponding testing

This commit is contained in:
2022-02-09 17:07:47 +08:00
parent 63fdd34789
commit 2bc852b63c
3 changed files with 49 additions and 0 deletions

View File

@ -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 <typename T>
struct TTestStructA
{
T* Pad;
T* Data;
TTestStructA(T* InData) : Pad(nullptr), Data(InData) { }
~TTestStructA() { delete Data; }
T** operator&() { return &Data; }
};
template <typename T>
int32 TestFunctionB(TTestStructA<T>* Ptr)
{
return 0;
}
template <typename T>
int32 TestFunctionB(T** Ptr)
{
return 1;
}
NAMESPACE_UNNAMED_END
void TestMiscellaneous()
{
TTestStructA<int32> 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