jeudi 22 janvier 2015

store closures in an array

I would like to store some closures in an array. I tagged the question MSVC10 since it seems that according to c++11 closures should be compatible (at least under some conditions) with function pointers but MSVC10 does not supports that.


Is there a way around this limitation?


example:



typedef double (*Func)(const C* c);

struct Feature{
Feature(FeatureId i_id = None, const QString& i_name=QString(), Func i_ex = nullptr)
:id(i_id),name(i_name), extraction(i_ex)
{}
FeatureId id;
QString name;
Func extraction;
};

QList<Feature> features;

features.append(Feature(feat_t, "a/t", [](const C* c) -> double{return c->a.t;} ));


I want to be able to assign closures to the function pointer because i do not want to define dozens of separate functions.


Thanks in advance for your suggestions.


Aucun commentaire:

Enregistrer un commentaire