Re: Erase in a map
- From: "aao" <aao@xxxxxxxx>
- Date: Fri, 16 Mar 2007 12:43:53 -0500
for ( pos = connectionMap.begin(); pos != connectionMap.end(); ){
ConnectionInfo* conn = pos->second;
if ( current - conn->lastRequestTime > 60 * timeOut ) {
pos = connectionMap.erase(pos);
}
else
++pos;
}
"Charles Zhang" <CharlesZhang@xxxxxxxxxxxxxxxxx> wrote in message news:%23Rp6mF$ZHHA.3272@xxxxxxxxxxxxxxxxxxxxxxx
I want to erase items in a map based on some criteria. However, as soon
as the erase is called, iterator become invalid. I would like someone
to tell me the better way to do it.
Here is the source code I am using, and it is crashing.
for ( pos = connectionMap.begin(); pos != connectionMap.end(); ++pos){
ConnectionInfo* conn = pos->second;
if ( current - conn->lastRequestTime > 60 * timeOut ) {
connectionMap.erase(pos);
}
}
To overcome the problem, I start the loop from the beginning after a
item is removed. But this is too slow.
Thanks
Charles Zhang
- Follow-Ups:
- Re: Erase in a map
- From: Charles Zhang
- Re: Erase in a map
- References:
- Erase in a map
- From: Charles Zhang
- Erase in a map
- Prev by Date: Erase in a map
- Next by Date: Re: Erase in a map
- Previous by thread: Erase in a map
- Next by thread: Re: Erase in a map
- Index(es):
Relevant Pages
|
Loading