[Development] qMoveToConst helper for rvalue references to movable Qt containers?
Elvis Stansvik
elvstone at gmail.com
Sat Oct 27 14:52:48 CEST 2018
Den lör 27 okt. 2018 kl 13:37 skrev Olivier Goffart <olivier at woboq.com>:
>
> 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.
Yes, I thought that Q_FOREACH was slated for deprecation though. But
maybe that's not set in stone yet?
I just found this post by Marc: https://www.kdab.com/goodbye-q_foreach/
Lots of comments there I haven't had time to go through yet, so I bet
it's a contentious issue :)
Elvis
>
> --
> Olivier
>
> Woboq - Qt services and support - https://woboq.com - https://code.woboq.org
> _______________________________________________
> Development mailing list
> Development at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/development
More information about the Development
mailing list