What is the correct approach to transparently calling from the calling user foo?
You cannot do this, and that was so. Lvalue never moves from transparent.
Since the moved object usually remains in an unknown (but legal) state, it would be dangerous if the client could pass the lvalue value as an argument to the function, and this function was allowed to silently pass from it. A client can be left as a zombie object without even knowing it!
Therefore, the language enforces the rule that moving from an lvalue must be a conscious action and must occur by explicitly turning the lvalue into an rvalue (actually, an xvalue) by calling std::move() .
In this case, I would say that your function foo() - what it really should do, should take the rvalue reference, and the client should call it like this:
T t2 = foo(std::move(t1));
Note that this last sentence may not be correct after you turn a meaningless name, such as foo() , into something that reflects the semantics of a particular operation in a particular program. However, not knowing what the meaning of this operation is, I can only provide official, mechanical advice on how to compile code and how to think about the semantics of movement in general.
source share