std::future has been criticized e.g. in this CppCon presentation for being slow. You can avoid std::async and std:future entirely by using this header-only library. You can run any number of functions asynchronously and get the results as a tuple. Also exceptions can be caught normally.
Here is an example:
#include <iostream>
#include "Lazy.h"
template <class T>
T foo(T x) {
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
return x + 10.5;
}
int main() {
int input = 54;
try {
auto [i, d, c] = Lazy::runParallel(
[&](){ return foo(int(input)); },
[&](){ return foo(double(input)); },
[&](){ return foo(char(input)); } );
std::cout << "foo(int) = " << i << ", foo(double) = " << d << ", foo(char) = " << c << '\n';
}
catch (...) {
// Deal with the exception here
}
}
/* Output:
foo(int) = 64, foo(double) = 64.5, foo(char) = @
*/