[Development] QIntrusiveSharedPointer

Thiago Macieira thiago.macieira at intel.com
Fri Aug 9 00:32:00 CEST 2019


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






More information about the Development mailing list