[Development] qMoveToConst helper for rvalue references to movable Qt containers?

Olivier Goffart olivier at woboq.com
Sat Oct 27 13:37:38 CEST 2018


On 10/26/18 10:26 PM, Elvis Stansvik wrote:
> For completely other reasons, I came across "Range-based for
> statements with initializer" today:
> 
>      http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0614r1.html
> 
> With that, the Qt best practice could become
> 
> for (const auto list = getQList(); const auto &v : list) {
>      ...
> }
> 
> Which may or may not be pretty, but avoids the extra line of code and
> keeps the scope clean.
> 

We could even wrap this in a macro for convenience. We would call that macro 
'foreach' for example.
Ah no, wait, this name is already taken by a macro that does exactly that :-)

Jokes aside, I think we still should let users use Q_FOREACH for implicitly 
shared containers.

-- 
Olivier

Woboq - Qt services and support - https://woboq.com - https://code.woboq.org



More information about the Development mailing list