3 ms·
We don't because those pointers are explicit. But they're not with closures, even with something as low-level as [&] in C++. And, yes, what [=] produces is not
by int_19h 4y ago
We don't because those pointers are explicit. But they're not with closures, even with something as low-level as [&] in C++.
And, yes, what [=] produces is not a closure, by definition (but it's still a lambda).
- gpderetta 4y agoSorry, why wouldn't closing over a variable by value count as a closure? In fact in many functional languages you can't tell the difference.
- int_19h 4y agoIn functional languages where you can't tell the difference, like ML or Haskell, values are bound directly to variables, so capturing the value is closing over the variable. But in C++, variables represent storage locations which contain values, so if you copy the value, you're not really closing over the variable (unless it's const). To look at it from another perspective, if a closure closes over the variable, then references to that variable inside the closure should behave the same as references to that variable outside of it. If you can change the variable value outside, and it's not reflected inside the closure, then it's not really the same variable inside and outside.