What are you actually trying to remove? As the others have said, if you want to erase all but a given ID, then use the following:
int id = /* determine id */; myVec.erase(std::remove_if(myVec.begin(), myVec.end(), myInversePred(id)), myVec.end());
You can also use the std::not1 predicate to invert an existing predicate:#include <functional> int id = /* determine id */; myVec.erase(std::remove_if(myVec.begin(), myVec.end(), std::not1(myPred(id))), myVec.end());
I'm trying to use the std::not1 as suggested but I've troubles coding the predicate.
Here is the code:
std::vector<myStruct::myStructLib> myVector;
for (int f=0; f<tempValues.size(); f++)
{
int faceID=tempValues.at(f);
myVector.erase(std::remove_if(myVector.begin(), myVector.end(), std::not1(myPredicate(faceID))), myVector.end());
}
// predicate
struct myPredicate : std::unary_function<int,bool>{
bool operator()(const myStruct::myStructLib &obj) {
return obj.faceID==id;
}
int id;
};When I compile I get several errors:
error: no type named 'argument_type' in 'struct myPredicate'
error: no match for call to '(std::unary_negate<myPredicate>) (myStruct::myStructLib&)'