4 ms·
> This is what move semantics are for. You call something, it gives you a thing, and now it's yours to use and release. Needs language support to work well, but
by Veliladon 4y ago
> This is what move semantics are for. You call something, it gives you a thing, and now it's yours to use and release. Needs language support to work well, but is the right answer.
Isn't this literally Rust?
- woodruffw 4y agoI don't believe this should be downvoted, since it's an earnest question. The answer is that Rust has affine types, which is a fancy way of saying that variables are owned exactly once. The borrow checker enforces this property, essentially by making temporary reference copies of the owned object and proving that they never outlive their backing value. Move semantics are an implementation detail of affine typing, but can also be used (and are successfully applied) outside of purely affine languages like Rust. C++ is probably the most famous example of that, where `std::move` essentially means "extend the lifetime of this value by moving its contents to the lvalue."