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

Thiago Macieira thiago.macieira at intel.com
Mon Jul 20 21:26:48 CEST 2015


On Monday 20 July 2015 18:25:43 Keith Gardner wrote:
> > What's the difference in std::vector between an rvalue push_back and
> > emplace_back?
> 
> emplace_back takes variadic template arguments to construct the item
> directly in the vector instead of creating a temporary and then performing
> a move operation. If the template argument is just an rvalue of the
> container type, it will perform just like the rvalue push_back function.
> 
> http://en.cppreference.com/w/cpp/container/vector/emplace_back

Aside from the variadic and the templateness, what's the difference?

The templateness changes how a type different than the vector's type gets 
constructed (it might undergo a conversion first). But assuming I am pushing 
back a T, is there any reason I'd want emplace_back? Or vice-versa?
-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Development mailing list