4 ms·
> I never quite understood why unique_ptr and move semantics... It's not those types, in particular, it's because C++11 allows you move your ownership model in
by lbrandy 10y ago
> I never quite understood why unique_ptr and move semantics...
It's not those types, in particular, it's because C++11 allows you move your ownership model into the type system. And then, and this might sound familiar, writing code cognizant and explicit in its ownership semantics leads to safer, cleaner code.
- fauigerzigerk 10y agoTrue, but if you use smart pointers for that purpose, you cannot at the same time use references to protect against null pointers.
- pcwalton 10y ago> It's not those types, in particular, it's because C++11 allows you move your ownership model into the type system. But it doesn't ensure that you use it correctly. Most use-after-free isn't the result of not understanding the ownership semantics; it's the result of understanding it but forgetting to handle some edge case or another.