dimanche 7 juillet 2019

An rvalue reference binds to an lvalue

Let's considet the following code:

int x = 0;
using U = int&;
U&& r = x;

I tought that, by definition, an rvalue reference to Type only binds to an rvalue expressions of Type (no matter what type is equal to).

I have read some questions on SO, but couldn't figure out the meaning of that code (though, I know that there is a connection to the perfect forwarding). Am I right that the code fragment, I presented, is defined to be a valid code just to make the perfect forwarding possible.

Aucun commentaire:

Enregistrer un commentaire