Le 28/06/13 01:45, Klaim - Joël Lamotte a écrit :

On Thu, Jun 27, 2013 at 9:01 PM, Vicente J. Botet Escriba <vicente.botet@wanadoo.fr> 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.
Sorry, I was wrong and there is an issue with the implementation.

When I fix it, the continuation would not be called immediately but as the doc states it should

"- If the parent was created with promise<< or with a packaged_task<> (has no associated launch policy), the continuation behaves the same as the third overload with a policy argument of launch::async | launch::deferred and the same argument for func.
"



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)

Currently the prototype of a continuation takes a future by reference, but I could change it to by value (which need to move the future.
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.

This is associate to the issue of the current implementation. Instead of asserting the code should be

      return boost::detail::make_future_async_continuation_shared_state<BOOST_THREAD_FUTURE<R>, future_type, F>(
          lock, *this, boost::forward<F>(func)
      );

Best,
Vcente