Lambdas are a concise way of creating anonymous functions - when those functions are themselves concise. However, the use of lambdas for sizable
functions can make the code difficult to read. More importantly, following variable capture in lambdas can be difficult, potentially leading to
dangling pointers. Therefore lambdas should be avoided.
Noncompliant code example
int main() {
auto func = [] () { std::cout << "Hello world" << std::endl; };
func();
}
Compliant solution
void func () {
std::cout << "Hello world" << std::endl;
}
int main() {
func();
}