3 ms·
The purpose of the first code example in TFA: > This is straightforward: we create a vector containing the values [1, 2], then iterate over it and print each e
by PaulDavisThe1st 2y ago
The purpose of the first code example in TFA:
> This is straightforward: we create a vector containing the values [1, 2], then iterate over it and print each element, and then finally print out the length of the vector. This is the kind of code people write every day.
The C++ code I provided does essentially this (I omitted printing the length, since it is so trivial), and is "the kind of code people write every day".
The fact that Rust requires you to consider move semantics for such simple code is precisely one of the central points of the article.
- deleted 2y ago[deleted]
- steveklabnik 2y ago"C++ code that implements the problem, but in a different way" is not "the actual C++ translation of the opening code in TFA."
- PaulDavisThe1st 2y agoThe C++ code implements the intended goal, not the problem TFA is trying to illustrate. Changing between: for (auto i : vec) and for (auto & i : vec) has essentially no bearing on what the author is trying to show. If they were focused on how move semantics are always important, they would not use an integer type.