Class promise<T> (2.46.0-rc)

Implement ISO/IEC TS 19571:2016promise<T>.

Constructors

promise()

Creates a promise with an unsatisfied shared state.

promise(std::function< void()>)

Creates a promise with an unsatisfied shared state.

Parameter
NameDescription
cancellation_callbackstd::function< void()>

promise(null_promise_t)

Creates a promisewithout a shared state.

Parameter
NameDescription
xnull_promise_t

promise(promise &&)

Constructs a new promise and transfer any shared state fromrhs.

Parameter
NameDescription
promise &&

promise(promise const &)

Parameter
NameDescription
promise const &

Operators

operator=(promise &&)

Abandons the shared state in*this, if any, and transfers the shared state fromrhs.

Parameter
NameDescription
rhspromise &&
Returns
TypeDescription
promise &

operator=(promise const &)

Parameter
NameDescription
promise const &
Returns
TypeDescription
promise &

Functions

swap(promise &)

Swaps the shared state in*this withrhs.

Parameter
NameDescription
otherpromise &
Returns
TypeDescription
void

get_future()

Creates thefuture<T> using the same shared state as*this.

Returns
TypeDescription
future< T >

set_value(T)

Satisfies the shared state.

Parameter
NameDescription
valueT
Exceptions
TypeDescription
std::future_errorwith std::future_errc::promise_already_satisfied if the shared state is already satisfied.
std::future_errorwith std::no_state if the promise does not have a shared state.
Returns
TypeDescription
void

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-17 UTC.