|
![](/i/fill.gif) |
Warp wrote:
> You could, of course, create the same effect as with the lambda function
> by other means, but it would be laborious and cumbersome (eg. creating a
> struct of pointers to all the local variables you want visible
> inside the comparator function, and implementing the comparator inside
> that struct, and then instantiating the struct and giving it to std::sort),
> and most probably the compiler wouldn't even be able to optimize it as well.
That's actually how C# implements lambdas. Except that with GC available,
you can then return the lambda and the local variables (in all the stack
frames above that you've closed over) still exist until you GC the lambda
expression. Just so's ya know.
> The lambda functionality makes this a lot more convenient, and probably
> also more efficient.
Certainly more convenient, yes.
>> I 100% honestly think you're taking things personally that aren't being
>> personally directed at you.
>
> You still know that I get trolled when someone writes such mocking words
> about C++ as you have done.
I'll sincerely try to sound less mocking in the future.
> I really can't understand why you don't see the benefits.
Now that you've given me some examples to think about, I do. I was thinking
about the convenience of actual lambda functions that I've taken advantage
of, none of which are supported by what C++ calls lambda functions. Now that
you describe some examples where C++ lambdas are convenient, I can visualize
places where I've worked around the lack of that sort of feature.
For example, in Tcl, when you initialize a DLL written in C, you get to
return a void* from the initialization feature, and that void* gets carried
around by the interpreter and passed back into whatever functions that DLL
declared as Tcl-accessible. So that's the same sort of situation in which
using a downward funargs in C++ would be helpful. And it's not a lambda
either. :-)
I probably write different kinds of code than you do, but it doesn't really
come up that often in stuff I write in an OO language. Maybe because the
stuff that I'd normally be closing over I'm instead holding in member
variables, so the "this" gets passed around anyway for context.
> Personally I see C++ lambda functions (in conjunction with things like
> auto variables) having the same kind of potential.
I think C++ templates are far more powerful than C++ lambdas. Altho lambdas
that actually do the closure stuff are pretty powerful too. (For example,
you can define the integers using nothing but them. :-)
--
Darren New, San Diego CA, USA (PST)
My fortune cookie said, "You will soon be
unable to read this, even at arm's length."
Post a reply to this message
|
![](/i/fill.gif) |