[Development] FileRe: Move ctors for q_declare_shared types

Thiago Macieira thiago.macieira at intel.com
Mon Jun 29 17:50:31 CEST 2015


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

This is better than the three-way swap because there's no extra temporary 
being constructed and destructed out-of-line.

The drawback is that it implies null-d-pointer support forever, since it got 
inlined in user code.
-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center




More information about the Development mailing list