
Hi Phil, On 2/1/11 3:52 PM, Phil Endecott wrote:
Do you have any thoughts about how lambdas in C++0x compare for your problems?
Lambdas in C++0x look like they would work just as well for my problems and furthermore would be less verbose, though I haven't experimented with them since I don't have easy access to a compiler that supports them on my Mac laptop.
I guess I'm thinking, how useful is this going to be in a couple of years when hopefully we all have C++0x compilers?
That though had occurred to me as well. However, even in a couple of years there will likely still be lots of places where we will not have access to C++0x lambdas. For example, I have not seen any timeline for when the default OSX build environment will have them, given that they are not going to use any gcc above version 4.2 (due to the license change) and instead are planning to switch to LLVM/Clang, which is still ironing out the bugs in its C++03 support and has barely started on C++0x.
Could this be seen as a sort of "C++0x lambda emulation" library? I don't think it's really quite the same, though...
It offers a few additional features above merely emulating C++0x lambdas. Most significantly, the local functions that it provides are named, which means one can use them at multiple points in a function. It also provides a means to add an extra const annotation to the variables that it captures (which I do as much as possible) to make sure that the local function cannot mutate them even when they are mutable in the parent function, which is a feature not provided by C++0x lambdas. I have not used the other features myself, but it also provides local exits (similar to Boost.ScopeExit, but with the ability to bind the object "this" and to add const annotations to the bound variables) and "local blocks" that allow you to essentially put some of your code in a scope where they can only see a subset of the variables in a function. Cheers, Greg