[Development] Move ctors for q_declare_shared types
Marc Mutz
marc.mutz at kdab.com
Sat Jun 27 13:21:02 CEST 2015
On Saturday 27 June 2015 12:16:57 Marc Mutz wrote:
> On Friday 26 June 2015 19:23:58 Marc Mutz wrote:
> > > Wyh can you do this inline?
> > >
> > > QFoo &operator=(QFoo &&other) { swap(other);QFoo<>().swap(other);
> > >return
> > >
> > > *this; } would not work ?
> >
> >
> >
> > It would. But you would have made a previously fully inline function call
> > a non-inline one. You might as well copy, then (assuming we're still
> > talking about implictly shared classes).
>
> It also is no longer safe for self-assignment.
Provided there is a move constructor, which is not the case atm for the
majority of Q_DECLARE_SHARED classes, this would be self-assignment-safe:
QFoo moved(std::move(other); swap(moved); return *this;
which is nicely symmetric with
QFoo copy(other); swap(copy); return *this;
the well-known copy-swap idiom.
--
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