Last active
August 2, 2017 18:51
-
-
Save dwburke/c5560908f4d5b2be694209388a6344a8 to your computer and use it in GitHub Desktop.
Delete while iterating std::list
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
for (auto i = list.begin(); i != list.end();) { | |
if (condition) | |
i = list.erase(i); | |
else | |
++i; | |
} | |
or | |
list.remove_if([](auto& i) { return i > 10; }); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment