Documentation Home >> Headers >> <jss/experimental_future.hpp> Header >> std::experimental::when_all function template (iterator overload)

std::experimental::when_all combines a collection of futures into a single future that becomes ready when all 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::vector<typename std::iterator_traits<Iterator>::value_type> >
when_all(Iterator begin,Iterator end);

Preconditions:

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.

Effects:

The futures in the supplied range are transferred into internal storage. The asynchronous result associated with each future is marked so that when all of the futures are ready the future returned from when_all is ready. If all 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.

Returns:

A std::experimental::future<std::vector<std::iterator_traits<Iterator>::value_type> > which becomes ready when all of the futures in the supplied range becomes ready. When the future is ready, the stored value is a std::vector holding the supplied futures in the same order they were present in the original sequence.

Synchronization:

The marking of each of the futures as ready synchronizes with any call to wait() or get() on the returned future that sees the result as ready.

Throws:

std::bad_alloc if the required internal storage cannot be allocated.

Header

#include <experimental/future>

See Also