[cfe-dev] status of lambda expression implementation

M.E. O'Neill oneill at cs.hmc.edu
Tue Sep 20 00:34:49 PDT 2011


Shawn Erickson wrote:
> Has the C++11 status page been updated with the current status of this work (and other C++11 related work).

I can't help being at least a little frustrated at the slow progress of lambda support.  It seems like the it's a super-low priority for the Apple folks (who are some of the most prolific clang contributors), and is instead being left to other people who are working on it slowly, as a hobby project.

This is a shame because other compilers (Microsoft C++, GNU G++) have lambda support already, and lots of people seem to be advocating lambda use as the "modern C++ way" (e.g., Herb Sutter's talk at //build/ (*) -- video here: http://channel9.msdn.com/Events/BUILD/BUILD2011/TOOL-835T ).  

		(*) Shouldn't it have been \\build\	;-)

It's especially strange, since it feels to me like it really shouldn't be so hard to give users *something*.  What tantalizes me is that if you use blocks syntax, you can have something that actually (kinda-sorta) works *today*.

unix% cat > feeling-blocked.cpp
#include <list>
#include <string>
#include <iostream>
#include <algorithm>

int main(int argc, const char** argv)
{
    std::list<std::string> args(argv+1, argv+argc);
    std::for_each(args.begin(), args.end(), ^(const std::string& s) {
        std::cout << s << std::endl;
    });
    return 0;
}
^D
unix% clang++ -std=c++0x -stdlib=libc++ -Wall -o feeling-blocked feeling-blocked.cpp 
unix% ./feeling-blocked Oh for some lambda love.
Oh
for
some
lambda
love.

So, I could get by writing code like this:

#if __APPLE__
    #define LAMBDA ^
#else
    #define LAMBDA []
#endif

But it would be *so* much nicer if I didn't have to.

    M.E.O.





More information about the cfe-dev mailing list