[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
Tue Jul 21 17:55:42 CEST 2015


On Tuesday 21 July 2015 12:40:26 Marc Mutz wrote:
> > > So start using qMove() or pass temporaries in your QVector::append()
> > > calls.
> >
> > 
> >
> > Are we also using move internally when resizing and detaching?
> 
> No.
> 
> For detach, we cannot (we need a copy).
> 
> For resize, the pressure to implement it isn't very big, because most types 
> that have a move ctor can also be Q_MOVABLE_TYPE (or, soon,
> Q_RELOCATABLE_TYPE, ie. Q_MOVABLE_TYPE, except for QList), and just
> realloc()  is still faster calling lots of move ctors + dtors.

In my version of QVector, this is already implemented. Movable and trivial 
types are simply realloc()ed, so no copy takes place.

Other than those, they're always copied due to partial exception safety 
developed by João for Qt 5.0.

> If you have a move-only type, or a type that can be moved but cannot be 
> Q_MOVABLE_TYPE (and not just because of QList BiC, which Q_RELOCATABLE_TYPE 
> will fix), better use std::vector to hold it.

Agreed.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Development mailing list