[Interest] Q_FOREACH creating copy , was (no subject)
Gunnar Roth
gunnar.roth at gmx.de
Mon Jun 29 19:16:55 CEST 2015
Hi Prav
>
> for (Container::const_iterator iter=container.cbegin(); iter!=container.cend(); ++iter) {
> //...
> }
>
> But why this could be more insecure to container copy (as result of detaching) as Koehne Kai warns:
>
> I'd be careful with such an advice, unless you understand the performance
> implications (because range-based loop will sometimes detach the Qt
> Container, which is potentially a lot more expensive than the shallow copy
> foreach does)
>
> is still unclear for me.
>
> _
Maybe you can read my mail from this morning. In short, i talked about
c++11 ranged base for loop which would look like
for( const auto & element : container) {
...
}
this can detach the container , as even as the element is const, the non const begin would be called if container is not a const instance.
Regards,
Gunnar
More information about the Interest
mailing list