4 ms·
Rust just took C++ std::unique and std::shared ptr and made those integrated directly in the language, and the only option for allocation. Which is awesome. It
by frankreyes 3y ago
Rust just took C++ std::unique and std::shared ptr and made those integrated directly in the language, and the only option for allocation. Which is awesome.
It would be nice to see if we can have a sub set of C++ that forces us to only use std::make_unique or std::make_shared calls.
- UncleMeat 3y agoYou can already write a very very very simple linter that bans use of the "new" keyword. Rust did quite a bit more to make this ergonomic than just force you to use smart pointers.
- proto_lambda 3y ago> Rust just took C++ std::unique and std::shared ptr and made those integrated directly in the language, and the only option for allocation Not really. Both Box and Rc/Arc are first and foremost library features implemented using the equivalent of malloc() and free(). Box is a bit special due to its deref semantics, but other than that, there's nothing stopping you from implementing them or something else yourself.
- frankreyes 3y agoThanks, never wrote Rust so I'm just guessing. What else there is, besides static type checks? Is there a runtime side too?
- proto_lambda 3y agoThere is no runtime (other than init/exit handling). The main thing that provides memory safety without a GC is the borrow checker, which is a language feature and independent of the smart pointer types in the standard library.