Created
June 11, 2017 01:24
-
-
Save sat0b/81d18b30f92b53cfcf81d7e70711f23e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #include <iostream> | |
| using namespace std; | |
| template<typename Func> | |
| void call_f(Func f) { | |
| f(); | |
| } | |
| void hello () { | |
| cout << "hello wrold" << endl; | |
| } | |
| int main() { | |
| // lambda expressions | |
| auto l_hello = []{cout << "hello world" << endl;}; | |
| cout << "1 : "; | |
| l_hello(); | |
| // callback | |
| cout << "2 : "; | |
| call_f(hello); | |
| cout << "3 : "; | |
| call_f(l_hello); | |
| // generic lambda expressions | |
| auto plus = [](auto a, auto b) { | |
| return a + b; | |
| }; | |
| cout << "4 : "; | |
| cout << plus(1, 2) << endl; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment