C++ lambdas are a killer feature, its just a shame that they are too bloated to ever be used. I had so much hope for this feature, I was crushed when I saw the generated assembly. Seriously WTF, every single captured variable is done so by way of a separate pointer. You could capture everything using just a single pointer to the parent scope. What a lazy good for nothing excuse for an implementation, I am not sure if something in the C++ standard has steered the implementation to be this way but every compiler does this as far as I can tell.
Here is a comparison between the generated assembly for GCC C nested functions vs C++ lambdas, I think you should clearly be able to see why I am so angry. I don’t understand why anyone would think that this bullshit code is acceptable, it makes the the whole feature completely worthless.
Lambda test code:
C++ Lambda assembly:
GCC C Nested function equivalent: