I try to remove objects from a vector using vector::erase and std::remove_if. I have an external namespace which does the selection ala:
template<unsigned int value, someType collection>
bool Namespace::isValid(const Foo* object){
do something
}
Now I have a vector which contains some element which I want to filter if the are valid. In order to do so I do:
std::vector<foo*> myVector;
//fill it
myVector.erase( std::remove_if(myVector.begin(), myVector.end(), Namespace::isValid<myValue, myCollectionType>), myVector.end());
Now this works fine and removes all valid candidates, but actually I want to keep and remove all other. Hence, I need to negate the predicate. Is there any way to do so? Unfortunately, C++11 is not currently supported in this context.
Thanks
Use the
std::not1adapter to negate the value returned by yourisValidfunction. Note thatstd::not1expects a function object (C++ calls this a “functor”), so if you have a plain function in a name space you will also needstd::ptr_funto create a function object out of your function.So,
becomes