hpx/async_combinators/when_all.hpp#

See Public API for a list of names and headers that are part of the public HPX API.

namespace hpx

Functions

template<typename InputIter, typename Container = vector<future<typename std::iterator_traits<InputIter>::value_type>>>
hpx::future<Container> when_all(InputIter first, InputIter last)#

The function when_all is an operator allowing to join on the result of all given futures. It AND-composes all future objects given and returns a new future object representing the same list of futures after they finished executing.

Note

Calling this version of when_all where first == last, returns a future with an empty container that is immediately ready. Each future and shared_future is waited upon and then copied into the collection of the output (returned) future, maintaining the order of the futures in the input collection. The future returned by when_all will not throw an exception, but the futures held in the output collection may.

Parameters
  • first – [in] The iterator pointing to the first element of a sequence of future or shared_future objects for which when_all should wait.

  • last – [in] The iterator pointing to the last element of a sequence of future or shared_future objects for which when_all should wait.

Returns

Returns a future holding the same list of futures as has been passed to when_all.

  • future<Container<future<R>>>: If the input cardinality is unknown at compile time and the futures are all of the same type. The order of the futures in the output container will be the same as given by the input iterator.

template<typename Range>
hpx::future<Range> when_all(Range &&values)#

The function when_all is an operator allowing to join on the result of all given futures. It AND-composes all future objects given and returns a new future object representing the same list of futures after they finished executing.

Note

Calling this version of when_all where the input container is empty, returns a future with an empty container that is immediately ready. Each future and shared_future is waited upon and then copied into the collection of the output (returned) future, maintaining the order of the futures in the input collection. The future returned by when_all will not throw an exception, but the futures held in the output collection may.

Parameters

values – [in] A range holding an arbitrary amount of future or shared_future objects for which when_all should wait.

Returns

Returns a future holding the same list of futures as has been passed to when_all.

  • future<Container<future<R>>>: If the input cardinality is unknown at compile time and the futures are all of the same type.

template<typename ...T>
hpx::future<hpx::tuple<hpx::future<T>...>> when_all(T&&... futures)#

The function when_all is an operator allowing to join on the result of all given futures. It AND-composes all future objects given and returns a new future object representing the same list of futures after they finished executing.

Note

Each future and shared_future is waited upon and then copied into the collection of the output (returned) future, maintaining the order of the futures in the input collection. The future returned by when_all will not throw an exception, but the futures held in the output collection may.

Parameters

futures – [in] An arbitrary number of future or shared_future objects, possibly holding different types for which when_all should wait.

Returns

Returns a future holding the same list of futures as has been passed to when_all.

  • future<tuple<future<T0>, future<T1>, future<T2>…>>: If inputs are fixed in number and are of heterogeneous types. The inputs can be any arbitrary number of future objects.

  • future<tuple<>> if when_all is called with zero arguments. The returned future will be initially ready.

template<typename InputIter, typename Container = vector<future<typename std::iterator_traits<InputIter>::value_type>>>
hpx::future<Container> when_all_n(InputIter begin, std::size_t count)#

The function when_all_n is an operator allowing to join on the result of all given futures. It AND-composes all future objects given and returns a new future object representing the same list of futures after they finished executing.

Note

As long as ec is not pre-initialized to hpx::throws this function doesn’t throw but returns the result code using the parameter ec. Otherwise it throws an instance of hpx::exception.

Note

None of the futures in the input sequence are invalidated.

Parameters
  • begin – [in] The iterator pointing to the first element of a sequence of future or shared_future objects for which wait_all_n should wait.

  • count – [in] The number of elements in the sequence starting at first.

Throws

This – function will throw errors which are encountered while setting up the requested operation only. Errors encountered while executing the operations delivering the results to be stored in the futures are reported through the futures themselves.

Returns

Returns a future holding the same list of futures as has been passed to when_all_n.

  • future<Container<future<R>>>: If the input cardinality is unknown at compile time and the futures are all of the same type. The order of the futures in the output vector will be the same as given by the input iterator.