Question

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

Was it helpful?

Solution

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.

OTHER TIPS

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.

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.

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)

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top