What is lifetime of lambda-derived implicit functors in C++?

前端 未结 1 999
礼貌的吻别
礼貌的吻别 2021-01-02 06:08

The question is simple: what is lifetime of that functor object that is automatically generated for me by the C++ compiler when I write a lambda-expression?

I did a

相关标签:
1条回答
  • 2021-01-02 06:33

    Depends on how you capture your variables. If you capture them by reference ([&]) and they go out of scope, the references will be invalid, just like normal references. Capture them by value ([=]) if you want to make sure they outlife their scope.

    0 讨论(0)
提交回复
热议问题