std::list::erase(it)

deletes the element the iterator points to and returns an iterator that points to the element that comes AFTER the deleted one, so this “advancement of the iterator” needs to be taken care of in the loop

{
    bool advance = true;
    for(auto it = container.begin(); it != container.end(); advance ? it++ : it)
    {
        advance = true;
        doStuff();
        if(someCondition)
        {
            it = container.erase(it);
            advance = false;
        }
        doMoreStuff();
    }
}