$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [boost] Futures - wait callback with a user specific parameter.
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2009-01-15 12:47:41
Hi,
Currently the wait callback parameter is either a promise or packaged_task
template<typename F>
void set_wait_callback(F f);
prom.set_wait_callback(f); // will call f(&prom)
task.set_wait_callback(f); // will call f(&task)
I would like to have a wait callback with a user specific parameter.
template<typename F,typename U>
void set_wait_callback(F f,U* u); // will call f(u)
prom.set_wait_callback(f, x); // will call f(x)
The use case is a class that contains a promise and wants to provide a set_wait_callback. Which parameter will have the wait calback? A promise. But the user is not aware that my class has promise, and he will surely want to have as parameter a pointer to my class. So the simpler is to provide a user specific parameter that is defaulted to instance providing the wait_callback setting.
Of course my class can wrap the user function and the class instance
template <typename R>
class X {
template <typename F>
static void wait_callback_wrapper(promise<R>* p, F f, X*x) {
f(x);
}
template<typename F>
void set_wait_callback(F f) {
prom_.set_wait_callback(bind(wait_callback_wrapper, _1, f, this));
}
};
But this implies much more resources, two binds instead of one.
Could this be added without to much trouble?
Thanks,
Vicente