This constructor creates a new shared state that becomes satisfied when both rhs and rhs.get() become satisfied. If rhs is satisfied, but rhs.get() returns an invalid future then the newly created future becomes satisfied with a std::future_error exception, and the exception error code is std::future_errc::broken_promise.
Parameter
Name
Description
rhs
future< future< T > > &&
future(future< U > &&)
Creates a future from a future whose result type is convertible to this future's result type.
Parameters
Name
Description
rhs
future< U > &&
class U
typename Enable
future(std::shared_ptr< shared_state_type >)
Parameter
Name
Description
state
std::shared_ptr< shared_state_type >
Functions
get()
Waits until the shared state becomes ready, then retrieves the value stored in the shared state.
Exceptions
Type
Description
...
any exceptions stored in the shared state.
std::future_error
with std::no_state if the future does not have a shared state.
Returns
Type
Description
T
then(F &&)
Attach a continuation to the future.
Attach a callable func to be invoked when the future is ready. The return type is a future wrapping the return type of func.
Side effects: valid() == false if the operation is successful.
Parameters
Name
Description
func
F &&
a Callable to be invoked when the future is ready. The function might be called immediately, e.g., if the future is ready.
typename F
Returns
Type
Description
future< >
future<T> where T is std::result_of_t<F, R> (basically). If T matches future<U> then it returns future<U>. The returned future will contain the result of func.
Type Aliases
shared_state_type
Alias Of: typename internal::future_base< T >::shared_state_type
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-14 UTC."],[[["\u003cp\u003eThe content provides documentation for the \u003ccode\u003efuture\u003c/code\u003e class in the Google Cloud C++ client library, spanning multiple versions from 2.10.1 to the latest release candidate 2.37.0-rc.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003efuture\u003c/code\u003e class implements ISO/IEC TS 19571:2016 \u003ccode\u003efuture<T>\u003c/code\u003e, offering constructors and functions for managing asynchronous operations and their results.\u003c/p\u003e\n"],["\u003cp\u003eA notable constructor allows creating a \u003ccode\u003efuture\u003c/code\u003e that unwraps another \u003ccode\u003efuture<future<T>>\u003c/code\u003e, becoming satisfied when both the outer and inner futures are ready, though this constructor is noted as potentially not being \u003ccode\u003enoexcept\u003c/code\u003e as required by the technical specification.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eget()\u003c/code\u003e function retrieves the value from a shared state after it becomes ready, and it invalidates the future after being called, meaning subsequent calls to \u003ccode\u003eget()\u003c/code\u003e will result in failure.\u003c/p\u003e\n"],["\u003cp\u003eThe function \u003ccode\u003ethen()\u003c/code\u003e allows attaching a continuation to the future, invoking the provided function when the future is ready, returning a new future that encapsulates the result of the provided function.\u003c/p\u003e\n"]]],[],null,[]]