Advertisement
sehe

Untitled

Jan 2nd, 2012
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. There won't be a discernable performance difference, when using a decent compiler.
  2.  
  3. for (int i=0; i < data.size(); ++i)
  4. data[i].Foo();
  5.  
  6. Not slower, just profile that! Simple code tends to be quicker. In this case, all versions are equally simple
  7.  
  8. for (Object& it : data)
  9. it.Foo();
  10.  
  11. Fixed that for you: use a reference to avoid unwanted copying. This is roughly equivalent to:
  12.  
  13. for (auto it=std::begin(data); it!=std::end(data); ++it)
  14. it->Foo();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement