mercredi 2 mars 2016

async returns future of void type instead of expected type

I'm learning C++'s futures and asynchronous programming. I have the following code based on that in chapter 42 of Stroustrup's C++ reference. Both GCC and Microsoft compilers complain that there is no conversion from future<void> to future<InputIterator>in the call to push_back. Why is the call to async returning a future<void> instead of a future<std::iterator> that I would expect from std::find?

template<typename T, typename InputIter>
InputIter p_find(InputIter first, InputIter last, const T& value, const int grain)
{
std::vector<std::future<InputIter>> results;
while (first != last)
{
    results.push_back(std::async([=]() mutable {std::find(first, first + grain, value); }));
    first += grain;
}
//blah blah

Aucun commentaire:

Enregistrer un commentaire