9 ms·
> That's not simpler at all - it's basically the same Oh, you mean like how you have rvalues, lvalues, xvalues, glvalues and prvalues[1]. In Rust you have valu
by vvanders 8y ago
> That's not simpler at all - it's basically the same
Oh, you mean like how you have rvalues, lvalues, xvalues, glvalues and prvalues[1]. In Rust you have value, ref and mut ref.
You also don't specify ownership of passed pointers. So you need to encode that into your function documentation, as opposed to Rust where only value types can change ownership.
> And just like in C++ you have types in Rust that look like stack allocations but aren't, like Vec.
Never said anything about that, we're just talking about parameter types here, of course you can have value types take ownership of stack allocations(Box<T>, std::unique_ptr and their variants).
> And you need to specify in your function if it's taking ownership or not in addition to whether or not it's pass-by-value or pass-by-reference.
Not in the case of Rust, value types are the only thing that can take ownership(even Arc/Rc return value types when you clone()). Refs just allow temporary access in a mutable/const way for the lifecycle of the function.
> Rust got to break backwards compatibility which allowed it to remove a lot of C/C++'s old mistakes
Thanks for proving my point. I've never seen a C++ codebase that didn't use some of C++'s mistakes.
[1] https://stackoverflow.com/questions/3601602/what-are-rvalues-lvalues-xvalues-glvalues-and-prvalues https://stackoverflow.com/questions/3601602/what-are-rvalues...
- kllrnohj 8y ago> Oh, you mean like how you have rvalues, lvalues, xvalues, glvalues and prvalues[1]. In Rust you have value, ref and mut ref. That is not a reasonable comparison and you know it. rvalues & lvalues are the only things in C++ that you ever care about in the slightest unless you're writing a compiler, and if you're writing a compiler then Rust has things like xvalues, too (how do you think the Drop trait works?)
- vvanders 8y agoAnswer me a simple question, why does std::move exist then? (here's a hint, Rust doesn't need xvlaues because every value already has an associated lifetime)