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.
std::move produces an
xvalue expression that identifies its argument
t. It is exactly equivalent to a
static_cast for a reference type
Its syntax is:
std::move(first, last, result).
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 (
v3) with the following coordinates:
Output will be:
Now let’s assume that a player won by marking the diagonal from left to right.
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:
Complete code created for this example:
Very simple, right ?!