値をキャプチャしたが、値の型がテンプレート関数の参照である場合
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);
}
それは印刷します
2
3
2
しかし、ラムダが呼び出すときT t1(t);
T
はint&
そうt1
あるべきです。なぜ出力されないのですかint&
test(t1)
2
3
3