Skip to content

Instantly share code, notes, and snippets.

@sat0b
Created June 11, 2017 01:24
Show Gist options
  • Select an option

  • Save sat0b/81d18b30f92b53cfcf81d7e70711f23e to your computer and use it in GitHub Desktop.

Select an option

Save sat0b/81d18b30f92b53cfcf81d7e70711f23e to your computer and use it in GitHub Desktop.
#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