The code below is based on Herb Sutter's ideas of an implementation of a .then() type continuation.
template<typename Fut, typename Work>
auto then(Fut f, Work w)->std::future<decltype(w(f.get()))>
{ return std::async([=] { w(f.get()); }); }
This would be used like auto next = then(f, [](int r) { go_and_use(r); });
or similar.
This is a neat idea, but as it stands will not work (futures are move only and not copyable). I do like the idea as it is likely to appear in upcoming versions of c++ as far as I can guess (although as .then() or even await.)
Before making the futures shared or similar I wonder what the stack overflow community would think of this implementation specifically with improvements and suggestions (even shared futures)?
Thanks in advance for any suggestions.
(I am aware this is a fix till a standards based mechanism exists as it will cost a thread (maybe))).
See Question&Answers more detail:os