Conversation

In fact I never ever used uniq_ptr::get() directly. I only used uptr->type. (shared_ptr has its issues, but its still better than C ptr generally speaking, rust gives a better scope compile time analysis, but C++ gives you some of that. It's not as good, but better than 0 of C)
1
C++ doesn't provide any compile-time safety from use-after-free, since references have no safety and are even implicit. Where are you even using std::unique_ptr? I don't find that there are many use cases for unique pointers other than implementing tree data structures.
1
A std::unique_ptr is no safer than a value on the stack, which is unsafe in C++. It only introduces the additional problems of having null pointer dereferences and encouraging use-after-move. The fundamental problem is that it frees when there are still active references.
1
Having that free as automatic / implicit certainly makes it harder to leak memory, but in the real world I don't think it improves safety. Many of the memory corruption bugs that I find are due to use-after-free largely missed due to implicit C++ destruction at the end of scope.
1
All I'm saying is std::unique_ptr does nothing to help. It's slightly less safe to have `std::unique_ptr<T> foo` than `T foo` since it can be null and encourages moving, but other than that it makes little difference. It's best avoided unless you really need lighter moves/swaps.
1
I rarely find any use case for std::unique_ptr<T> or Box<T> in Rust unless I need a custom tree data structure. Part of the reason for that is because I avoid dynamic dispatch and prefer concrete types, *especially* in C++ where dynamic dispatch is via class-based inheritance.
1
I consider class-based inheritance to be an incredibly awful idea in most cases. One of the only times it's actually a good idea instead of interfaces is when being forced to implement an external class-based inheritance scheme because the standard you're implementing uses it.