Boost logo

Boost :

From: Anthony Williams (anthony_w.geo_at_[hidden])
Date: 2008-05-13 16:03:30


"vicente.botet" <vicente.botet_at_[hidden]> 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());
}

Anthony

-- 
Anthony Williams            | Just Software Solutions Ltd
Custom Software Development | http://www.justsoftwaresolutions.co.uk
Registered in England, Company Number 5478976.
Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk