
Gabriel Dos Reis wrote:
Jaakko Jarvi <jajarvi@cs.indiana.edu> writes:
My example was a bit contrived too. Here's another example (with imaginary syntax):
auto foo() { int i; return auto(int x) { return i + x; } }
Is it different from
int& f() { int i; return i; }
?
Yes, it's a bit different, since the reference return is explicit. I can choose between "int & f()" and "int f()" and the semantics are fairly straightforward. In a lambda, bind by value and bind by reference are equally useful, and we should have a (straightforward) way to choose between them. And it seems to be that the default should be by value since it's safe, and by-ref should probably be designated by the usual ref(i) construct (*&i is also an option, but it's somewhat of a wart).