mercredi 25 février 2015

C++: Map of functions accepting any arguments and return value

Is it possible, and how, can I have a std::map of functions that can take any number of arguments and return any type that can be converted to a std::string?


What I have tried was using std::function but when declaring the std::map I still always had to specify the type of the arguments that the function can allow. e.g. std::map<int,std::function<INT, BOOL>>.


I have also tried multiple variations of variadic functions and derived classes but none seemed to have given me what I need.


I've also seen some lambda examples that I didn't quite understand but still not sure if that was the right approach.


In principle what I am trying to achieve is to have a function of any type or form bound to each key that can be pressed on the keyboard. See image of how I imagined this map visually would look like: link to image When pressing a key, the function corresponding with the colour of the key, must be called.


Aucun commentaire:

Enregistrer un commentaire