absl::flat_hash_map: efficient way to implement `remove_if`

813 Views Asked by At

Is there an efficient way to implement remove_if for absl::flat_hash_map?

It is my understanding that absl::flat_hash_map doesn't return the iterator to the next element, which is generally used for remove_if's implementation.

Does Abseil provide an alternative implementation for such operation?

Pretty much what I want is to iterate on the map and selectively remove items. I'm trying to avoid having a separate container to keep track of what to remove if at all possible.

1

There are 1 best solutions below

0
Sneftel On

remove_if reorders elements, and so is inapplicable to associative containers (it has nothing to do with Abseil’s implementation). Just use std::erase_if (or absl::erase_if).