Algo::StableRemoveIf is a bit slow but it also maintains order.
for (FFitnessVrChartItemGroup& Group : ChartItemGroups)
{
if (const int32 Result = Algo::StableRemoveIf(Group.ChartItemsInGroup,
[&InExpiredItems](AFitnessVrChartItemBase* Comparator)
{
return InExpiredItems.Contains(Comparator);
})
)
{
Group.ChartItemsInGroup.SetNum(Result);
if (!bHaveAnyGroupsChanged)
{
bHaveAnyGroupsChanged = true;
}
}
}
StableRemoveIf returns a number of items that match the lambda and will be ‘removed’ by moving the non-matching items to the front of the array. If the result is more than 0, I set the number of elements in the array directly, cutting off the removed items.