Skip to content

Instantly share code, notes, and snippets.

@hadronized
Last active March 22, 2017 23:11
Show Gist options
  • Save hadronized/e93463fb3e7cfe9bd6c67e56ccbace5a to your computer and use it in GitHub Desktop.
Save hadronized/e93463fb3e7cfe9bd6c67e56ccbace5a to your computer and use it in GitHub Desktop.
// g++ main.cpp -std=c++17 -W -Wall -pedantic
#include <cstdlib>
#include <cstdint>
#include <functional>
auto foo() -> std::function<void ()> {
int32_t a = 317;
return [&a]() {
printf("%d", a);
};
}
auto foo_move() -> std::function<void ()> {
int32_t a = 317;
return [&a]() {
printf("%d", a);
};
}
int main() {
auto closure = foo();
closure();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment