How to use std::foreach with parameters/modification
问题 I've found myself writing for(int i=0;i<myvec.size();i++) myvec[i]->DoWhatever(param); a lot, and I'd like to compress this into a foreach statement, but I'm not sure how to get param in there without going super-verbose. I've also got things like for(int i=0;i<myvec.size();i++) if(myvec[i]->IsOK()) myvec[i]->DoWhatever(param); and I'd like to rewrite that guy too. Any thoughts? Oh, also, for various reasons, I don't want to use boost. 回答1: #include <vector> #include <algorithm> #include