mercredi 27 février 2019

How to remove elements of a vector with a predicate based on another vector

I have two vectors

std::vector<Mat> images;
std::vector<std::string> image_paths;

and would like to filter out the indices in both vectors where the image is empty. This can easily be done on a single vector:

std::remove_if(images.begin() images.end(), [](const Mat& img) { return img.empty(); });

But now I'd like to remove the very same indices on image_paths as well. This can of course be generalized to vectors of arbitrary types or arbitrary predicates. How can I do this most elegantly?

Aucun commentaire:

Enregistrer un commentaire