vendredi 27 novembre 2015

How to implement a generic vector of functions?

I would like to implement something of this sort, and I don't think it's supported by the language.

std::vector<std::function<void(ANY TYPE)>> = v;

We have:

void f1(A*){}
void f2(B*){}

Then

v[0] = std::bind(f1,_1);
v[1] = std::bind(f2,_1);

Then

A* a = new A;
v[0](a);

B* b = new B;
v[1](b);

Is there any construct in C++ that will allow me to do something like this?

Aucun commentaire:

Enregistrer un commentaire