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) { ... };