lefticus / cpp_weekly

The official C++ Weekly Repository. Code samples and notes of future / past episodes will land here at various times. PR's will be accepted in some cases.
The Unlicense
663 stars 24 forks source link

.reset vs ->reset #370

Closed lefticus closed 3 months ago

lefticus commented 3 months ago

If you have a pointer like thing that contains a pointer like thing.

std::optional<std::unique_ptr<>> for example

fcolecumberri commented 3 months ago

Why would you have a std::optional<std::unique_ptr<>>? I mean, it would make sense if std::unique_ptr could not be empty (Actually that would make more sense), but since std::unique_ptr can be empty, using std::unique_ptr over std::optional<std::unique_ptr<>> is better.

lefticus commented 3 months ago

It was just the first example I came up with. The point being, anything with a pointer-like interface containing anything with a pointer-like interface.

This is based on a real issue I had someone DM to me about their own code.

lefticus commented 3 months ago

https://compiler-explorer.com/z/b1PbPcP9n

lefticus commented 3 months ago

Coming in Ep 424