In general, the way to remove elements from a list based depending on a condition is to use the std::list::remove_if
member function.
bool pred(const Treenode* t) { .... }
currentNewLevel.remove_if(pred);
The predicate can be a functor, so it can keep any state that is required to implement the removal criteria:
#include <algorithm> // for std::find_if
#include <list>
// unary predicate functor. Returns true if an element of a reference
// list satisfies "something" and the functor call argument satisfies "somethingDifferent"
struct Pred
{
Pred(const std::list<Treenode*>& nodes) : nodes_(nodes) {}
bool (const Treenode* t) const
{
return std::find_if(nodes_.begin(), nodes_.end(), something) != nodes_.end() &&
somethingDifferent(t);
}
private:
const std::list<Treenode*>& nodes_;
};
then
Pred p(currentLevel);
currentLevel.remove_if(p);