1 Sep 2009 01:04
Re: Correct use of unordered_map
zap.foster <zap.foster <at> gmail.com>
2009-08-31 23:04:34 GMT
2009-08-31 23:04:34 GMT
I believe one solution would look something like:
const my_map_t::iterator end= my_map.end();
for (my_map_t::iterator it= my_map.begin(); it != end; )
{
if (is_to_be_removed(it->first))
it = global_map.erase (it);
else
++it;
}
-z
John Dlugosz wrote:
> Consider this loop:
>
> const my_map_t::iterator end= my_map.end();
> for (my_map_t::iterator it= my_map.begin(); it != end; ++it) {
> if (is_to_be_removed(it->first)) global_map.erase (it);
> }
>
> The documentation I've seen for unordered_map says that removing doesn't invalidate iterators except
those referring to the element being deleted. But that's the case for it itself! Also, what does removing
one element do to the ordering of the elements -- is there any guarantee that the iterator will visit
exactly the ones that were not visited before?
>
> What is the correct, standards-conforming, way to perform this?
>
> Thanks,
> --John
(Continue reading)
RSS Feed