[Development] The future of smart pointers in Qt API

Giuseppe D'Angelo giuseppe.dangelo at kdab.com
Sun Feb 2 00:18:46 CET 2020


Il 01/02/20 13:31, Allan Sandfeld Jensen ha scritto:
> On Samstag, 1. Februar 2020 10:15:02 CET you wrote:
>> Il 01/02/20 09:27, Allan Sandfeld Jensen ha scritto:
>>> To me the name is still perfect. It makes perfect sense. Just because it
>>> is
>>> movable doesn't mean you move the object itself, a move moves the content
>>> of the object. So each move triggers a move of the payload of a scoped
>>> pointer to another scoped pointer in another scope.
>>>
>>> I never understood why anyone would think the name would make that
>>> impossible.
>> The counter argument is: it would imply that the _pointer_ escapes the
>> _scope_.
>>
> Not the smart pointer, it never leaves. Only the raw pointer does, and only
> because you have moved it out of the scoped pointer, and it into a new one.

<devil's advocate>

This isn't a counter argument -- in a shared pointer, you share the 
_pointer_, not the smart pointer itself (you'll have several distinct 
smart pointer objects, but all sharing the same pointer).

In a scoped pointer, you "scope" the pointer, not the smart pointer 
object. :-P


>> This conversation is 9 years too old -- the ship has sailed.
>> std::unique_ptr is the vocabulary type that is on every C++ book
>> teaches, every C++ talk explains, every C++ project uses (all over the
>> place inside Qt itself). Unless some extraordinary argument appears,
>> that's the name that Qt should also use.
> 
> It is still a terrible name. Unique pointer refers to something
> std::unique_ptr can abstractly achieve, but not what it actually is.

With this I may agree. The mental exercise used here is not that the 
pointer itself is "unique" (whatever that means), but the ownership is 
unique -- and represented by the unique_ptr object itself.

My 2 c,
-- 
Giuseppe D'Angelo | giuseppe.dangelo at kdab.com | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4329 bytes
Desc: Firma crittografica S/MIME
URL: <http://lists.qt-project.org/pipermail/development/attachments/20200202/2de7f1ab/attachment-0001.bin>


More information about the Development mailing list