Documentation Home >> Headers >> <future> Header >> jss::when_any function template

jss::when_any combines a set of futures into a single future that becomes ready when any of the futures in the set become ready. The return type and semantics are subtly different to the Concurrency TS specification. For the Concurrency TS version, see the std::experimental::when_any function template and std::experimental::when_any function template (iterator overload) documentation.

template<typename ... FutureTypes>
std::future<std::tuple<FutureTypes...> >
when_any(FutureTypes&&... futures);


Each type in FutureTypes is an instantiation of either std::future or std::shared_future. For each value in futures a call to valid() must return true. Any future which is an instantation of std::future must be passed as an rvalue.


The supplied futures 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.


A std::future<std::tuple<FutureTypes> > which becomes ready when any of the supplied futures becomes ready. When the future is ready, the stored value is a std::tuple holding the supplied futures.


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.


On compilers that don't support variadic templates, an overloaded set of function templates is provided that supports passing of up to 5 arguments.


On compilers that don't provide std::tuple, jss::tuple is used instead. The macro _JSS_STD_TUPLE is defined to either std::tuple or jss::tuple as appropriate.


#include <future>

See Also