Try replacing the call to std::remove_if
with std::list::remove_if
. The latter should only copy some pointers from the preceding and succeeding elements, instead of trying to move the elements to the end of the list, which is the cause of the multiple allocations you're seeing. An additional benefit is that since it is a member function of std::list
, it actually removes (i.e. erases) the elements matching your criterion.
class MyClass
{
bool isDone(MyData& myData)
{
return myData.isDone();
}
void removeIfDone(std::list<MyData>& myList)
{
myList.remove_if( boost::bind( &MyClass::isDone, this, _1 ) );
}
};