std::vector<int> items = {1, 2, 3, 4, 5};
std::vector<int> removeItems = {2, 4};
I need to delete the values in items
that are in removeItems
, while retaining the order of items
. Something like this:
items.remove(removeItems);
Output
items = {1, 3, 5}
Are there any built in vector methods that can achieve this? I haven't found any that accept another vector of items to remove. If not, whats the most efficient way of achieving this?
Edit
Erasing elements from a vector This post refers to removing one item at a time, I'm looking to delete a whole bunch at once in a more compact way then
for(num in removeItems) {
items.erase(std::remove(items.begin(), items.end(), num), items.end())
}
Because surely this way of removing items is very inefficient because you have to check the entire items
vector twice (removeItems.size()
) for each item in removeItems
Edit 2
Number of elements in items
or removeItems
will be in the range 0-10000