I am trying implement a class which should be able to store several functions, like int p1(int x) { return ...; } or int p2(int x, int y) { return ...;} and evaluate all of them in the order they were added, just by the call to object(value) . but right now, it's only working for function with one argument. anyone can tell me what I am missing here?
Your problem is dealing with type. A function with a different signature will require a duplicated set of members using what you've shown, headed in the wrong direction because you really need a mechanism that is unconstrained. And that's why I didn't take on the question head on.
I thought the Args... in the std::function<T(T,Args...)> could indicate that I wanted use any number of arguments for the functions? What should be the right way to indicate that then?
then you would instead be able to store functions that takes three arguments (an int, a double and a std::string).
mbozzi wrote:
I'm not sure what you want. Something like this, maybe? ...
Isn't this essentially the same as what he's already got? Except for the different syntax used to specify the return type and parameter types, and the ability to specify the return type and the type of the first parameter independently.