Lambda 表示式

lambda 只能有一個尾隨返回型別; 前導返回型別語法不適用於 lambdas。請注意,在許多情況下,根本不需要為 lambda 指定返回型別。

struct Base {};
struct Derived1 : Base {};
struct Derived2 : Base {};
auto lambda = [](bool b) -> Base* { if (b) return new Derived1; else return new Derived2; };
// ill-formed: auto lambda = Base* [](bool b) { ... };