Should I put lambda?

If I have a function that defines a lambda, will the lamda “build” every time the function is called? Should I make it static to prevent this?

void func(int x) { static auto lambda = [&x](int y) -> bool { // ... }; } 
+6
source share
1 answer

No, do not make it static, as it captures a local variable by reference.

I have no idea what the cost of building a lambda is. If you suspect this is a performance issue: benchmark.

+6
source

Source: https://habr.com/ru/post/894090/


All Articles