Skip to content

Instantly share code, notes, and snippets.

@blmarket
Forked from anonymous/gist:5034882
Created February 26, 2013 01:10
Show Gist options
  • Save blmarket/5034891 to your computer and use it in GitHub Desktop.
Save blmarket/5034891 to your computer and use it in GitHub Desktop.
#include <memory>
#include <iostream>
using namespace std;
typedef function<void(int)> func;
shared_ptr<func> create_lambda() {
return make_shared<func>([]() {
int tmp;
return [&tmp](int c) {
cout << tmp++ << endl;
};
}());
}
int main(void) {
shared_ptr<func> normal(create_lambda());
(*normal)(1);
(*normal)(2);
(*normal)(5);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment