What you want is a monad. std::future is almost, but not quite a monad, but it does not have the ability to correctly compose functions, raising them, as you noticed. See this blog post for more on this.
The summary is that for C ++ 17 an additional method was proposed for std::future : either next or then , which will use a function that will be applied to the future value when it is available. This is roughly equivalent to bind in Haskell, for example (note: not std::bind ).
Let's take two functions:
T foo(int); U bar(T const &);
Here we have the mapping int -> T -> U , you need to raise this mapping to int -> std::future<T> -> std::future<U> . It might look like this:
int x = 2; std::async([=](){return foo(x);}).then(bar);
Where then is a function that automatically maps T -> U to std::future<T> -> std::future<U> .
Disclaimer: I am not a Haskell programmer and understand that I have probably messed up everything. I welcome the corrections.
source share