[Interest] Q_FOREACH creating copy , was (no subject)
pr12og2 at programist.ru
Tue Jun 30 17:35:43 CEST 2015
> Just a note: AFAIK, you can also prevent the detach by iterating over a
> const ref to the container instead of the actual one. However, that also
> is more work to write, of course.
Mmmm ... glad you end up with the same idea Koehne ... +1 in my "team" :) ... "const ref to the container" loop ... this is what the discussion started from.
If in definition of QForeachContainer class we add just ONE symbol "&" before "с" in line
const T c;
const T &c;
we will end up with this loop which will be same "work to write" as current foreach. So easy to do :)
In such a way we can modify current foreach or add another for loop macro .. like "forevery" ... or any other name which is fine for majority.
This seems to be the question to Thiago Macieira. No?
In case the idea of adding of "const ref to the container" loop will be rejected by community I am aware only about necessity for everybody to
know that people may add their own for loop so that code completion feature of QtCreator will not use any hardcoded names like "foreach" and thus work for other for-loops as well.
More information about the Interest