Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <functional>
- struct LogicImpl1
- {
- int some_result()
- {
- return 10;
- }
- };
- struct LogicImpl2
- {
- std::string some_result()
- {
- return "ten";
- }
- };
- struct Test
- {
- template<typename Logic>
- void set_logic(Logic logic)
- {
- logic_functor = [logic = std::move(logic)]() mutable
- {
- std::cout << logic.some_result() << std::endl;
- };
- }
- void imagine_async_action()
- {
- logic_functor();
- }
- std::function<void()> logic_functor;
- };
- int main()
- {
- Test t;
- t.set_logic(LogicImpl1{});
- t.imagine_async_action();
- t.set_logic(LogicImpl2{});
- t.imagine_async_action();
- t.set_logic(LogicImpl1{});
- t.imagine_async_action();
- return 0;
- }
Add Comment
Please, Sign In to add comment