#pragma once #include struct ContainerBase { virtual void perform() = 0; virtual ~ContainerBase() = default; }; template struct Container : ContainerBase { Lambda m_lambda; Container(Lambda&& lambda) : m_lambda(std::move(lambda)) {} virtual void perform() { m_lambda(); } }; class function { // equivalent to std::function ContainerBase *m_ctr; public: template function(Lambda lambda) : m_ctr(new Container(std::move(lambda))) {} void operator()() { m_ctr->perform(); } ~function() { delete m_ctr; } };