mercredi 24 mai 2017

boost::future .then() continuations returning boost::future

I was reading the new C++ proposal regarding improvements to std::future and std::promise here http://ift.tt/1TrxLEv and it says

It is a common situation that the body of a then function object will itself be a future-based operation, which leads to the then() returning a future>. In this case, it is almost always the case that what you really care about is the inner future, so then() performs an implicit unwrap() (see below) before returning.

Therefore in the following code

auto promise = std::promise<int>{};
auto another_future = promise.get_future().then([](auto future) {
    return std::async([]() { return 1; });
});

the type of another_future is std::future<int> and not std::future<std::future<int>>

I was trying to use boost::future to achieve the same thing but it seems like boost continuations do not implicitly unwrap the future. Is there something I can do to enable the same behavior from boost futures? It seems like there is no unwrap() function available to use on the resulting feature either.

Am I stuck with having to unwrap the future via a constructor manually? Also on trying that I get the following error, what should I do?

inline explicit BOOST_THREAD_FUTURE(
    BOOST_THREAD_RV_REF(
        BOOST_THREAD_FUTURE<BOOST_THREAD_FUTURE<R> >) other); // EXTENSION

Aucun commentaire:

Enregistrer un commentaire