I\'ve got code that looks like this:
for (std::list- ::iterator i=items.begin();i!=items.end();i++)
{
bool isActive = (*i)->update();
/
Here's an example using a for
loop that iterates the list and increments or revalidates the iterator in the event of an item being removed during traversal of the list.
for(auto i = items.begin(); i != items.end();)
{
if(bool isActive = (*i)->update())
{
other_code_involving(*i);
++i;
}
else
{
i = items.erase(i);
}
}
items.remove_if(CheckItemNotActive);