Implementpromise<T>as defined in ISO/IEC TS 19571:2016.
Constructors
promise
Creates a promise with an unsatisfied shared state.
promise
Creates a promise with an unsatisfied shared state.
Parameter
Name
Description
cancellation_callback
std::function< void()>
promise
Creates a promisewithouta shared state.
Parameter
Name
Description
x
null_promise_t
promise
Constructs a new promise and transfer any shared state fromrhs.
Parameter
Name
Description
promise &&
~promise
Abandons any shared state.
If the shared state was not already satisfied it becomes satisfied with astd::future_errorexception. The error code in this exception isstd::future_errc::broken_promise.
promise
Parameter
Name
Description
promise const &
Operators
operator=
Abandons the shared state in*this, if any, and transfers the shared state fromrhs.
Parameter
Name
Description
rhs
promise &&
Returns
Type
Description
promise &
operator=
Parameter
Name
Description
promise const &
Returns
Type
Description
promise &
Functions
swap
Swaps the shared state in*thiswithrhs.
Parameter
Name
Description
other
promise &
Returns
Type
Description
void
get_future
Creates thefuture<T>using the same shared state as*this.
[[["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 the \u003ccode\u003epromise\u003c/code\u003e class in C++, specifically referencing implementations from version 2.10.1 up to the latest release candidate 2.37.0-rc.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003epromise\u003c/code\u003e class can be created with or without a shared state, offering constructors that accept a cancellation callback or a \u003ccode\u003enull_promise_t\u003c/code\u003e parameter.\u003c/p\u003e\n"],["\u003cp\u003eShared state management is handled via copy and move semantics, including operators and methods for transfering and abandoning shared state, as well as a \u003ccode\u003eswap\u003c/code\u003e function to exchange shared state with another \u003ccode\u003epromise\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eget_future\u003c/code\u003e function allows the creation of a \u003ccode\u003efuture<T>\u003c/code\u003e object linked to the \u003ccode\u003epromise\u003c/code\u003e's shared state, while \u003ccode\u003eset_value\u003c/code\u003e is used to satisfy the shared state.\u003c/p\u003e\n"],["\u003cp\u003eThe destruction of a promise that has not been satisfied results in the shared state becoming satisfied with a \u003ccode\u003estd::future_error\u003c/code\u003e exception.\u003c/p\u003e\n"]]],[],null,["# Class google::cloud::promise (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_1promise)\n- [2.41.0](/cpp/docs/reference/common/2.41.0/classgoogle_1_1cloud_1_1promise)\n- [2.40.0](/cpp/docs/reference/common/2.40.0/classgoogle_1_1cloud_1_1promise)\n- [2.39.0](/cpp/docs/reference/common/2.39.0/classgoogle_1_1cloud_1_1promise)\n- [2.38.0](/cpp/docs/reference/common/2.38.0/classgoogle_1_1cloud_1_1promise)\n- [2.37.0](/cpp/docs/reference/common/2.37.0/classgoogle_1_1cloud_1_1promise)\n- [2.36.0](/cpp/docs/reference/common/2.36.0/classgoogle_1_1cloud_1_1promise)\n- [2.35.0](/cpp/docs/reference/common/2.35.0/classgoogle_1_1cloud_1_1promise)\n- [2.34.0](/cpp/docs/reference/common/2.34.0/classgoogle_1_1cloud_1_1promise)\n- [2.33.0](/cpp/docs/reference/common/2.33.0/classgoogle_1_1cloud_1_1promise)\n- [2.32.0](/cpp/docs/reference/common/2.32.0/classgoogle_1_1cloud_1_1promise)\n- [2.31.0](/cpp/docs/reference/common/2.31.0/classgoogle_1_1cloud_1_1promise)\n- [2.30.0](/cpp/docs/reference/common/2.30.0/classgoogle_1_1cloud_1_1promise)\n- [2.29.0](/cpp/docs/reference/common/2.29.0/classgoogle_1_1cloud_1_1promise)\n- [2.28.0](/cpp/docs/reference/common/2.28.0/classgoogle_1_1cloud_1_1promise)\n- [2.27.0](/cpp/docs/reference/common/2.27.0/classgoogle_1_1cloud_1_1promise)\n- [2.26.0](/cpp/docs/reference/common/2.26.0/classgoogle_1_1cloud_1_1promise)\n- [2.25.1](/cpp/docs/reference/common/2.25.1/classgoogle_1_1cloud_1_1promise)\n- [2.24.0](/cpp/docs/reference/common/2.24.0/classgoogle_1_1cloud_1_1promise)\n- [2.23.0](/cpp/docs/reference/common/2.23.0/classgoogle_1_1cloud_1_1promise)\n- [2.22.1](/cpp/docs/reference/common/2.22.1/classgoogle_1_1cloud_1_1promise)\n- [2.21.0](/cpp/docs/reference/common/2.21.0/classgoogle_1_1cloud_1_1promise)\n- [2.20.0](/cpp/docs/reference/common/2.20.0/classgoogle_1_1cloud_1_1promise)\n- [2.19.0](/cpp/docs/reference/common/2.19.0/classgoogle_1_1cloud_1_1promise)\n- [2.18.0](/cpp/docs/reference/common/2.18.0/classgoogle_1_1cloud_1_1promise)\n- [2.17.0](/cpp/docs/reference/common/2.17.0/classgoogle_1_1cloud_1_1promise)\n- [2.16.0](/cpp/docs/reference/common/2.16.0/classgoogle_1_1cloud_1_1promise)\n- [2.15.1](/cpp/docs/reference/common/2.15.1/classgoogle_1_1cloud_1_1promise)\n- [2.14.0](/cpp/docs/reference/common/2.14.0/classgoogle_1_1cloud_1_1promise)\n- [2.13.0](/cpp/docs/reference/common/2.13.0/classgoogle_1_1cloud_1_1promise)\n- [2.12.0](/cpp/docs/reference/common/2.12.0/classgoogle_1_1cloud_1_1promise)\n- [2.11.0](/cpp/docs/reference/common/2.11.0/classgoogle_1_1cloud_1_1promise)\n- [2.10.1](/cpp/docs/reference/common/2.10.1/classgoogle_1_1cloud_1_1promise) \nImplement `promise\u003cT\u003e` as defined in ISO/IEC TS 19571:2016.\n\nConstructors\n------------\n\n### promise\n\nCreates a promise with an unsatisfied shared state.\n\n### promise\n\nCreates a promise with an unsatisfied shared state.\n\n### promise\n\nCreates a promise *without* a shared state.\n\n### promise\n\nConstructs a new promise and transfer any shared state from `rhs`.\n\n### \\~promise\n\nAbandons any shared state. \nIf the shared state was not already satisfied it becomes satisfied with a `std::future_error` exception. The error code in this exception is `std::future_errc::broken_promise`.\n\n### promise\n\nOperators\n---------\n\n### operator=\n\nAbandons the shared state in `*this`, if any, and transfers the shared state from `rhs`.\n\n### operator=\n\nFunctions\n---------\n\n### swap\n\nSwaps the shared state in `*this` with `rhs`.\n\n### get_future\n\nCreates the `future\u003cT\u003e` using the same shared state as `*this`.\n\n### set_value\n\nSatisfies the shared state."]]