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

Milian Wolff milian.wolff at kdab.com
Tue Jul 21 19:58:24 CEST 2015


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.

Bye
-- 
Milian Wolff | milian.wolff at kdab.com | Software Engineer
KDAB (Deutschland) GmbH&Co KG, a KDAB Group company
Tel: +49-30-521325470
KDAB - The Qt Experts



More information about the Development mailing list