Hi, I'm trying to delete from a vector all the elements that satisfy a specific property with the Erase-Remove idiom.
So I have a std::vector<MyType> myVector and in the header file I have a member function
1 2 3
bool HasToBeRemovedFromVector(MyType &v) {
return (/* Here I evaluate the condition */);
}
I actually never call it... I just pass it to the remove_if which should use it to evaluate whether the element has to be removed from the vector or not.
But probably you are right about the fact that it is not a member function. I put that code in the header file, within the definition of the class, but maybe this is not correct...
If this is just a function, just pass it to algorithm (without using deprecated entities which are going to be deleted from next language revision) myVector.erase(std::remove_if(myVector.begin(), myVector.end(), HasToBeRemovedFromVector), myVector.end());
Deprecated is defined by the IS as: Normative for the current edition of the Standard, but not guaranteed to be part of the Standard in future revisions.
As such, it sends a clear message to programmers: Do not use this feature anymore in any new code that you write. However if you already have legacy code that uses this feature, you have time to fix it: it will continue to work as it did before at least till the next revision of the standard. http://www.cplusplus.com/forum/general/62326/#msg337457
It is currently possible; and it will continue to be possible for another two years.
After which it will no longer be part of standard C++.
I know this is becoming more and more annoying but this does not work either.
It complains about the
use of deleted function ...
I am starting to think about giving up and creating a temporary vector in which to store all the objects that must be preserved. Then a swap and it's done.
Anyway I would have liked to understand this other method with the remove_if, but it is starting to seem unlikely...
Post your exact code. HasToBeRemovedFromVector , class it is in and where do you need it.
And show how you would use it other way. I still think that there is something about it or the way you are using it, which will require modifications to posted code.
I know it's weird but I can't post the exact code... The reason is that it is proprietary code (not mine, of course) and I do not have the authorization to release any part of it. I thought it was just something silly about the syntax, but it seems a bit more complicated. Nevermind: I will use a temporary vector and a swap.