Interesting and subtle indeed. This also relates to constant-ness AFAIU... When a method is non-const, then we can assume the object can't be concurrently accessed. Therefore we can assume the state can't pass from detached to shared while the method is executed.
Philippe On Thu, 8 Aug 2019 15:32:00 -0700 Thiago Macieira <[email protected]> wrote: > On Thursday, 8 August 2019 02:43:07 PDT Mutz, Marc via Development wrote: > > If there _was_ a QIntrusiveSharedPointer::isDetached(), _then_ it would > > have the same problem as shared_ptr::unique() in that the result becomes > > meaningless upon return to the caller. Such a method might still useful, > > but it's not currently proposed; qIntrusiveDetached() is _not_ that > > function. > > Not really, because of different semantics. > > isDetached() = false can have changed before you make use of the result. > > But isDetached() = true is useful. If an object is detached, it *stays* > detached. This allows you to optimise for that case, while still supporting > the non-detached case albeit slower. > > The examples are the in-place helper functions in QtCore that are called from > rvalue-ref members. Like: > > QByteArray QString::toLatin1_helper_inplace(QString &s) > { > if (!s.isDetached()) > return qt_convert_to_latin1(s); > [... modify s ...] > } > > -- > Thiago Macieira - thiago.macieira (AT) intel.com > Software Architect - Intel System Software Products > > > > _______________________________________________ > Development mailing list > [email protected] > https://lists.qt-project.org/listinfo/development _______________________________________________ Development mailing list [email protected] https://lists.qt-project.org/listinfo/development
