Array alive/dead entity "refresh" algorithm
You could probably use std::remove_if instead of your algorithm. Take this example code:

std::vector&lt;std::string&gt; vec = { "0", "1", "5", "0", "3", "6", "0", "1" };
std::remove_if(std::begin(vec), std::end(vec), [](const std::string&amp; val)
{
    return val == "0";
});

for (auto&amp;&amp; a: vec)
{
    std::cout &lt;&lt; a &lt;&lt; ' ';
}


I get the following output:

1 5 3 6 1 0 0 0


std::remove_if swaps the elements of a range so that the elements that are to be kept are at the beginning of the range and maintains their order. The elements that are still at the end have unspecified values, but if Entity is an RAII class, the deinitialization will happen at destruction. Since I don't know what Entity looks like, I can't be sure that this method will work, but there is probaby a way to ensure that it will do what you need it to do.

This method has two advantages: it allows to think in term of iterators instead of sizes and it uses an already existing algorithm. In your case, refresh could probably look like this:

void refresh()
{
    std::remove_if(std::begin(entities), std::end(entities),
                   [](const Entity&amp; ent)
                   {
                       return ent.isDead();
                   });
}


Once again, I am assuming some implementation details that are not shown though. Anyway, try check whether std::remove_if coud be used to do what you want it to do. Standard algorithms can often do much more things than thought.