[Development] qMoveToConst helper for rvalue references to movable Qt containers?
André Pönitz
apoenitz at t-online.de
Sat Oct 27 19:29:31 CEST 2018
On Sat, Oct 27, 2018 at 04:33:30PM +0100, Sérgio Martins wrote:
> On Sat, Oct 20, 2018 at 1:44 PM Elvis Stansvik <elvstone at gmail.com> wrote:
> >
> > Hi all (first post),
>
> Welcome :)
>
> > In Qt 5.7+ there's qAsConst, an std::as_const implementation for those
> > who are not on C++17 yet, which is convenient for iterating over Qt
> > containers using range-based for loops without causing a detach.
> >
> > For good reasons there's no version of qAsConst that takes an rvalue
> > reference, so you can't do e.g. for (auto foo :
> > qAsConst(returnsQtContainer()) { ... }. Instead you must do const
> > auto stuff = returnsQtContainer(); for (auto foo : stuff) { ... }.
>
> Should we instead just encourage people to make returnsQtContainer()
> return a const container ?
This is actually a route we recently took in some cases in Qt Creator's
code base.
Andre'
More information about the Development
mailing list