When I commit a value, but the type of the value is a reference in a template function
template<class T>
void test(T&&i)
{
++i;
std::cout << i << std::endl;
}
template<class T>
void typetest(T&& t)
{
++t;
T t1(t);
[=]() mutable { std::cout << t1 << std::endl; return test(t1); }();
std::cout << t << std::endl;
}
int main()
{
int i=1;
typetest(i);
}
he prints
2
3
2
But in T t1(t); Tthere int&, so it t1should be int&when the lambda calls test(t1). Why is there no way out?
2
3
3
source
share