lambda prints the return type as specified in auto. auto ret = i;prints rethow int.
One solution is to explicitly specify the type of the return value of the lambda:
funct = [](int &i) -> int& {
++i;
return i;
};
As mentioned in the comments, another way is
funct = [](int &i) -> decltype(auto) {
++i;
return i;
};
, decltype .
, , auto decltype(auto).