boostorg / unordered

Boost.org unordered module
http://boost.org/libs/unordered
Boost Software License 1.0
62 stars 55 forks source link

unordered_map iterator stability after reserve #235

Closed GuyAv46 closed 6 months ago

GuyAv46 commented 6 months ago

I was trying to replace the standard unordered_map in my code with the boost implementation, but I ran into an instability that caused my test to crash.

I was able to find minimal reproduction steps. Notice that by replacing the boost::unordered_map with std::unordered_map at the start, the program succeeds.

I couldn't find any documentation about this, but I was under the impression that Boost's unordered map is a drop-in replacement for the std one.

cmazakas commented 6 months ago

All iterators are invalidated after calls to rehash() and reserve().

See the section here on cppreference: https://en.cppreference.com/w/cpp/container/unordered_map#Iterator_invalidation

GuyAv46 commented 6 months ago

Thanks!