(Visual) C++0xの「λ式」と「型推論」と静的assert

http://blogs.msdn.com/vcblog/archive/2008/10/28/lambdas-auto-and-static-assert-c-0x-features-in-vc10-part-1.aspx
(via 知人)

個人的注目ポイント:

If a lambda's compound-statement is { return expression; } , then the lambda's return type will be automatically deduced to be the type of expression:

Lambdas with more complicated compound-statements don't get automatically deduced return types. You have to explicitly specify them:

You can have stateful lambdas [sumii注:いわゆる「クロージャ」です…] too, and this is accomplished through "capturing" local variables.

If you forget the capture-list, the compiler will complain:

Here, you can clearly see that the captures are "by value".

instead of specifying every local variable that you want to capture, you can say "capture everything by value". The syntax for this is the lambda-introducer [=]

By default, a lambda's function call operator is const, but you can make it non-const by saying mutable:

you want to capture by reference. The syntax for doing this is the lambda-introducer [&x, &y]

Of course, if a lambda function object outlives local variables that it has captured by reference, you get crashtrocity.

Again, you can use default captures; the lambda-introducer [&] says "capture everything by reference".

(以下、注目ポイントがありすぎるので省略)