can you deleting multple elements in vector in one iteration?

Jun 17, 2017 at 5:16pm
Is there a way to delete multiple elements by searching if the return value of a member function equals true.

1
2
  std::vector<std::unique_ptr<Entity>> enteties;
  bool isAlive() const { return alive; }
Jun 17, 2017 at 5:31pm
The erase-remove idiom:
1
2
std::entities.erase(std::remove_if(entities.begin(), entities.end(), 
           [](auto elt){ return elt->isAlive(); }), entities.end());
Last edited on Jun 21, 2017 at 7:00pm
Jun 21, 2017 at 3:22pm
1
2
entities.erase(std::remove_if(entities.begin(), entities.end(),
					[](auto elt) { return elt->isAlive(); }), entities.end());

i get compile errors.
Jun 21, 2017 at 4:22pm
i get compile errors
no way for anyone to know unless you state what these errors might be. anyways, here's ...
http://coliru.stacked-crooked.com/a/6635eac9c2318874
Topic archived. No new replies allowed.