Re:Closures and Objects Are Equivalent (2013)
by gpderetta on Tuesday November 22, 2022 @06:12AM
(#33704493)
Sorry, 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.
Re:Closures and Objects Are Equivalent (2013)
by int_19h on Tuesday November 22, 2022 @05:46PM
(#33712638)
In 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.
And, yes, what [=] produces is not a closure, by definition (but it's still a lambda).