#include #include using namespace std; int main() { bool guard = false; //------------------------------------------------------------- // the capture list [&] means "capture all in scope variables as // references. (The list [=] means capture all as values.) // (The list [=,&guard] means capture all as values, except capture // guard as a reference.) //------------------------------------------------------------- auto f = [&](const vector &lhs, const vector &rhs) -> bool { return guard && lhs.size() < rhs.size(); }; auto g = f; cout << "guard = " << guard << endl; cout << f({1},{2}) << endl; cout << g({1},{1,2}) << endl; guard = true; cout << "guard = " << guard << endl; cout << f({1},{2}) << endl; cout << g({1},{1,2}) << endl; return 0; }