|
From: TSalm <TS...@fr...> - 2009-09-10 20:26:35
|
Роман Донченко a écrit :
> TSalm <TS...@fr...> писал(а) в своём письме Thu, 10
> Sep 2009 01:29:23 +0400:
>
>
>>> TSalm,
>>>
>>> This is a much general C++ question rather than that about MinGW. I
>>> think the newsgroup comp.lang.c++ would be better.
>>>
>>> It is not safe to delete an element of a map before using the iterator
>>> pointing to it. One of my methods may like this:
>>>
>>> for (map<string, string> it = myMap.begin(); it != myMap.end(); )
>>> {
>>> if (it->first == "2") // condition for deleting
>>> {
>>> map<string, string> toDel = it;
>>> it++;
>>> myMap.erase(toDel);
>>> }
>>> else
>>> {
>>> it++;
>>> }
>>> }
>>>
>> Thanks, this work perfectly !
>> And thanks too for your advice about comp.lang.c++.
>>
>
> Also of note is that in C++9x you will likely be able to delete by saying
> "it = myMap.erase(it)", as the definition of erase is amended to make it
> return an iterator to the next element. Until then, do the above.
>
>
Interesting. Is there a version of MingW featuring some C++0x
functionnalities ?
|