tags:

views:

492

answers:

5

Lately I've been getting very excited about the support for lambdas in VC2010. I'm slowly starting to grasp the full potential this feature has in transforming C++ into something alot better.

But then I realized that this potential greatly depends on main stream support of lambdas in day to day libraries like boost and QT.
Does anyone know if there are plans to extend these libraries with the new features of C++0x?

lambdas practically replace the need for boost::lambda and everything in boost that interacts with it. QT could add support for lambdas in all of their container and maybe even as an alternative way of defining SLOTs

+3  A: 

Chances are such libraries are going to wait until there's proper compiler support for the relevant C++0x features , and not bother much with it until the mainstream compilers do support it. Don't hold your breath.

nos
+6  A: 

Lambdas already fit very well into existing libraries - anywhere that a function accepts a function object of a type given by a template parameter.

This is one of the great things about them - they're a classic example of a language feature that codifies existing practice in a nifty syntax.

Obviously the boost lambda library becomes redundant, but that means it doesn't require any new features to be added to it.

Daniel Earwicker
A comment from the downvoter might be interesting (but then again, it might not).
Daniel Earwicker
Heh, is that your cookie-cutter down vote comment? :P
GMan
+4  A: 

I don't see how usage of lambda depends on support by libraries. Lambdas eliminate the need to create many classes just to wrap different small algorithms and neatly fit together with other language/library features (std::function comes to mind). Wherever you used to pass either a function object or a function pointer, lambdas can be used, too.

So they mainly add another alternative for making use of existing code and libraries. The only way I can see for libraries to better support lambda is use more functional-style approaches.

sbi
A: 

Most libraries use standard function pointers for callbacks. C++0x lambdas can be used as function pointers, so most libraries wouldn't need to be modified. Other libraries use templates so they can take any callable object (e.g. std::foreach wouldn't need to be modified).

The only other C++0x feature that I can think of that libraries might change to is using strongly typed enums. Also, libraries might start to use extern templates to reduce compilation times.

Zifre
r-value references will (or should) have a big impact - a lot of libraries have classes that serve as wrappers around resources that are expensive to construct, and the addition of move operations will instantly speed up many programs written with such libraries (or make correct programs much more readable).
Daniel Earwicker
Ah, yes, I forgot about R-value references. I'm guessing they would be used a lot in libraries like Boost, but not so much in application oriented libraries like Qt. Also, in most cases, it will not break the interface, so you won't ever have to worry about them (except using them in your own code).
Zifre
You cannot assign the result of a lambda expression to a function pointer.
sellibitze
@sellibitze: An old comment, I know, but now you can if the lambda is stateless.
GMan
+1  A: 

This is NOT true, you cannot replace boost::lambda with C++0x lambda. See here for some reasons (about boost bind, but I think most of it transfers)

Also, @daniel this might help you get started using lambda functions/boost bind for slots. It makes my life incredibly easy.

Additionally, @litb from my sources, lambdas are not going to be changed (argh)

cheez
thanks alot for the link cheez!
Idan K
@cheez - regarding the ugly problem of closing over a loop variable and having to make a copy. Instead use `for_each` to loop through the `vector<int>`. Pass it a lambda to act as the "loop block", i.e. `for_each(d.begin(), d.end(), [` Now that `i` can now be safely captured by value as it is already a copy, and so inside the loop you'd say `funcs.push_back([=]() { return i + 5; });`. The same problem/solution arises in C# and JavaScript.
Daniel Earwicker