#include #include int main () { int m{5}, n{6}; auto f1 = [](int x)->int{return x + 1;}; // a function that returns x + 1. auto f2 = [m](int x){return x + m;}; // can read m from local context. auto f3 = [=](int x){return x + m + n;}; // can read all local variables from local context. auto f4 = [&m](){++m;}; // access to m by reference - can write. auto f5 = [&](){++m; n--;}; // access to all variables in local context by ref. auto f6 = [&]{++m;}; // the empty parameter list is implicit. std::cout << f1(1) << std::endl; // 2 std::cout << f2(1) << std::endl; // 6 std::cout << f3(1) << std::endl; // 12 f4(); // m becomes 6 f5(); // m becomes 7, n becomes 5 f6(); // m becomes 8 std::cout << "m: " << m << " n: " << n << std::endl; // m: 8 n: 5 }