fork download
  1. #include <iostream>
  2. int main() {
  3. auto&& function = [](int i0) {
  4. int i = i0;
  5. return [=]() mutable { i *= 2; return i;};
  6. };
  7. auto fn = function(5);
  8. for ( unsigned long i = 0; i != 10; ++i )
  9. std::cout << "\t" << fn() << "\t|";
  10. std::cout << "\n";
  11. return 0;
  12. }
Success #stdin #stdout 0.01s 5236KB
stdin
Standard input is empty
stdout
	10	|	20	|	40	|	80	|	160	|	320	|	640	|	1280	|	2560	|	5120	|