[Development] QVector now has rvalue push_back (was: Re: HEADS UP: potential trouble from a recent QVector change)
Keith Gardner
kreios4004 at gmail.com
Tue Jul 21 19:57:42 CEST 2015
On Tue, Jul 21, 2015 at 12:49 PM Gunnar Roth <gunnar.roth at gmx.de> wrote:
>
> >
> > void push_back(T &&t) {
> > ensureCapacity(size() + 1);
> > new (m_end) T(std::move(t)); // move-construct
> from t
> > ++m_end;
> why is std::move needed here? Afaik std::move(t) converts t into a rvalue
> ref, but t is already an r-value ref.
>
The rule of thumb is if you can get the address of the object, then it is
an l-value. It may be an r-value going into the function but once in the
function, you can get its address. You need to use std::move to treat data
as an r-value again.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20150721/d87ed719/attachment.html>
More information about the Development
mailing list