std::move is used to indicate that an object can be “moved from..to”, that is, allowing the efficient transfer of resources from t to another object.
In particular, std::move produces an xvalue expression that identifies its argument t. It is exactly equivalent to a static_cast for a reference type rvalue.
Its syntax is: std::move(first, last, result).
Usage examples
Let’s suppose we are creating a Tic Tac Toe game and we have a namespace with the following struct that stores the coordinates of our game:
And we have the vectors (v1, v2 and v3) with the following coordinates:
Output will be:
Now let’s assume that a player won by marking the diagonal from left to right.
Using std::move for us to move 0.0 to 1.1 and to 2.2 we would use this code:
Running our code and displaying the output after the player wins would be: