Skip to content

Instantly share code, notes, and snippets.

@thiagomg
Last active October 13, 2015 00:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thiagomg/8f910117dcbc4461a7e0 to your computer and use it in GitHub Desktop.
Save thiagomg/8f910117dcbc4461a7e0 to your computer and use it in GitHub Desktop.
Range loops - Writing safe
//First possibility
for(auto it = msgs.cbegin(); it != msgs.cend(); it++) {
PublishMessage(*it);
}
//Second possibility
for(const auto &msg : msgs) {
PublishMessage(msg);
}
//Thrird possibility
for_each(begin(msgs), end(msgs), [](const auto &msg) {
PublishMessage(msg);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment