Creating New Futures
This lesson discusses how one extended future can be attached to another in C++20.
We'll cover the following
C++20 gets four new functions for creating special futures: std::make_ready_future
, std::make_execptional_future
, std::when_all
, and std::when_any
. First, let’s look at the functions std::make_ready_future
, and std::make_exceptional_future
.
std::make_ready_future
and std::make_exceptional_future
Both functions create a future that is immediately ready. In the first case, the future has a value; in the second case, an exception. Therefore, what seems to be strange at first actually makes a lot of sense. In C++11, the creation of a ready future requires a promise. This is necessary even if the shared state is immediately available.
Get hands-on with 1400+ tech skills courses.