且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从lambda获取捕获的变量?

更新时间:2023-11-11 13:02:10

这是不可能的设计


5.1.2 [expr.prim.lambda]

15 [ 。]对于通过复制捕获的每个实体,在闭包类型中声明一个未命名的非静态数据成员。这些成员的声明顺序未指定。 [...]

16 [...]未指定在引用捕获的实体的闭包类型中是否声明了其他未命名的非静态数据成员。

5.1.2 [expr.prim.lambda]
15 [...] For each entity captured by copy, an unnamed non-static data member is declared in the closure type. The declaration order of these members is unspecified. [...]
16 [...] It is unspecified whether additional unnamed non-static data members are declared in the closure type for entities captured by reference.

捕获的变量未命名(或至少有名字不可能由凡人说出),并且它们的声明顺序是故意未指定的。

Captured variables are unnamed (or at least have names that are unspeakable by mortals) and their declaration order is deliberately unspecified. By-reference captures may not even exist in the closure type.

您仍然不希望这样做。你可能会认为你做,但你不是真的。

You don't want to do this anyway. You may think you do, but you don't really.