There is a potential improvement to std.algorithm.remove() for its SwapStrategy.unstable version:
static if (s != SwapStrategy.stable)
{
for (;!range.empty;)
{
if (!unaryFun!pred(range.front))
{
range.popFront();
continue;
}
move(range.back, range.front); // <-- *
range.popBack();
result.popBack();
}
}
The move on the marked line can be avoided if range.back does not satisfy the predicate. In other words, why move the element to front just to popFront it in the next iteration if it does not satisfy the predicate to begin with. :)
Ali
Comment #1 by robert.schadek — 2024-12-01T16:23:44Z