Consider the code below. What is going on there?
#include <iostream>
#include <stdio.h>
using namespace std;
template<class T>
void test(T &t) // but why int&& is valid here,when instantiated with test<int&>??
{
puts("T&");
}
int tref(int&& param) //compile error
{
puts("tref&");
}
int main()
{
int i;
test<int&>(i);
}
I am not sure I follow, if you mean
int&&in the first one becauseTisint&you are wrong. WhenTisint&, theT&in the signature is stillint&. Also,int&&has nothing to do with composingint&with an extra&.&&has a specific meaning: rvalue-reference.§8.3.2[dcl.ref]/5
§8.3.2[dcl.ref]/6