[Qt5-feedback] Why lambdas would be very good to have
Timur Kristóf
venemo at fedoraproject.org
Sun Jun 12 11:41:17 CEST 2011
Hi,
There was an initiative I've seen in
http://labs.qt.nokia.com/2011/05/26/cpp0x-in-qt/ that Qt intends to
support features included in C++0x, including lambdas. I must also point
out that lambdas already work with GCC and MSVC.
I'd like to point out some very good use cases for lambdas and recommend
some features for Qt based on them which would make everyone's life a
lot easier.
Let's say you have a collection (QList) of something and you want to
filter or find some elements from it. This is currently only doable with
a foreach loop. So you each time you want to find something, you will
need a foreach loop in your app.
MS.NET uses lambdas in a creative way to address this (the technique is
called LINQ), and I think we could easily add similar functionality to
Qt.
I have implemented a class that provides a simplistic implementation of
the above and put together a small example code to demonstrate how it
works.
http://pastebin.com/tZdkJQCd
http://pastebin.com/WiC6MTNn
I think a similar class (or the implementation of these methods in QList
itself) could be a reasonable improvement in Qt.
The other area where I would love to see lambdas is signal-slot
connections: allow the developers to connect signals to inline lambda
functions, similar to how C# lets you connect event handlers to
anonymous delegates.
I haven't thought about how to implement this one yet, but I'm sure it
would be considered a great feature.
I'm curious, what do you guys think about these?
As for me, I'd love to see these feature in Qt 5.
Cheers,
Timur
More information about the Qt5-feedback
mailing list