Skip to content

Instantly share code, notes, and snippets.

@mtao
Created December 27, 2017 04:21
Show Gist options
  • Save mtao/8edccac1c433b4b44240de23852eb484 to your computer and use it in GitHub Desktop.
Save mtao/8edccac1c433b4b44240de23852eb484 to your computer and use it in GitHub Desktop.
turns out structured bindings work in ranged for loops!
#include <map>
#include <iostream>
int main() {
std::map<int,int> pairs;
pairs[0] = 1;
pairs[1] = 5;
pairs[2] = 4;
pairs[3] = 3;
pairs[4] = 2;
for(auto&& [k,v]: pairs) {
std::cout << k << " => " << v << std::endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment