I know the code isn't good practice, so the question is not about that. I just want to understand how the following example works. Notice I don't do anything with the iterator when I call remove, so when the loop goes to the next iteration how is it pointing to the next element?
#include <string>
#include <list>
#include <algorithm>
#include <iostream>
class Obj;
std::list<Obj> objs;
class Obj
{
public:
  Obj(const std::string& name, int age)
  : name_(name), age_(age)
  {}
  std::string name()
  {
    return name_;
  }
  int age()
  {
    return age_;
  }
private:
  std::string name_;
  int age_;
};
void remove(const std::string& name)
{
  auto it = find_if(objs.begin(), objs.end(),[name] (Obj& o) { return (o.name() == name); });
  if (it != objs.end())
  {
    std::cout << "removing " << it->name() << std::endl;
    objs.erase(it);
  }
}
int main()
{
  objs.emplace_back("bob", 31);
  objs.emplace_back("alice", 30);
  objs.emplace_back("kevin", 25);
  objs.emplace_back("tom", 45);
  objs.emplace_back("bart", 37);
  objs.emplace_back("koen", 48);
  objs.emplace_back("jef", 23);
  objs.emplace_back("sara", 22);
  auto it = objs.rbegin();
  while (it != objs.rend())
  {
   std::cout << it->name() << std::endl;
   if (it->name() == "tom")
   {
      remove(it->name()); //notice I don't do anything to change the iterator
   }
   else
   {
     ++it;
   }
  }
  return 0;
}
Following is the output:
sara
jef
koen
bart
tom
removing tom
kevin
alice
bob
 
     
    