logoalt Hacker News

ghm2180yesterday at 4:43 PM4 repliesview on HN

> Let me put this in simpler terms: std::move is like putting a sign on your object “I’m done with this, you can take its stuff.”

and later:

> Specifically, that ‘sign’ (the rvalue reference type) tells the compiler to select the Move Constructor instead of the Copy Constructor.

This is the best conceptual definition of what `std::move` is. I feel that is how every book should explain these concepts in C++ because its not a trivial language to get into for programmers who have worked with differently opiniated languages like python and java.

If you read Effective Modern C++ right Item 23 on this, it takes quite a bit to figure out what its really for.


Replies

dsnryesterday at 5:12 PM

In simpler terms

1. You must implement a move constructor or a move assignment operator in order for std::move to do anything

2. The moved object could be left in an unusable state, depending on your implementation, after stealing its internal resources.

show 3 replies
yunnppyesterday at 5:55 PM

I thought "move doesn't move" was a fairly common C++ mantra at this point.

show 1 reply
qbaneyesterday at 8:58 PM

I read Effective Modern C++ years ago and was confused exactly like what you describe.

QuercusMaxyesterday at 5:47 PM

Modern C++ is hard to get into for people who learned C++ in the 90s and then worked in other languages for a decade or two.