Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Kind of, though because the language does a lot of things for you when you use the built in copy, make_unique gets complicated when you want to use std::box inside of another structure. You would need to override the default copy constructor to get this to work. For instance, vector<box<Foo>> wouldn't be possible to implement with unique_ptr because you can't override the copy constructor for a templated type. std::box would allow you to copy it. As for why you would need to do this (over vector<Foo>), consider Foo having subclasses. Complexity breeds complexity...

Regardless, I think lifetime annotations would solve far more problems than std::box. I really do like box as a suggestion as it would help clean up types, make things a bit more explicit in a few places, but there are bigger issues with C++ right now. This is a great suggestion (as is unique_resource for similar on the stack), but a relatively minor thing in the scheme of things. Still nice.



Lifetime annotations are somehow complicated without subseting the language.

It isn't as if Microsoft, Apple and Google haven't been doing it for a while.

https://devblogs.microsoft.com/cppblog/high-confidence-lifet...

https://reviews.llvm.org/D15032




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: