|
|
|
|
|
by PaulDavisThe1st
414 days ago
|
|
You opted to use features of std::vector that are documented to be unsafe (notably ::data()). This is the actual C++ translation of the opening code in TFA: #include <vector>
#include <iostream>
int main() {
std::vector<int> vec = {1, 2, 3};
for (auto const & i : vec) {
std::cout << i << std::endl;
}
}
It is possible to use C++ to write unsafe code! Amazing! Some people want a language where this is not possible! Great! |
|
No, it isn't: this is iterating over references, not moving. This is equivalent to
in Rust. Note the &, just like in your C++.