public member function
<future>

std::shared_future::get

generic template (1)
const T& get() const;
reference specialization (2)
R& shared_future<R&>::get() const;     // when T is a reference type (R&)
void specialization (3)
void shared_future<void>::get() const; // when T is void
Get value
Returns a reference to the value stored in the shared state (or throws its exception) when the shared state is ready.

If the shared state is not yet ready (i.e., the provider has not yet set its value or exception), the function blocks the calling thread and waits until it is ready.

Once the shared state is ready, the function unblocks and returns (or throws), but does not release its shared state (unlike future::get), allowing other shared_future objects to also access the stored value (or new accesses by the same object).

All visible side effects are synchronized between the point the provider makes the shared state ready and the return of this function, but note that no synchronization exists among the potential multiple functions returning on this event (in case of multiple shared_future objects were waiting for the same shared state).

The member of the void specialization (3) does not return any value, but still waits for the shared state to become ready before returning/throwing.

Parameters

none

Return value

A reference to the value stored in the shared state by its provider.
The lifetime of the referred value extends at least until the last object associated with the shared state releases it or is destroyed.
T is the type of the value in the shared state (i.e., the template parameter of shared_future).

Data races

The shared_future object is accessed.
The shared state is accessed as an atomic operation relative to the previous modifying operation by the provider, but not in relation to multiple accesses from shared_future objects.

Exception safety

The function throws the exception stored in the shared state when the provider makes it ready by setting it to an exception. Note that in this case, a strong guarantee is offered, with the shared_future object remaining unchanged.

Calling this member function on a shared_future object that is not valid, produces undefined behavior (although library implementations may detect this and throw future_error with a no_state error condition).

See also