[Development] Deleter that calls deleteLater() for use with std::unique_ptr<> and other smart pointers

Thiago Macieira thiago.macieira at intel.com
Wed Apr 19 19:43:22 CEST 2017

On quarta-feira, 19 de abril de 2017 06:44:24 PDT Konstantin Tokarev wrote:
> Hello,
> I think it will be a good idea to provide implementation of functor calling
> deleteLater() instead of delete which can be used with std::unique_ptr,
> std::shared_ptr and other smart pointers with compatible interface.
> We already have QScopedPointerObjectDeleteLater, however it implements
> cleanup(T*) instead of operator()(T*).
> Any suggestions how to name this new class and where to place it?

QSharedPointer already supports a PMF as a deleter.

	auto ptr = QSharedPointer<QObject *>(new QObject, &QObject::deleteLater);

So I think this actually belongs in the std-proposals mailing list, not in Qt.

Until C++20 gets it, you can use a lambda.

Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center

More information about the Development mailing list