this post was submitted on 30 Nov 2023
-1 points (45.5% liked)
C++
1779 readers
2 users here now
The center for all discussion and news regarding C++.
Rules
- Respect instance rules.
- Don't be a jerk.
- Please keep all posts related to C++.
founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
I’ve been using unique_ptr since way before it was called that, and it’s not something magical. You need to know what it does and what it doesn’t or you’ll be surprised.
I always thought of unique as a warning not a guarantee. Make sure it’s the only thing pointing at your structure, or you’ll be in trouble.
I don't think that
std::unique_ptr
is shrouded in mystery: it's designed to be the unique handle of a raw pointer, and it frees the memory when it's lifetime ends. As it's designed to be the unique holder of a resource, it's implemented to disallow making copies. It might be implemented in clever ways, but a developer experience point of view it's quite straight to the point.