|
Boost Users : |
Subject: Re: [Boost-users] Correct use of unordered_map
From: zap.foster (zap.foster_at_[hidden])
Date: 2009-08-31 19:04:34
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
>
>
> TradeStation Group, Inc. is a publicly-traded holding company (NASDAQ GS: TRAD) of three operating subsidiaries, TradeStation Securities, Inc. (Member NYSE, FINRA, SIPC and NFA), TradeStation Technologies, Inc., a trading software and subscription company, and TradeStation Europe Limited, a United Kingdom, FSA-authorized introducing brokerage firm. None of these companies provides trading or investment advice, recommendations or endorsements of any kind. The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited.
> If you received this in error, please contact the sender and delete the material from any computer.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net