1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| // 串行组合
template<typename F, typename G>
auto then(std::future<F>&& f, G&& g) {
return std::async(std::launch::async, [f = std::move(f), g = std::forward<G>(g)]() mutable {
return g(f.get());
});
}
// 并行组合
template<typename F, typename G>
auto both(std::future<F>&& f, std::future<G>&& g) {
return std::async(std::launch::async, [f = std::move(f), g = std::move(g)]() mutable {
auto result_f = f.get();
auto result_g = g.get();
return std::make_pair(result_f, result_g);
});
}
|