class template
<future>

std::shared_future

template <class T>  shared_future;
template <class R&> shared_future<R&>;   // specialization : T is a reference type (R&)
template <>         shared_future<void>; // specialization : T is void
Shared future
A shared_future object behaves like a future object, except that it can be copied, and that more than one shared_future can share ownership over their end of a shared state. They also allow the value in the shared state to be retrieved multiple times once ready.

shared_future objects can be implicitly converted from future objects (see its constructor), or explicitly obtained by calling future::share. In both cases, the future object from which it is obtained transfers its association with the shared state to the shared_future and becomes itself non-valid.

The lifetime of the shared state lasts at least until the last object with which it is associated is destroyed. Retrieving the value from a shared_future (with member get) does not release its ownership over the shared state (unlike with futures). Therefore, if associated to shared_future objects, the shared state can survive the object from which it was obtained in the first place (if any).

Member functions


Template specializations

Two specific shared_future specializations are declared in <future>:
1
2
template <class R&> shared_future<R&>;   // specialization : T is a reference type (R&)
template <>         shared_future<void>; // specialization : T is void 

They operate in the same way as the unspecialized template, except for the return value of their shared_future::get member function.