This constructor creates a new shared state that becomes satisfied when bothrhsandrhs.get()become satisfied. Ifrhsis satisfied, butrhs.get()returns an invalid future then the newly created future becomes satisfied with astd::future_errorexception, and the exception error code isstd::future_errc::broken_promise.
Note:The technical specification requires this to be anoexceptconstructor I (coryan) believe this is a defect in the technical specification, as thiscreatesa new shared state: shared states are dynamically allocated, and the allocator (which might be the defaultoperator new) may raise.
Parameter
Name
Description
rhs
future< future< T > > &&
future
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
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.
Note:This operation invalidates the future, subsequent calls will fail, the application should capture the returned value because it would.
Returns
Type
Description
T
then
Attach a continuation to the future.
Attach a callablefuncto be invoked when the future is ready. The return type is a future wrapping the return type offunc.
Side effects:valid() == falseif 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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[[["\u003cp\u003eThe document details various versions of the \u003ccode\u003efuture\u003c/code\u003e class, spanning from version 2.10.1 up 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 and provides constructors for creating new futures, including those that unwrap another future or are built from a shared state.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eget()\u003c/code\u003e function retrieves the value stored in the shared state once it's ready, and the operation will invalidate the future such that subsequent calls will fail.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003ethen()\u003c/code\u003e function enables attaching a callable to be invoked when the future is ready, potentially being called immediately, and returns a future wrapping the return type of the attached callable function.\u003c/p\u003e\n"]]],[],null,["# Class google::cloud::future (2.10.1)\n\nVersion 2.10.1keyboard_arrow_down\n\n- [2.42.0-rc (latest)](/cpp/docs/reference/common/latest/classgoogle_1_1cloud_1_1future)\n- [2.41.0](/cpp/docs/reference/common/2.41.0/classgoogle_1_1cloud_1_1future)\n- [2.40.0](/cpp/docs/reference/common/2.40.0/classgoogle_1_1cloud_1_1future)\n- [2.39.0](/cpp/docs/reference/common/2.39.0/classgoogle_1_1cloud_1_1future)\n- [2.38.0](/cpp/docs/reference/common/2.38.0/classgoogle_1_1cloud_1_1future)\n- [2.37.0](/cpp/docs/reference/common/2.37.0/classgoogle_1_1cloud_1_1future)\n- [2.36.0](/cpp/docs/reference/common/2.36.0/classgoogle_1_1cloud_1_1future)\n- [2.35.0](/cpp/docs/reference/common/2.35.0/classgoogle_1_1cloud_1_1future)\n- [2.34.0](/cpp/docs/reference/common/2.34.0/classgoogle_1_1cloud_1_1future)\n- [2.33.0](/cpp/docs/reference/common/2.33.0/classgoogle_1_1cloud_1_1future)\n- [2.32.0](/cpp/docs/reference/common/2.32.0/classgoogle_1_1cloud_1_1future)\n- [2.31.0](/cpp/docs/reference/common/2.31.0/classgoogle_1_1cloud_1_1future)\n- [2.30.0](/cpp/docs/reference/common/2.30.0/classgoogle_1_1cloud_1_1future)\n- [2.29.0](/cpp/docs/reference/common/2.29.0/classgoogle_1_1cloud_1_1future)\n- [2.28.0](/cpp/docs/reference/common/2.28.0/classgoogle_1_1cloud_1_1future)\n- [2.27.0](/cpp/docs/reference/common/2.27.0/classgoogle_1_1cloud_1_1future)\n- [2.26.0](/cpp/docs/reference/common/2.26.0/classgoogle_1_1cloud_1_1future)\n- [2.25.1](/cpp/docs/reference/common/2.25.1/classgoogle_1_1cloud_1_1future)\n- [2.24.0](/cpp/docs/reference/common/2.24.0/classgoogle_1_1cloud_1_1future)\n- [2.23.0](/cpp/docs/reference/common/2.23.0/classgoogle_1_1cloud_1_1future)\n- [2.22.1](/cpp/docs/reference/common/2.22.1/classgoogle_1_1cloud_1_1future)\n- [2.21.0](/cpp/docs/reference/common/2.21.0/classgoogle_1_1cloud_1_1future)\n- [2.20.0](/cpp/docs/reference/common/2.20.0/classgoogle_1_1cloud_1_1future)\n- [2.19.0](/cpp/docs/reference/common/2.19.0/classgoogle_1_1cloud_1_1future)\n- [2.18.0](/cpp/docs/reference/common/2.18.0/classgoogle_1_1cloud_1_1future)\n- [2.17.0](/cpp/docs/reference/common/2.17.0/classgoogle_1_1cloud_1_1future)\n- [2.16.0](/cpp/docs/reference/common/2.16.0/classgoogle_1_1cloud_1_1future)\n- [2.15.1](/cpp/docs/reference/common/2.15.1/classgoogle_1_1cloud_1_1future)\n- [2.14.0](/cpp/docs/reference/common/2.14.0/classgoogle_1_1cloud_1_1future)\n- [2.13.0](/cpp/docs/reference/common/2.13.0/classgoogle_1_1cloud_1_1future)\n- [2.12.0](/cpp/docs/reference/common/2.12.0/classgoogle_1_1cloud_1_1future)\n- [2.11.0](/cpp/docs/reference/common/2.11.0/classgoogle_1_1cloud_1_1future)\n- [2.10.1](/cpp/docs/reference/common/2.10.1/classgoogle_1_1cloud_1_1future) \nImplement ISO/IEC TS 19571:2016 `future\u003cT\u003e`.\n\nConstructors\n------------\n\n### future\n\n### future\n\nCreates a new future that unwraps `rhs`. \nThis 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`.\n\u003e **Note:**\n\u003e The technical specification requires this to be a `noexcept` constructor I (coryan) believe this is a defect in the technical specification, as this *creates* a new shared state: shared states are dynamically allocated, and the allocator (which might be the default `operator new`) may raise.\n\n### future\n\nCreates a future from a future whose result type is convertible to this future's result type.\n\n### future\n\nFunctions\n---------\n\n### get\n\nWaits until the shared state becomes ready, then retrieves the value stored in the shared state. \n\u003e **Note:**\n\u003e This operation invalidates the future, subsequent calls will fail, the application should capture the returned value because it would.\n\n### then\n\nAttach a continuation to the future. \nAttach a callable *func* to be invoked when the future is ready. The return type is a future wrapping the return type of *func*.\n\nSide effects: `valid() == false` if the operation is successful."]]