mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-26 14:01:45 +00:00
add TArray::AppendFill for appending a single value multiple times
This commit is contained in:
parent
30e7b30c45
commit
5b85557ddb
1 changed files with 21 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue