In C++11, if I try to do this:
int x = 5;
int && y = x;
It will fail to compile, with an error telling that an r-value reference cannot bind to an lvalue.
However if I do:
int x = 5;
auto && y = x;
It compiles with no errors. Why is it happening? I tried to get the type of y
but typeid()
takes away the reference attributes. Does auto &&
automatically collapses to a &
or &&
depending on what is being assigned?