これはC ++のコードです11 Notes Sample by Scott Meyers、
int x;
auto&& a1 = x; //x is lvalue, so type of a1 is int&
auto&& a2 = std::move(x); //std::move(x) is rvalue, so type of a2 is int&&
I am having trouble understanding auto&&
.
I have some understanding of auto
, from which I would say that auto& a1 = x
should make type of a1
as int&
引用符で囲まれたコードのどちらが間違っているようですか。
私はこの小さなコードを書いて、gccの下を走った。
#include
using namespace std;
int main()
{
int x = 4;
auto& a1 = x; //line 8
cout << a1 << endl;
++a1;
cout << x;
return 0;
}
Output = 4 (newline) 5
Then I modified line 8 as auto&& a1 = x;
, and ran. Same output.
My question : Is auto&
equal to auto&&
?
If they are different what does auto&&
do?