vendredi 27 mars 2015

Erase specific elements in std::vector

I am trying to understand how to implement lambda function for erasing specific elements in a vector. I have a std::vector newLabel whose certain elements I am trying to erase given that those indices of std::vector isPlaneArray are 0. The code is given below. The code throws an exception (3) saying vector subscripts out of range.



std::vector<int> newLabel(length); // declaration of label vector
std::vector<int> isPlaneArray(length); // declaration of vector which stores plane flag (if plane store 1, else store 0)
// store label vector
// store planar flag vector
// this step throws an exception
newLabel.erase(std::remove_if(newLabel.begin(),newLabel.end(),[&isPlaneArray](size_t i) {return (bool)isPlaneArray[i];}),newLabel.end());

Aucun commentaire:

Enregistrer un commentaire