Consider following code
void printPromised(std::future<int> f)
{
std::cout << f.get() << std::endl;
}
int main()
{
printPromised(std::async(std::launch::async, [](){ return 8; })); // This works
auto f = std::async(std::launch::async, [](){ return 8; });
printPromised(f); // This won't work
}
It says "It is a deleted function". Why is that? Further I need to pass (share) the same promised result which std::async
generated to multiple users. That means when someone calls the get() function, I need to pass the same result (I don't need to re generate the result using std::async
if it is already generated) and also I need the blocking mechanism which std::future::get
has.