Consider http://en.cppreference.com/w/cpp/experimental/when_any. The following is just a naive and simplified implementation:
#include <future>
template<typename Iterator>
auto when_any(Iterator first, Iterator last)
{
while (true)
{
for (auto pos = first; pos != last; ++pos)
{
if (pos->is_ready())
{
return std::move(*pos);
}
}
}
}
I am not satisfied because it is a busy polling in an infinite loop.
Is there a way to avoid busy polling?