Boost logo

Boost Users :

Subject: Re: [Boost-users] future<>.then and promises
From: Klaim - Joël Lamotte (mjklaim_at_[hidden])
Date: 2013-06-27 19:45:12


On Thu, Jun 27, 2013 at 9:01 PM, Vicente J. Botet Escriba <
vicente.botet_at_[hidden]> wrote:

> I guess you need to call fut.then() before the value is set. I will need
> to check if this works when the future is not created with async().

If the callback isn't called when set using then() if the value is already
acquired, I don't see the point of then().
Between the time you retrieve a future from any function returning it and
the time you call then(), the value could have been set.
So I expect ft.then( task ) to call immediately task if the value have
already been set.
Or maybe I didn't understood correctly what you meant?

On a related topic: I just upgraded to the latest SVN and forced Boost to
use decltype as result_of, which fixed a problem already mentionned.
Just in case it is not already known:

1.

   ft.then( []( future<T> f ) { return 42; } );

This will not compile (VS2012U3) because there is an attempt to copy
future<T> (which looks like a bug I reported where returning a future would
trigger copy instead of moving the future, bug fixed since then so I'm a
bit surprise about this one)

2.
  ft.then( []( future<T>& f ) { return 42; } );

This trigger the following warning:

1>e:\projects\sdk\boost\boost\include\boost-1_54\boost\thread\future.hpp(3956):
warning C4715: 'boost::future<aosd::backend::Id<aosd::backend::Project>
>::then<<lambda_f0fec0502a034b6d05aaa9610f9b705e> >' : not all control
paths return a value

Indeed the then() implementation have a series of if-else ending with an
else with assert false forced.
The compiler can't catch the assertion I suppose something have to be
written there after the assertion
to silence the warning.

Joel Lamotte



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net