Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <functional>
- #include <iostream>
- struct Receiver {
- void receive(std::function<void()> f) {
- func_ = f;
- }
- std::function<void()> func_;
- };
- void pusher(Receiver& r) {
- auto wrapper=[&](std::function<void()> w) {
- r.receive([w=move(w)]() {
- std::cout << "Before" << std::endl;
- w();
- std::cout << "After" << std::endl;
- });
- };
- wrapper([&]() {
- std::cout << "Original" << std::endl;
- });
- }
- int x= 15;
- int main() {
- std::function<void()> a = [&]() { std::cout << x << std::endl; };
- a();
- x = 20;
- a();
- Receiver r;
- pusher(r);
- r.func_();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement