I ended up doing this for now -
void invoke(void (f)(), list<any>& params)
{
f();
}
template <typename R>
void invoke(R (f)(), list<any>& params)
{
params.push_front(f());
}
template <typename T0>
void invoke(void (f)(T0), list<any>& params)
{
T0 t0 = any_cast<T0>(*params.begin()); params.pop_front();
f(t0);
}
template <typename R, typename T0>
void invoke(R (f)(T0), list<any>& params)
{
T0 t0 = any_cast<T0>(*params.begin()); params.pop_front();
params.push_front(f(t0));
}
template <typename T0, typename T1>
void invoke(void (f)(T0, T1), list<any>& params)
{
T0 t0 = any_cast<T0>(*params.begin()); params.pop_front();
T1 t1 = any_cast<T1>(*params.begin()); params.pop_front();
f(t0, t1);
}
template <typename R, typename T0, typename T1>
void invoke(R (f)(T0, T1), list<any>& params)
{
T0 t0 = any_cast<T0>(*params.begin()); params.pop_front();
T1 t1 = any_cast<T1>(*params.begin()); params.pop_front();
params.push_front(f(t0, t1));
}
template <typename T0, typename T1, typename T2>
void invoke(void (f)(T0, T1, T2), list<any>& params)
{
T0 t0 = any_cast<T0>(*params.begin()); params.pop_front();
T1 t1 = any_cast<T1>(*params.begin()); params.pop_front();
T2 t2 = any_cast<T2>(*params.begin()); params.pop_front();
f(t0, t1, t2);
}
template <typename R, typename T0, typename T1, typename T2>
void invoke(R (f)(T0, T1, T2), list<any>& params)
{
T0 t0 = any_cast<T0>(*params.begin()); params.pop_front();
T1 t1 = any_cast<T1>(*params.begin()); params.pop_front();
T2 t2 = any_cast<T2>(*params.begin()); params.pop_front();
params.push_front(f(t0, t1, t2));
}
I'm lacking the full power of boost::bind - like, I can't handle method pointers - but I also realized that by doing this, I've got a stack processor. I can keep invoking methods that operator on the parameters on the stack.