I want to make a "function proxy" that:
And for now, my problem is how (and is it even possible) to create this (functor) class using template teq, and pass the unknown argument list to bind.
Thanks in advance.
template<typename R, typename... ARGS>
class Proxy {
typedef std::function<R(ARGS...)> Function;
Function f;
public:
Proxy(Function _f) : f(_f) {}
R operator(ARGS... args) {
std::function<R> bound = std::bind(f, args...);
send_to_worker_thread(bound);
wait_for_worker_thread();
return worker_thread_result();
}
};
// Because we really want type deduction
template<typename R, typename... ARGS>
Proxy<R,ARGS...>* newProxy(R(*x)(ARGS...)) {
return new Proxy(std::function<R,ARGS...>(x);
}
I haven't actually tested this.
You'll probably want something asynchronous, but I'll leave that to you.