Create a gist now

Instantly share code, notes, and snippets.

@thiagomg /loop1.cpp
Last active Oct 13, 2015

What would you like to do?
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