
----- Original Message ----- From: "Anthony Williams" <anthony_w.geo@yahoo.com> To: <boost@lists.boost.org> Sent: Tuesday, May 13, 2008 10:03 PM Subject: Re: [boost] Review Request: future library : what does futureofreferences exactly means?
"vicente.botet" <vicente.botet@wanadoo.fr> writes:
Well let me come back to my initial example. Supose that I had Result f(InOut& ref); // ... { InOut v=0; // ... v = 13; Result r = f(v); // ... use r or v; g(r, v); v = 15; }
Do you mean that the following works with your proposal?
unique_future<Result> f(shared_future<InOut>& ref); // ... { shared_future<InOut> v; v->get()=0; // ... v->get() = 13; unique_future<Result> r = f(v); // ... use r or v; g(r->get(), v->get()); v->get() = 15; }
Not quite. You can't set a value on a future by writing to the result of a call to get() - you need a promise or a packaged task for that. However, you can write:
void foo() { promise<InOut> p; shared_future<InOut> v=p.get_future(); p.set_value(13);
unique_future<Result> r=f(v);
// v.get() may have changed if f took v by reference g(r.get(),v.get()); }
Sorry, this is exactly the behaviour I wanted to refactor. Thanks Vicente