I have a situation where I go through a vector doing things:
std :: vector :: iterator iter = my_list.begin ();
for (; iter! = my_list.end (); ++ iter)
{
if (iter-> doStuff ()) // returns true if successful, false o / w
{
// Keep going ...
}
else
{
for (; iter! = m_list.begin (); --iter) // ... This won't work ...
{
iter-> undoStuff ();
}
}
}
Under normal conditions - if everything goes well - I go through my_list.end()and successfully complete the cycle.
However, if something goes wrong when I do something, I want to be able to undo everything - basically, return my steps back to the very beginning of the vector, undoing everything one by one in the reverse order.
, my_list.begin() - - , undoStuff() . , .
, , , my_list.rend(). std::vector:: iterator std::vector:: reverse_iterator.
, , /?