Skip to content

Instantly share code, notes, and snippets.

@alepez
Created October 4, 2018 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alepez/094fe32835a994873316fa21a80f41fd to your computer and use it in GitHub Desktop.
Save alepez/094fe32835a994873316fa21a80f41fd to your computer and use it in GitHub Desktop.
lambda_on_destructor.cpp
#include <iostream>
#include <memory>
struct Foo {
Foo(std::function<void()>&& fun) : f{std::move(fun)} { }
~Foo() { f(); }
std::function<void()> f;
};
int main() {
const Foo t([]() { std::cerr << "Arrivederci\n"; });
std::cerr << "Buongiorno!\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment