4 ms·
There's hardly extra complexity in C++0x lambdas, you just need the & or = character to specify if variables are captured by value or by reference and off you g
by iam 15y ago
There's hardly extra complexity in C++0x lambdas, you just need the & or = character to specify if variables are captured by value or by reference and off you go. You can even save the closure as an auto variable instead of needing to spell out the type! Seems easier to me.
Personally I prefer the C++0x closures precisely because of the reference/value capturing distinction.
- fauigerzigerk 15y agoI prefer the C++ solution as well because detailed control of everything is what I use C++ for, but saying there is no extra complexity "you just need the ..." is funny because you could say the same about everything that's causing extra complexity. Also, the requirement to add an empty parameter list whenever there's something between [] and {} amounts to extra complexity. This seems to be a purely syntactical dismbiguation thing as neither the mutable qualifier nor the return type should be related to an empty parameter list. We have to realise what complexity is. Part of it is having to think of B whenver we do A even though we do not wish to say anything about B at all.
- pilif 15y agoAs far as I understood the article, using references is a desaster waiting to happen as accessing the references once the original variables are out of scope is "undefined behaviour" - probably accessing random values on the stack if your reference was pointing to a variable on the stack
- shin_lao 15y agoNot using references doesn't help you at all, you have to recursively make sure the lifetime of all the objects you use is greater than the lifetime of your closure.