Koenig explains std::move
as, well, just a bit of a fib, really:
Sometimes You Must Violate an Abstraction to Maintain It
by Andrew Koenig
From the article:
What
std::move
really does is to return its argument as an rvalue reference. In effect, every time we usestd::move
, we are telling a lie. In this case, by writingstd::move(t.s)
, we are saying that we want to uset.s
, but to do so in a way that treatst.s
as an rvalue. It is acceptable for us to tell this lie for exactly the same reason that it is acceptable for us to castt.s
tostring&&
in the previous example: We know thatt.s
is a member oft
, andt
really refers to an rvalue in our caller's context.We can tell such lies any time we are willing to take responsibility for the consequences. ...
Add a Comment
Comments are closed.