fork download
  1. #include <iostream>
  2. #include <functional>
  3.  
  4. int main() {
  5. std::function<int()> xs[10];
  6. for (int i = 0; i < 10; i++) {
  7. xs[i] = [&i]() { return i; };
  8. }
  9. std::cout << xs[5]() << std::endl;
  10. return 0;
  11. }
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
10