CommonHelpers.h#
Includes#
vector
Included By#
Namespaces#
Functions#
Source Code#
#pragma once
#include <vector>
namespace pvrvk {
template<typename T>
static void setElementAtIndex(const uint32_t index, const T& newElement, std::vector<T>& elements)
{
size_t numElements = elements.size();
if (index > numElements)
{
elements.reserve(index + 1u); // so we don't do 2 dynamic allocations
elements.resize(index); // don't need to initialize elements[index], assumes you want default initializer
}
if (index >= numElements)
{ elements.emplace_back(newElement); }
else
{ elements[index] = newElement; }
}
} // namespace pvrvk