[Qt-interest] What is the best, "for" or "foreach"?

David Ching dc at remove-this.dcsoft.com
Sat Nov 28 16:27:37 CET 2009


"M. Bashir Al-Noimi" <mbnoimi at gmx.com> wrote in message 
news:4B1133EC.30200 at gmx.com...
> Can I use "foreach" for modifying container items just like for?

Yes, you can use a non-const &, but then you will run into the performance 
degradation mentioned in the blog.  The blog says foreach has comparable 
performance only when used with const &.

I can't exactly picture why this is the case.  Apparently each item is 
copied in the non-const case, which takes more time.  But why is it copied?

-- David 




More information about the Qt-interest-old mailing list