Erasing item in a for(-each) auto loop
Is there a way to erase specific elements when using a auto variable in a for loop like this? for(auto a: m_Connections) { if(something) { //Erase this element } } I know I can either do say for(auto it=m_map.begin() ... or for(map<int,int>::iterator it=m_map.begin() ... and manually increment the iterator (and erase) but if I could do it with less lines of code I'd be happier. Thanks! No, there isn't. Range based for loop is used to access each element of a container once. Every time an element is removed from the container, iterators at or after the erased element are no longer valid (and