Skip to content

Instantly share code, notes, and snippets.

@acmorrow
Last active December 12, 2015 04:49
Show Gist options
  • Save acmorrow/4717073 to your computer and use it in GitHub Desktop.
Save acmorrow/4717073 to your computer and use it in GitHub Desktop.
// C++11 offers type inference. That can cut both ways:
std::vector<std::map<std::string, std::string>> my_vec;
// OUCH:
std::vector<std::map<std::string, std::string>>::iterator current = my_vec.begin();
// Better, but still pretty verbose, and introduces a new name to grok.
typedef std::vector<std::map<std::string, std::string>> strmap_vec;
strmap_vec::iterator current = my_vec.begin();
// C++11 makes this super nice:
auto current = my_vec.begin(); // GREAT!
// BUT 'auto' is not without its perils
auto val = (*current)["query"].second; // What is type of val?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment