What is the most safe way to iteration remove TMap.

For maps you likely need to use the iterator as I’m not sure you can use “RemoveAt” for them. However, iterators have an aptly named “RemoveCurrent” method which will remove that key/value pair from the map.




TMap<FName, UObject*> MyMapOfStuff;
For(TMap<FName, UObject*>::Iterator ItRemove = MyMapOfStuff.CreateIterator(); ItRemove; ++ItRemove)
{
   // If I want to remove the current pair for whatever reason.
   ItRemove.RemoveCurrent();
}



5 Likes