Last active
January 27, 2016 15:13
-
-
Save MizukiSonoko/5e334be83e6991e00ceb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function<int(int)> g(function<int(int)> f){ | |
cout << " exec g !\n"; | |
return [f](int x) -> int { | |
cout<< " exec g return lambda! "<< x << endl; | |
return f(x + 1); | |
}; | |
} | |
void e(function<int(int)> F){ | |
cout<< " exec e !\n"; | |
F(1); | |
} | |
void sandbox(){ | |
cout << "(1)\n"; | |
auto F1 = | |
g( | |
g([](int x){ | |
cout <<" exec g argv lambda! "<< x << endl; | |
return x + 1; | |
}) | |
); | |
auto F2 = [F1](int x){ | |
cout << " exec F2 lambda! "<< x << endl; | |
return F1(x); | |
}; | |
cout << "(2)\n"; | |
e(F2); | |
auto F3 = [f = F2(5)](int x){ | |
cout << " exec F3 lambda! "<< x << endl; | |
return f; | |
}; | |
cout << "(3)\n"; | |
e(F3); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(1) | |
exec g ! | |
exec g ! | |
(2) | |
exec e ! | |
exec F2 lambda! 1 | |
exec g return lambda! 1 | |
exec g return lambda! 2 | |
exec g argv lambda! 3 | |
exec F2 lambda! 5 | |
exec g return lambda! 5 | |
exec g return lambda! 6 | |
exec g argv lambda! 7 | |
(3) | |
exec e ! | |
exec F3 lambda! 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment