when_all for different task types

Jun 26, 2015 at 9:11 AM
Edited Jun 26, 2015 at 5:53 PM
What is the best way to wait for multiple tasks with different types?
How to put them in a vector?
Use boost variants, shared_ptr, ... ?
std::vector<pplx::task<???>> tasks;
pplx::task<T1> t1 = ...
pplx::task<T2> t2 = ...
pplx::task<std::vector<???>> result =  pplx::when_all(tasks.begin(), tasks.end());
Jun 26, 2015 at 10:36 PM
If you would like to use boost variants, you could do something like
using V = boost::variant<T1, T2>;
std::vector<pplx::task<V>> tasks;
pplx::task<T1> t1 = ...
pplx::task<T2> t2 = ...
tasks.push_back(t1.then([](T1& t) { return V(t); });
tasks.push_back(t2.then([](T2& t) { return V(t); });
pplx::task<std::vector<V>> result = pplx::when_all(tasks.begin(), tasks.end());
result.then([](std::vector<V>& v)
// In here, we know that v[0] will be a T1 and v[1] will be a T2
Jun 27, 2015 at 12:11 PM
Edited Jun 27, 2015 at 12:12 PM
Thanks for the suggestion!

Jun 29, 2015 at 8:52 PM
Hi Andy,

There isn't any way to do so with the library currently without writing some code yourself. In addition to what roschuma suggested, I noticed the PPL power pack has a heterogeneous when_all that works with tuples. I'm not sure what it would take to integrate it but perhaps you can use it with your project.