[Interest] QScopedPointer::create

Thiago Macieira thiago.macieira at intel.com
Thu Jan 19 06:20:41 CET 2023


On Wednesday, 18 January 2023 14:36:08 PST Hamish Moffatt via Interest wrote:
> Is there any reason why QScopedPointer doesn't have a create static
> method, like QSharedPointer does?

Because there's no benefit. QSharedPointer::create, like std::make_shared, 
makes a single allocation of both the data block and the control block.

QScopedPointer has no control block, so there's only one allocation to begin 
with. Therefore, there's no benefit of having said function. That's probably 
also why C++11 forgot std::make_unique, though that was added in C++14. And 
unlike std::unique_ptr, QScopedPointer is not movable, so you can't write
  auto ptr = QScopedPointer<Foo>::create(args);

> I didn't see any requests for it in jira. Should I just use unique_ptr
> instead?

Yes. QScopedPointer is not being developed any more and is there only for 
compatibility. std::unique_ptr is superior to it in every aspect.

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Cloud Software Architect - Intel DCAI Cloud Engineering
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5167 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20230118/8589997a/attachment.bin>


More information about the Interest mailing list