• Create Account

### #ActualHodgman

Posted 17 November 2012 - 11:15 PM

Erase returns the a new iterator value; you should be using it instead of the dodgey "--" trick.
for (hordeIt zIt=horde.begin(); zIt !=horde.end(); /*N.B. nothing here*/)
{
if (...)
{
zIt = horde.erase(zIt);
}
else
{
++zIt;
}
}
2) Replacing STL data-structures with custom implementations that do the same thing isn't that helpful (especially when you replace them with buggy versions). Avoiding STL structures is more useful if you require another kind of structure altogether (e.g. something other than a doubly linked list, e.g. an enumerable pool of zombies, etc...).
3) You were lucky in the game of russian-roulette that is undefined-behaviour. In your code, --zIt is making use of an invalidated iterator. Depending on the STL implementation, this could do anything (including 'work as intended').

### #3Hodgman

Posted 17 November 2012 - 11:10 PM

Erase returns the a new iterator value; you should be using it instead of the dodgey "--" trick.
for (hordeIt zIt=horde.begin(); zIt !=horde.end(); /*N.B. nothing here*/)
{
if (...)
{
zIt = horde.erase(zIt);
}
else
{
++zIt;
}
}
2) Replacing STL data-structures with custom implementations that do the same thing isn't that helpful (especially when you replace them with buggy versions). Avoiding STL structures is more useful if you require another kind of structure altogether (e.g. something other than a doubly linked list).
3) You were lucky in the game of russian-roulette that is undefined-behaviour. In your code, --zIt is making use of an invalidated iterator. Depending on the STL implementation, this could do anything (including 'work as intended').

### #2Hodgman

Posted 17 November 2012 - 11:06 PM

Erase returns the a new iterator value; you should be using it instead of the dodgey "--" trick.
for (hordeIt zIt=horde.begin(); zIt !=horde.end(); /*N.B. nothing here*/)
{
if (...)
{
zIt = horde.erase(zIt);
}
else
{
++zIt;
}
}

### #1Hodgman

Posted 17 November 2012 - 11:06 PM

Erase returns the a new iterator value; you should be using it instead of the dodgey "--" trick.
for (hordeIt zIt=horde.begin(); zIt !=horde.end(); /*N.B. nothing here/)
{
if (...)
{
zIt = horde.erase(zIt);
}
else
{
++zIt;
}
}

PARTNERS