Should I create a member variable in an object that allows me to say that I want to remove myobj, and then create a predicate that checks if a member variable has been set?
Have you not done this already? Isn't that what m_bMarkedDelete ? You should write a predicate as follows:
bool IsMarkedToDelete(const myobj & o) { return o.m_bMarkedDelete; }
Then:
myList.erase( std::remove_if(myList.begin(), myList.end(), IsMarkedToDelete), myList.end());
Or using lambdas:
myList.erase( std::remove_if(myList.begin(), myList.end(), [](const myobj & o) { return o.m_bMarkedDelete; }), myList.end());
If your class does not actually have this member, and you ask us if that is the case, then I would say no. What criteria did you use to decide whether to mark it for deletion? Use the same criteria in your predicate, for example:
bool IndexGreaterThanTen(const myobj & o) { return o.index > 10; }
note - The functions that I wrote are, of course, not valid, since all your members are private. So you need access to them.
Benjamin Lindley Oct 31 '11 at 19:08 2011-10-31 19:08
source share