You will only get a move if the argument of the function (in this case, the argument of push_back
) is an rvalue, as well as in certain situations when you return objects from a function.
In your example, pr
is not an rvalue, so you won't get it moved.
However, if you – for example – pass a temporary object to the vector, like this:
v.push_back(std::pair<std::string,bool>());
This will be an rvalue and trigger a move.
You can also trigger the move by explicitly casting the argument to an rvalue in the way you suggested:
v.push_back(std::move(pr));
Note, however, that in this case you won't be able to use pr
after the call in a meaningful way any more as its contents have been moved away.
(Of course, another precondition for a move is that the function you call actually accepts rvalue references. For vector push_back
this is indeed the case.)