vendredi 10 mars 2017

remove_if from a std::vector of shared pointers with a member function

How can I delete the elements of a std::vector<std::shared_ptr<PTile>> ptiles fullfilling the condition ptile->hasNoRegions()? I've been trying to use remove_if for this, but the Predicate uses a data member of the object, not the pointer. How do I set the predicate to the function if the elements are smart pointers to the object?

What I have at the moment

    ptiles.erase(std::remove_if(ptiles.begin(), ptiles.end(), &PTile::hasNoRegions), ptiles.end());

where hasNoRegions is a member function of PTile. Which obviously doesn't work since I have a std::shared_ptr<PTile>, not a PTile.

I'm using MSVC 2012.

Aucun commentaire:

Enregistrer un commentaire