[Qt5-feedback] Why lambdas would be very good to have
Charley Bay
charleyb123 at gmail.com
Tue Jun 14 18:02:23 CEST 2011
>
> vivainio asketh:
> > Why would functors be better than lambdas for some things, given that
> among
> > lambda can invoke a functor? Execution speed?
>
Thiago respondeth:
> Lambdas are functors out of an anonymous class and with a completely new
> declaration syntax,
I agree with Thiago, but since I penned the original assertion from which
the question came:
charley asserteth:
> I also have implemented my own version of "lambdas" with Functors, and it
> works nicely. For the trivial stuff, lambdas would probably be easier; for
> the "heavy" stuff, Functors are probably better.
>
In my use, the "heavy stuff" means I *want* an explicit application-specific
Functor class with well-known members and types, explicit instantiation, and
explicit management as a part of a design. I'm not concerned about
execution speed (usually), but rather, need to have an explicit lifecycle
(creation/management/execution[perhaps more than once]/destruction).
However, I'd want "lambdas" to hook things together, and would probably make
all my signals/slots mere hook-ups through lambdas. I'd still have
application-specific "heavy" Functors so I could manage their lifecyles,
though (but perhaps trigger their execution through lambdas).
Signals and slots let you couple "signalling" when you don't want to couple
the types. Lambdas similarly let you create functors when you don't want to
bother defining a functor type (e.g., an "anonymous functor type" with a
completely new syntax, as Thiago states).
So, I'd still use both, but lambdas when I can.
--charley
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt5-feedback/attachments/20110614/7e06b37c/attachment.html
More information about the Qt5-feedback
mailing list