P
Pete Becker
Howard said:Even if it *did* return an iterator, the above code would only work if it
So tell the person who posted it.
Howard said:Even if it *did* return an iterator, the above code would only work if it
Pete Becker said:So tell the person who posted it.
Jeff said:Assuming this thread is important to the OP, I just did.
Pete Becker said:Sigh. Okay. RESPOND TO THE PERSON WHO ORIGINALLY POSTED THE WORDS THAT
YOU THINK ARE INCORRECT. Is it really that hard to grasp?
Howard said:Why are you so upset??? So our responses fall under yours instead of
directly under joey's. So what?
He should be perfectly capable of seeing
the whole conversation, and the context of the responses. (Aren't you?)
It's not like we sent emails to you personally. We posted them to the
newsgroup, as follow-ups to your response. There's no sense in now going
back and posting *again*, directly to joey's post, just so he (and everyone
else) can read the same answer for the third time.
Howard said:Ok...but then, what if you were to pass the iterator *by reference* to some
function instead? What value would the function then get, (considering the
previously stated rule that the increment side-effect has to be completed
prior to the calling of the function)? Would a temporary (un-incremented)
copy be created, passed by reference, and then that copy destroyed after the
return of the function? (That seems to be the only way to maintain the
concept of post-increment without violating the side-effect rule.)
Pieter Thysebaert said:Hello,
I've got a question conerning erasing key-value pairs from a std::map while
iterating over it.
According to the STL docs, erasing an element in a map invalidates all
iterators pointing to that element
so
for (map<...>::iterator i = mymap.begin(); i != mymap.end(); i++) {
if (test(i)) {
mymap.erase(i);
mymap.insert(newelement);
}
}
looks like bad practice, and it does crash when it gets executed, at least
on one machine i've run such code on.
So my question is, how do I conveniently erase the "current" element in a
map on the fly while I'm iterating over it? (I admit that this sounds as
weird in English as it sounds in C++)?
Thanx,
Pieter
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.