If the associated state contains a deferred function from a call to
std::async
then invoke that function and return the result, otherwise wait until
the asynchronous result associated with an instance of std::future is ready, and then return
the stored value or throw the stored exception.
void future<void>::get(); R& future<R&>::get(); R future<R>::get();
- Preconditions:
this->valid()would returntrue.- Effects:
-
If the state associated with
*thiscontains a deferred function, invoke the deferred function and return the result or propagate any thrown exception.Otherwise, block until the asynchronous result associated with
*thisis ready. If the result is a stored exception then throw that exception. Otherwise return the stored value. - Returns:
If the associated state contains a deferred function then the result of the function invocation. Otherwise, if
ResultTypeisvoidthen return normally. IfResultTypeisR&for some typeRthen return the stored reference. Otherwise, return the stored value.- Throws:
The exception thrown by the deferred exception, or stored in the asynchronous result, if any.
- Postcondition:
this->valid()==false
Header
#include <future>