feat(templates): add TPropagateConst and the corresponding testing

This commit is contained in:
2023-01-20 21:02:28 +08:00
parent e498d9b0b8
commit 2ef2c4a729
4 changed files with 199 additions and 0 deletions

View File

@ -25,6 +25,7 @@ void TestTemplates()
TestFunction();
TestAtomic();
TestScopeHelper();
TestPropagateConst();
TestMiscTemplates();
}
@ -1469,6 +1470,46 @@ void TestScopeHelper()
}
void TestPropagateConst()
{
{
struct FTestA
{
void Check(bool bFlag) { check(!bFlag); }
void Check(bool bFlag) const { check(bFlag); }
};
struct FTestB
{
FTestB() { Ptr = &Object; }
FTestA Object;
TPropagateConst<FTestA*> Ptr;
};
FTestB TempA;
const FTestB TempB;
TempA.Ptr->Check(false);
TempB.Ptr->Check(true);
}
{
int64 IntA;
int64 IntB;
TPropagateConst<int64*> TempA;
TPropagateConst<int64*> TempB = &IntA;
TPropagateConst<int64*> TempC = &IntB;
TempA = TempB;
TempB = TempC;
check(TempA.IsValid());
check(TempA == &IntA);
check(TempB == TempC);
}
}
NAMESPACE_UNNAMED_BEGIN
template <typename T>