If I have a function that defines a lambda, will the lamda be ‘constructed’ every time the function is called? Should I make it static to prevent that?
void func(int x)
{
static auto lambda = [&x](int y) -> bool {
// ...
};
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, don’t make it static, as it captures a local variable by reference.
I have no idea what the cost of constructing a lambda is. If you suspect it to be a performance problem: benchmark.