add TArray::AppendFill for appending a single value multiple times

This commit is contained in:
Ricardo Luís Vaz Silva 2023-04-20 22:03:17 -03:00 committed by Rachael Alexanderson
parent 30e7b30c45
commit 5b85557ddb

View file

@ -54,6 +54,7 @@
#include <new>
#include <utility>
#include <iterator>
#include <algorithm>
#if !defined(_WIN32)
#include <inttypes.h> // for intptr_t
@ -420,6 +421,26 @@ public:
return start;
}
unsigned AppendFill(const T& val, unsigned append_count)
{
unsigned start = Count;
Grow(append_count);
Count += append_count;
if constexpr (std::is_trivially_copyable<T>::value)
{
std::fill(Array + start, Array + Count, val);
}
else
{
for (unsigned i = 0; i < append_count; i++)
{
new(&Array[start + i]) T(val);
}
}
return start;
}
bool Pop ()
{
if (Count > 0)