HPX - High Performance ParalleX


Function template when_some



// In header: <hpx/lcos/when_some.hpp>

template<typename... T> 
  future< when_some_result< tuple< future< T >...> > > 
  when_some(std::size_t n, T &&... futures);


The function when_some 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 n of them finished executing.

[Note] Note

The future returned by the function when_some becomes ready when at least n argument futures have become ready.

[Note] 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_some will not throw an exception, but the futures held in the output collection may.



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


[in] The number of futures out of the arguments which have to become ready in order for the returned future to get ready.


Returns a when_some_result holding the same list of futures as has been passed to when_some and an index pointing to a ready future..

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

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