Skip to content

Instantly share code, notes, and snippets.

@xaxxon
Last active December 29, 2015 04:20
Show Gist options
  • Save xaxxon/1683f166b630a87ebe2f to your computer and use it in GitHub Desktop.
Save xaxxon/1683f166b630a87ebe2f to your computer and use it in GitHub Desktop.
#include <list>
template<typename F> class Caller {
public:
F func;
Caller(T func) : func(func) {}
void call(MyClass o, list<int>, Ts... ts) {
o.func(ts...);
}
};
template<typename F, typename RET, typename HEAD, typename TAIL>
class Caller<F, RET(HEAD,TAIL...)> : Caller<T, RET(TAIL...)> {
public:
typedef Caller<RET(TAIL)> super;
typedef HEAD Head;
Caller(F func):super(func) {}
void call(MyClass o, std::list<int> l, Ts... ts) {
HEAD head = l.first;
l.pop_front();
this->super::call(o, list, head, ts...);
}
};
class MyClass {public: void foo(int,int){}};
MyClass my_object;
std::list<int> ints = {1,2};
Caller caller(&MyClass::foo, &MyClass::foo); // I can make a helper to make this better
caller.call(my_object, ints); // this should run my_object.foo(1,2);
@xaxxon
Copy link
Author

xaxxon commented Dec 29, 2015

This code is pseudo-c++ to call a method with parameters presented in a list. Is it anywhere near something that could work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment