logoalt Hacker News

spacechild1last Monday at 11:08 PM1 replyview on HN

> Passing the value of something doesn't imply making a copy

Yes, languages like Rust can automatically move variables if the compiler can prove that they will not be used anymore. Unfortunately, this is not possible in C++, so the user has to move explicitly (with std::move).


Replies

1718627440yesterday at 12:31 AM

> Unfortunately, this is not possible in C++, so the user has to move explicitly (with std::move).

Honestly why not? A locally used variable sounds to be very much something the compiler can reason about. And a variable only declared in a loop, which is destroyed at the end of each iteration and only read from should be able to be optimized away. I don't know Rust, I mostly write C.

show 1 reply