C++ Logo


Advanced search

Re: New way to declare smart pointers

From: Domen Vrankar <domen.vrankar_at_[hidden]>
Date: Wed, 23 Oct 2019 15:14:23 +0200
On Wed, Oct 23, 2019, 2:30 PM Aymeric Pellé via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> Hello,
> This proposal aims to ease the basic use of smart pointers.
> The following declarations:
> T*s ptr;
> T*u ptr;
> T*w ptr;
> would be equivalent to this ones:
> std::shared_ptr<T> ptr;
> std::unique_ptr<T> ptr;
> std::weak_ptr<T> ptr;
> What do you think about it?

What is the motivating example for this?

I personaly would not like it. If nothing else it encourages pointer
parameters instead of dereferencing them and passing them by reference.

For example: The caller is holding the lifetime anyway so "void foo(const
std::shared_ptr<const T>&)" that I see quite often (should be "void
foo(const T&)") at least theoretically encourages people to switch from
pointers to references where possible while "void foo(const T*s)" would
give the feeling that using pointers everywhere is a good idea.

Also this would most likely be an issue for parsers since you can allready
write "void foo(const T*s)" without a space between * and variable name.


Received on 2019-10-23 08:16:52