How C++ lambdas affect Qt?



  • I don't know about you, but I'm excited about the next "C++ standard":http://en.wikipedia.org/wiki/C++0x which should be coming out in the next year or two. Lambdas, auto, threading, ...

    But it makes me wonder how it will affect Qt. Especially lambdas. I see lambdas as having game-changing effect on how some code is written. The standard library looks to become much more useful with the help of lambdas. How about Qt? Will it be possible to use these powerful new capabilities with Qt?

    What is your opinion?



  • That
    @
    connect(this, SIGNAL(foo(int)), [](int x) { /* ... */ })
    @
    would be simply awesome.



  • My favorite c++0x feature are lambdas too, but i don't think they change that much the way we write code, they are more a "syntactic sugar" for functors, with the advantage that you can just define it "inline", or use smallest 0x feature: the "auto" to name the lambda ;)
    But there are other nice features in C++0x that Qt developers could benefit, like like: initializer lists, move semantics, support for concurrency (we already have that with Qt)

    Anyway 0x it's a good update to C++, and hopefully the next standard (with concepts) won't need another twelve years to complete.



  • [quote author="Giuseppe D’Angelo" date="1292049262"]That
    @
    connect(this, SIGNAL(foo(int)), [](int x) { /* ... */ })
    @
    would be simply awesome.[/quote]

    I think this may be the primary use case that I would like to see, and that I would miss the most if not available.



  • [quote author="Zlatomir" date="1292049421"]My favorite c++0x feature are lambdas too, but i don't think they change that much the way we write code, they are more a "syntactic sugar" for functors, with the advantage that you can just define it "inline", or use smallest 0x feature: the "auto" to name the lambda ;)[/quote]

    Have you see Herb Sutter's talk "Lambdas, Lambdas Everywhere":http://bit.ly/dcJcXN? I think it shows how many ways lambdas are useful. Yes, it is just syntactic sugar, but it is very very sweet.

    [quote author="Zlatomir" date="1292049421"]
    But there are other nice features in C++0x that Qt developers could benefit, like like: initializer lists, move semantics, support for concurrency (we already have that with Qt)[/quote]

    I like those too, but I think lambdas may have more impact on how code is written. That is why I specifically selected lambdas for the topic, rather than general C++0x.



  • That looks nice, but don't forget that signals and slots are member functions.
    Signal/slot mechanism provide inter-object function calls, if you just want to call a functor/lambda/"free" function you don't need signal/slots overhead for that, you just call it.

    LE:
    @Bradley: i didn't see Herb Sutter’s talk, thanks for the link



  • Connecting a signal to a lambda would also provide inter-object calls because lambdas capture values in the local scope.



  • [quote author="Giuseppe D’Angelo" date="1292049262"]That
    @
    connect(this, SIGNAL(foo(int)), [](int x) { /* ... */ })
    @
    would be simply awesome.[/quote]

    Yes indeed! :D



  • [quote author="Giuseppe D’Angelo" date="1292049262"]That
    @
    connect(this, SIGNAL(foo(int)), [](int x) { /* ... */ })
    @
    would be simply awesome.[/quote]

    Don't know if you knew, but Thiago has a patch working towards allowing exactly that :)



  • [quote author="Robin Burchell" date="1292087574"]Don't know if you knew, but Thiago has a patch working towards allowing exactly that :)[/quote]

    No, I didn't. Where does he talk about it? Is it available somewhere?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.