Skip to content

Instantly share code, notes, and snippets.

@rukletsov
Last active August 29, 2015 14:18
Show Gist options
  • Save rukletsov/e97d400650b1bbe78bcc to your computer and use it in GitHub Desktop.
Save rukletsov/e97d400650b1bbe78bcc to your computer and use it in GitHub Desktop.
Auto benefits
// A case for a more liberal use of `auto`: it's not always easy to get the type correct.
std::map<K, V> data;
for (const std::pair<K, V>& pair : data) {}
for (const auto& pair : data) {}
// First: data.size() copies.
// Second: 0 copies.
// Why? `std::map<K, V>::value_type` is `std::pair<const K, V>`, not `std::pair<K, V>`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment