Created
October 4, 2018 14:35
-
-
Save alepez/094fe32835a994873316fa21a80f41fd to your computer and use it in GitHub Desktop.
lambda_on_destructor.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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