-
-
Notifications
You must be signed in to change notification settings - Fork 147
support remove/erase idiom #18
Comments
This hashmap implementation can't support this use case unfortunately. |
I'm using the idiom you mentioned above. On that page, it says: In other words, I want to erase while iterating the container but never see the same element twice. Is this supported by unordered_flat_map? I'm getting the same element twice. |
Hi ed-lam, you shouldn't get the same elements twice. I actually have a test for that in auto it = map.begin();
while (it != map.end()) {
it = map.erase(it);
} |
Closing until I get a reproducer |
Here is a minimally working example. It appears the first element is seen again at the end if I delete some elements. This doesn't occur if you change it to std::unordered_map in the example. |
Thank you for your reproducer! You really stumbled uppon a bug. I could already narrow that bug down to a test case with just two elements. Working on a fix. |
Please see #42 |
I noticed when applying the remove/erase idiom that the following method is not implemented:
iterator erase ( const_iterator first, const_iterator last );
Reference: https://en.cppreference.com/w/cpp/container/unordered_map/erase
Example:
cache.erase( std::remove_if( cache.begin(), cache.end(), [&] ( const pair<int,int>& i ) { return i.second == 1 ); } ), cache.end() );
The text was updated successfully, but these errors were encountered: