Assuming the code compiles, is there any difference between:
A && a = .....
and
A & a = .....
? a
is a local variable in a function or method, not a parameter.
By giving the rvalue-reference a name (a
) it is effectively an lvalue for the rest of the scope? i.e. even with the former form, you'd have to use move(a)
to enable pilfering when passing a
to another function?
I appreciate there might be other problems with the second form, which prevent compilation, for example you can't have a (non-const) reference to a temporary. So, yes, I'm curious to know all the differences, but first I want to confirm my hunch that they are fully equivalent for the remainder of the scope.
Update: as an example of this 'temporary' problem, which @KerrekSB has reiterated, sometimes you must make the plain reference const
. In that case, my question is whether there is a difference between:
const A && a = .....
and
const A & a = .....