std::experimental::when_any
combines a collection of futures
into a single future that becomes ready when any of
the futures in the set become ready. For this overload, the collection
of futures is supplied as an iterator range.
template<typename Iterator> std::experimental::future<std::experimental::when_any_result< std::vector<typename std::iterator_traits<Iterator>::value_type> > > when_any(Iterator begin,Iterator end);
std::iterator_traits<Iterator>::value_type
is an instantiation
of either std::experimental::future
or std::experimental::shared_future
. For each
value in the range [begin
,end
) a call to valid()
must return true
.
The futures in the supplied range are transferred into internal storage.
The asynchronous result associated with each future is marked so
that when any of the futures are ready the future
returned from when_any
is ready. If any of the futures are already
ready at the point of the call, the returned
future will also be ready. If std::iterator_traits<Iterator>::value_type
is an instantiation
of std::experimental::future
, then the futures
are moved into the internal storage, otherwise they are copied.
A std::experimental::future<std::experimental::when_any_result<std::vector<std::iterator_traits<Iterator>::value_type>
> >
which becomes ready when any of the futures
in the supplied range becomes ready. When the
future is ready, the stored value's sequence
member is a std::vector
holding the supplied futures
in the same order they were present in the original sequence, and
the index
member
holds the index of the future that caused the result to become 'ready.
The marking of the first future as ready synchronizes
with any call to wait()
or get()
on the returned future that sees
the result as ready.
std::bad_alloc
if the required internal
storage cannot be allocated.
#include <experimental/future>