Converted the AZStd implementations of unintialized construct to use std (#2843)
* Converted the AZStd implementations of unintialized construct to use std The uninitialized_default_construct and uninitialized_value_construct functions implementations have been removed and the Standard library implementations have been brought into the AZStd namespace scope Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com> * Added a default construct to the UninitializedValueConstruct test case which value initializes the int member which uses zero initialization to initalize it to zero. Signed-off-by: lumberyard-employee-dm <56135373+lumberyard-employee-dm@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
44b053df58
commit
adaeb7c203
@@ -134,4 +134,48 @@ namespace UnitTest
|
||||
EXPECT_FLOAT_EQ(4.0f, resultAddress->m_floatValue);
|
||||
AZStd::destroy_at(resultAddress);
|
||||
}
|
||||
|
||||
TEST(CreateDestroy, UninitializedDefaultConstruct_IsAbleToConstructMultipleElements_Succeeds)
|
||||
{
|
||||
struct RefWrapper
|
||||
{
|
||||
RefWrapper()
|
||||
{}
|
||||
int m_intValue{ 2 };
|
||||
};
|
||||
constexpr size_t ArraySize = 2;
|
||||
AZStd::aligned_storage_for_t<RefWrapper> testArray[ArraySize];
|
||||
RefWrapper(&uninitializedAddress)[2] = reinterpret_cast<RefWrapper(&)[2]>(testArray);
|
||||
AZStd::uninitialized_default_construct(AZStd::begin(uninitializedAddress), AZStd::end(uninitializedAddress));
|
||||
|
||||
|
||||
EXPECT_EQ(2, uninitializedAddress[0].m_intValue);
|
||||
EXPECT_EQ(2, uninitializedAddress[1].m_intValue);
|
||||
// Reset uninitializedAddress to Debug pattern
|
||||
memset(uninitializedAddress, 0xCD, ArraySize * sizeof(RefWrapper));
|
||||
AZStd::uninitialized_default_construct_n(AZStd::data(uninitializedAddress), AZStd::size(uninitializedAddress));
|
||||
EXPECT_EQ(2, uninitializedAddress[0].m_intValue);
|
||||
EXPECT_EQ(2, uninitializedAddress[1].m_intValue);
|
||||
}
|
||||
|
||||
TEST(CreateDestroy, UninitializedValueConstruct_IsAbleToConstructMultipleElements_Succeeds)
|
||||
{
|
||||
struct RefWrapper
|
||||
{
|
||||
int m_intValue;
|
||||
};
|
||||
constexpr size_t ArraySize = 2;
|
||||
AZStd::aligned_storage_for_t<RefWrapper> testArray[ArraySize];
|
||||
RefWrapper(&uninitializedAddress)[2] = reinterpret_cast<RefWrapper(&)[2]>(testArray);
|
||||
AZStd::uninitialized_value_construct(AZStd::begin(uninitializedAddress), AZStd::end(uninitializedAddress));
|
||||
|
||||
|
||||
EXPECT_EQ(0, uninitializedAddress[0].m_intValue);
|
||||
EXPECT_EQ(0, uninitializedAddress[1].m_intValue);
|
||||
// Reset uninitializedAddress to Debug pattern
|
||||
memset(uninitializedAddress, 0xCD, ArraySize * sizeof(RefWrapper));
|
||||
AZStd::uninitialized_value_construct_n(AZStd::data(uninitializedAddress), AZStd::size(uninitializedAddress));
|
||||
EXPECT_EQ(0, uninitializedAddress[0].m_intValue);
|
||||
EXPECT_EQ(0, uninitializedAddress[1].m_intValue);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user