Skip to content

Instantly share code, notes, and snippets.

@eagafonov
Last active January 4, 2016 08:39
Show Gist options
  • Save eagafonov/8596834 to your computer and use it in GitHub Desktop.
Save eagafonov/8596834 to your computer and use it in GitHub Desktop.
Some C++11 magic
#include <iostream>
#include <functional>
using namespace std;
std::function<int()> getProc() {
static int a = 0;
auto p1 = [&]() {
a++;
};
auto p2 = [&]() {
a++;
};
return [&]() {p1(); p2(); return a;};
}
int main()
{
auto p = getProc();
std::cout << p() << std::endl;
std::cout << p() << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment