[Development] FileRe: Move ctors for q_declare_shared types

Marc Mutz marc.mutz at kdab.com
Mon Jun 29 20:42:40 CEST 2015


On Monday 29 June 2015 17:50:31 Thiago Macieira wrote:
> On Monday 29 June 2015 17:14:57 Marc Mutz wrote:
> > So, it doubles the number of dtor calls, and it pessimises all code
> > around it.  I am not prepared to make that pessimisation for out-of-line
> > types. People who use std::move can imo be bothered to clear the
> > moved-from object after the move in those miniscule fraction of cases
> > where that actually matters. Forcing people to use swap (if, indeed,
> > they can, because swap() doesn't bind to rvalues on the rhs) for the
> > common case is bad api design.
> 
> I agree with Marc here.
> 
> But, isn't there a third way for some types? For those that can take a null
> d- pointer, it should be easy to just do:
> 
> 	Klass &operator=(Klass &&other)
> 	{ d = other.d; other.d = nullptr; return *this; }

Doesn't work. this->d is leaked in the process.

-- 
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