How are C++11 lambdas represented and passed?

前端 未结 3 2058
死守一世寂寞
死守一世寂寞 2020-12-14 06:36

Passing a lambda is really easy in c++11:

func( []( int arg ) {
  // code
} ) ;

But I\'m wondering, what is the cost of passing a

3条回答
  •  渐次进展
    2020-12-14 07:04

    See also C++11 lambda implementation and memory model

    A lambda-expression is just that: an expression. Once compiled, it results in a closure object at runtime.

    5.1.2 Lambda expressions [expr.prim.lambda]

    The evaluation of a lambda-expression results in a prvalue temporary (12.2). This temporary is called the closure object.

    The object itself is implementation-defined and may vary from compiler to compiler.

    Here is the original implementation of lambdas in clang https://github.com/faisalv/clang-glambda

提交回复
热议问题