Last active
December 2, 2016 16:39
-
-
Save gregkepler/ceb6a6f6f017affd3a93eb678c0fa885 to your computer and use it in GitHub Desktop.
Iterate through C++ vector updating active objects and erasing ones marked for removal.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void update() | |
{ | |
// iterate through all objects in the vector | |
for( auto iter = mObjectVector.begin() ; iter != mObjectVector.end(); /*DO NOT INCREMENT HERE*/ ) | |
{ | |
if( (*iter)->isMarkedForRemoval() ){ | |
// Remove if obsolete and iter will be the following object in vector | |
iter = mObjectVector.erase( iter ); | |
} else { | |
// Update if still active | |
(*iter)->update(); | |
// increment here | |
iter++; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment