vicente.botet | 15 Jan 18:47
Picon

Re: Futures - wait callback with a user specific parameter.

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

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost


Gmane