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

Marc Mutz marc.mutz at kdab.com
Tue Jul 21 21:40:28 CEST 2015


On Tuesday 21 July 2015 20:11:33 Bubke Marco wrote:
> Gunnar Roth <gunnar.roth at gmx.de>
> 
> > >      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.
> 
> If T would be not a template t is binding to a rvalue reference but it is
> not itself a rvalue reference but an lvalue. If T is a template like in
> this case it is more complicated because it is a universal or forward
> reference. For a forward reference it could be an lvalue reference like
> (T&) or a lvalue(T) depending as the argument is a rvalue, lvalue or
> lvalue reference.
> T&& -> T
> T& -> T&
> T -> T
> 
> std::forward would be of better use than std::move:
> http://en.cppreference.com/w/cpp/utility/forward

Please try it, and then report back.

Thanks,
Marc

-- 
Marc Mutz <marc.mutz at kdab.com> | Senior 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