#include <iostream>
#include <memory>
#include <vector>
#include <functional>
using namespace std;

class Strategy; 
struct ScheduledEvent {
	function<void(Strategy*)> tocall; 
	void perform(Strategy*u) { tocall(u); }
	ScheduledEvent(function<void(Strategy*)> func) : tocall(func) { }
};

class Strategy {
	vector<unique_ptr<ScheduledEvent>> heap_eventlist;
public: 
	void schedule_function(function<void(Strategy*)> func) {
    	// Puts the scheduled event built with the strategy function onto a list
    	heap_eventlist.emplace_back(std::make_unique<ScheduledEvent>(func));
	}
	void do_it() {
		for (auto &x:heap_eventlist) 
			x->perform(this);
	}
    virtual void f() { cout <<"Strategy"<<endl; }
};

struct BasicAlgo : Strategy {
	string b="BasicAlgo";
    void ff() { cout << b<<endl; }
};


int main() {
	BasicAlgo g;
	g.schedule_function (&BasicAlgo::f);
	g.schedule_function ([](Strategy *x)->void { BasicAlgo*b=dynamic_cast<BasicAlgo*>(x); if (b) b->ff(); });
    g.do_it(); 

	return 0;
}