3 ms·
Yep, iterators are one of the most annoying things in C++. That's why I love range for in C++0x - instead of writing this, for example: for(std::vector<std::st
by stephen_g 15y ago
Yep, iterators are one of the most annoying things in C++. That's why I love range for in C++0x - instead of writing this, for example:
for(std::vector<std::string>::iterator it = vec.begin(); it != vec.end(); it++)
you can just do:
for(std::string x : vec)
So awesome!
- dzorz 15y agoEven better: for (auto &x : vec) { }
- cageface 15y agoI can't wait until I can start using this in XCode.
- dzorz 15y agoIf you compile recent clang, it supports range based for loops. Using https://github.com/Rip-Rip/clang_complete https://github.com/Rip-Rip/clang_complete you can use smart context-aware completion with vim/emacs. For example if you had this code: vector<string> vec; for (auto &x : vec) { x and then if you typed period (.), it would show members from std::string. I'd say it works better than Intellisense (it's very precise and you use the same parser for code completion and final compilation).
- voyvf 15y ago> If you compile recent clang, it supports range based for loops. Thanks for the tip, will update my copy and try it out this weekend! :D
- cageface 15y agoI'm too dependent on the rest of the integration with XCode to venture back into emacs land again but I'm looking forward to a rev of XCode that includes this.