Please consider the following example:
#include <iostream>
#include <future>
std::size_t calc_something(std::size_t lim_)
{
std::size_t result = lim_ * 10;
return result;
}
void calc_something(std::size_t lim_, std::promise<std::size_t> &promise_)
{
std::size_t result = lim_ * 10;
promise_.set_value(result);
}
void async_calc()
{
std::future<std::size_t> async_calc = std::async(calc_something, 5);
std::cout<< "async_calc = " << async_calc.get() <<std::endl;
}
I am still new to multi-threading, but why -on earth- can't std::async
pick the correct overload? The second overload uses a reference to an std::promise
object.
I've looked at this question here but it doesn't explain why. Also, I do not get an ambiguity error.
The error I get is:
error: no matching function for call to 'async' std::future<std::size_t> async_calc = std::async(calc_something, 5);