さまざまなタイプのタスクで PPL "when_all" を使用したいと思います。そして、そのタスクに「then」呼び出しを追加します。
ただし、 when_all はベクトルを取るタスクを返すため、すべての要素が同じ型である必要があります。では、これを行うにはどうすればよいですか?
これは私が思いついたものですが、ちょっとしたハックのように感じます:
//3 different types:
int out1;
float out2;
char out3;
//Unfortunately I cant use tasks with return values as the types would be different ...
auto t1 = concurrency::create_task([&out1](){out1 = 1; }); //some expensive operation
auto t2 = concurrency::create_task([&out2](){out2 = 2; }); //some expensive operation
auto t3 = concurrency::create_task([&out3](){out3 = 3; }); //some expensive operation
auto t4 = (t1 && t2 && t3); //when_all doesnt block
auto t5 = t4.then([&out1, &out2, &out3](){
std::string ret = "out1: " + std::to_string(out1) + ", out2: " + std::to_string(out2) + ", out3: " + std::to_string(out3);
return ret;
});
auto str = t5.get();
std::cout << str << std::endl;
誰かがより良いアイデアを得ましたか?
(parallel_invokeブロックなので使いたくない)