I’m trying to figure out how to write this function:
template <typename Bound> Bound::result_type callFromAnyList(Bound b, list<any> p) { }
Then, if I had some function:
double myFunc(string s, int i) { return -3.0; }
I could call it by doing something like this:
list<any> p; p.push_back((string)'Hello'); p.push_back(7); double result = callFromAnyList(bind(myFunc, _1, _2), p);
Is it possible to write something like my callFromAnyList function? Can you inspect the result type and the parameter types from the type returned from bind? And then call any_cast<P1>(*p.begin()), etc? I’ve tried to understand the bind code, but it’s a little hard to follow, and it doesn’t appear as though they wrote it with inspection in mind.
As you updated your concerns in the comment sections, here the answer. Just getting the return type of a function is possible:
I guess you see what this comes down to 🙂 You can use boost function types which already has solved it: http://www.boost.org/doc/libs/1_37_0/libs/function_types/doc/html/index.html