News for hackers. Stuff that matters.
Re:Go is Google's language, not ours by asveikau on Wednesday May 22, 2019 @04:42PM (#19985248)
> Move constructors are one of the worst parts of C++

Move constructors fix a narrow problem, which is, when you have something like a vector append, how do you copy over all the previous elements as a "shallow" copy rather than a deep one?

In C with realloc(), it's just assumed that memcpy works for that. With C++03 and earlier copying the elements could very well end up duplicating everything on the heap for no reason, then discarding the old copy.

How does rust do this? What I am reading from googling is that every assignment is a move?

Re:Go is Google's language, not ours by damnyou on Wednesday May 22, 2019 @06:08PM (#19986085)
Yes, every assignment of a non-Copy type is a move. (Copy types are basically primitive ones like ints, so not vectors etc.) The compiler prevents you from using the old variable at that point.

Since Rust always enforces that a move is a memcpy, a vector reallocation is just a realloc() like in C.