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