S
Steve Edwards
Hi,
While iterating through a multimap, I need to replace elements that meet
certain conditions with a new element.
There doesm't seem to be a replace() function for multimaps, so I'm
inserting a new element, and then deleting the old.
typedef multimap<double, MyStructType, greater<double> >;MyMultimap
MyMultimap map = ...
MyMultimap::iterator iter;
for(iter = map.begin(); iter!= map.end())
{
if(...)
{
map.insert(MyMultimap::value_type(newKey, newData));
map.erase(iter++);
}
else
++iter;
}
The for loop never exits.
I'm guessing that the iterator is messed up after the insert, but can't
see how to correct it.
Is there a way around this, or even a more efficient way to replace
elements altogether?
Thanks
Steve
While iterating through a multimap, I need to replace elements that meet
certain conditions with a new element.
There doesm't seem to be a replace() function for multimaps, so I'm
inserting a new element, and then deleting the old.
typedef multimap<double, MyStructType, greater<double> >;MyMultimap
MyMultimap map = ...
MyMultimap::iterator iter;
for(iter = map.begin(); iter!= map.end())
{
if(...)
{
map.insert(MyMultimap::value_type(newKey, newData));
map.erase(iter++);
}
else
++iter;
}
The for loop never exits.
I'm guessing that the iterator is messed up after the insert, but can't
see how to correct it.
Is there a way around this, or even a more efficient way to replace
elements altogether?
Thanks
Steve