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.
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 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.
typename F
Returns
Type
Description
future< >
future<T>where T isstd::result_of_t<F, R>(basically). If T matchesfuture<U>then it returnsfuture<U>. The returned future will contain the result offunc.
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"]],[["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."],[],[],null,["# Class future<T> (2.39.0)\n\nVersion 2.39.0keyboard_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(future\\\u003c future\\\u003c T \\\u003e \\\u003e \\&\\&)\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| **Note:** 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(future\\\u003c U \\\u003e \\&\\&)\n\nCreates a future from a future whose result type is convertible to this future's result type.\n\n### future(std::shared_ptr\\\u003c shared_state_type \\\u003e)\n\nFunctions\n---------\n\n### get()\n\nWaits until the shared state becomes ready, then retrieves the value stored in the shared state. \n| **Note:** This operation invalidates the future, subsequent calls will fail, the application should capture the returned value because it would.\n\n### then(F \\&\\&)\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.\n\nType Aliases\n------------\n\n### shared_state_type\n\n**Alias Of** : `typename internal::future_base\u003c T \u003e::shared_state_type`"]]