From my research I understand that rvalue ref is introduced to resolve the ctor overload at compile time, to enable going to the move ctor/ move assignment operator function i.e move semantics for resource stealing. But is that all there is to rvalue reference or is there something different about it?
int a = 10;
int&& r = move(a);
cout << "r : " << r << "; a : " << a << endl; // r : 10; a : 10
r += 10;
cout << "r : " << r << "; a : " << a << endl; // r : 20; a : 20
So in the above code, 'r' has the rvalue reference of 'a' after going through 'move'. That being said, is it like the classic lvalue reference here, given that we're not dealing with a constant?
If we were having 'move(some_constant)' instead, then will a copy of the constant be created, so that 'r' starts referring to the copy, and that way 'r' can be changed? Technically not changing the constant in the first place?
Because rvalue reference sounds like a reference to something that shouldn't be changed, but in the above cases, that's not likely.
Aucun commentaire:
Enregistrer un commentaire