i have bunch of static functions using in async call , passing string x function.
std::future<void> f1 = std::async(std::launch::async, f001, x); std::future<void> f2 = std::async(std::launch::async, f002, x); std::future<void> f3 = std::async(std::launch::async, f003, x); and calling on each.
f1.get(); f2.get(); f3.get(); if consider have ten functions , doing same looks repetitive me.
i tried create list of function pointers , called above functions, following.
std::vector<void (*) (std::string)> funs; funs.push_back(foo1); funs.push_back(foo2); funs.push_back(foo3); std::vector<std::future<void>> tasks for(auto& t : temp ){ task.push_back(std::async(std::launch::async, t, x);) } for(auto task : tasks){ task.get(); } but giving me errors delete functions , similar.
is there better way of doing this.
thanks
you have take tasks reference:
for(auto& task : tasks){ task.get(); } you should have seen related future(const future&) = delete; in error message.
Comments
Post a Comment