[Development] QVector now has rvalue push_back (was: Re: HEADS UP: potential trouble from a recent QVector change)

Gunnar Roth gunnar.roth at gmx.de
Tue Jul 21 20:23:58 CEST 2015


> Am 21.07.2015 um 19:58 schrieb Milian Wolff <milian.wolff at kdab.com>:
> 
> On Tuesday 21 July 2015 19:49:13 Gunnar Roth 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.
> 
> Yes, it is an r-value ref, but itself it's an lvalue. So for perfect 
> forwarding, you need to move it. Or something like that, Scott Meyers wrote a 
> chapter on that afaik but I have to admit that I forgot most of it already.
> 

I think what you mean is  std::forward <http://en.cppreference.com/w/cpp/utility/forward>()
Regards,
Gunnar


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20150721/1d2aa5cd/attachment.html>


More information about the Development mailing list