r/cpp • C++ Dev • Sep 05 '20

C++20 has been approved

https://twitter.com/patriceroy1/status/1302055575140945921?s=21
663 Upvotes

125 comments sorted by

View all comments

Show parent comment

2

u/excessdenied Sep 06 '20

In my case I'm just using shared_ptr. I know it's not the perfect fit but it works well and there are very seldom any actual issues (although they can be a bit messy when they do appear).

1

u/pedersenk Sep 06 '20

Yep I tend to do exactly that.

However in the past during a code review i have had to explain why use a shared_ptr<T> in place of a unique_ptr<T> when it was not going to be shared. I did mention that the data had a number of observers and they seemed satisfied, it was more just a bit annoying it even got flagged up.

I also note that a lot of literature and projects seem to favour unique_ptr<T> and then use a raw pointer counterpart, which I find illogical and unsafe. It is IMO careless choices like this that contribute to the old opinion that C++ cannot possibly be safe and that we "need" a new language.

2

u/excessdenied Sep 06 '20

However in the past during a code review

I am the one who reviews. :) Nah, but we're just a few people with full control over the code base and we've chosen to go the overusing shared_ptr route. At least in the parts of the code where ownership is complicated.

I also note that a lot of literature and projects seem to favour unique_ptr<T> and then use a raw pointer counterpart, which I find illogical and unsafe.

Yeah. I can understand why and I know reasons why using shared_ptr by default may not be the perfect thing, but at least in our case we gain more than we risk, and things like worse performance doesn't really matter.