Futures
Concurrency
Collaboration diagram for Futures:

## Classes

class | std::__basic_future< _Res >
class | std::future< _Res >
class | std::future< _Res & >
class | std::future< void >
class | std::future_error
struct | std::is_error_code_enum< future_errc >
class | std::packaged_task< _Res(_ArgTypes...)>
class | std::promise< _Res >
class | std::promise< _Res & >
class | std::promise< void >
class | std::shared_future< _Res >
class | std::shared_future< _Res & >
class | std::shared_future< void >

## Enumerations

enum class | std::future_errc { future_already_retrieved , promise_already_satisfied , no_state , broken_promise }
enum class | std::future_status { ready , timeout , deferred }
enum class | std::launch { async , deferred }

## Functions

| std::__basic_future< _Res >::__basic_future (const shared_future< _Res > &) noexcept
| std::__basic_future< _Res >::__basic_future (future< _Res > &&) noexcept
| std::__basic_future< _Res >::__basic_future (shared_future< _Res > &&) noexcept
template<typename _Fn, typename... _Args>
future< __async_result_of< _Fn, _Args... > > | std::async (_Fn &&__fn, _Args &&... __args)
template<typename _Fn, typename... _Args>
future< __async_result_of< _Fn, _Args... > > | std::async (launch __policy, _Fn &&__fn, _Args &&... __args)
const error_category & | std::future_category () noexcept
error_code | std::make_error_code (future_errc __errc) noexcept
error_condition | std::make_error_condition (future_errc __errc) noexcept
constexpr launch | std::operator& (launch __x, launch __y) noexcept
constexpr launch & | std::operator&= (launch &__x, launch __y) noexcept
constexpr launch | std::operator^ (launch __x, launch __y) noexcept
constexpr launch & | std::operator^= (launch &__x, launch __y) noexcept
constexpr launch | std::operator| (launch __x, launch __y) noexcept
constexpr launch & | std::operator|= (launch &__x, launch __y) noexcept
constexpr launch | std::operator~ (launch __x) noexcept
template<typename _Fun, typename _Signature = __function_guide_t<_Fun, decltype(&_Fun::operator())>>
| std::packaged_task (_Fun) -> packaged_task< _Signature >
template<typename _Res, typename... _ArgTypes>
| std::packaged_task (_Res(*)(_ArgTypes...)) -> packaged_task< _Res(_ArgTypes...)>
shared_future< _Res > | std::future< _Res >::share () noexcept
shared_future< _Res & > | std::future< _Res & >::share () noexcept
shared_future< void > | std::future< void >::share () noexcept
template<typename _Res, typename... _ArgTypes>
void | std::swap (packaged_task< _Res(_ArgTypes...)> &__x, packaged_task< _Res(_ArgTypes...)> &__y) noexcept
template<typename _Res>
void | std::swap (promise< _Res > &__x, promise< _Res > &__y) noexcept

## Detailed Description

Futures and promises provide support for retrieving the result from an asynchronous function, e.g. one that is running in another thread. A std::future represents an asynchronous result that will become ready at some later time. A consumer can wait on a future until the result is ready to be accessed.

Since
  C++11

## Enumeration Type Documentation

## future_errc

enum class std::future_errc

strong

Error code for futures.

Definition at line 76 of file future.

## future_status

enum class std::future_status

strong

Status code for futures.

Definition at line 195 of file future.

## launch

enum class std::launch

strong

Launch code for futures.

Definition at line 151 of file future.

## Function Documentation

## __basic_future() [1/3]

template<typename _Res>

std::__basic_future< _Res >::__basic_future | ( | const shared_future< _Res > & | __sf | ) |

inline explicit protected noexcept

Definition at line 1055 of file future.

## __basic_future() [2/3]

template<typename _Res>

std::__basic_future< _Res >::__basic_future | ( | future< _Res > && | __uf | ) |

inline explicit protected noexcept

Definition at line 1067 of file future.

## __basic_future() [3/3]

template<typename _Res>

std::__basic_future< _Res >::__basic_future | ( | shared_future< _Res > && | __sf | ) |

inline explicit protected noexcept

Definition at line 1061 of file future.

## async() [1/2]

template<typename _Fn, typename... _Args>

future< __async_result_of< _Fn, _Args... > > std::async | ( | _Fn && | __fn,
|  | _Args &&... | __args )

inline nodiscard

async, potential overload

Definition at line 1844 of file future.

References async(), and forward().

## async() [2/2]

template<typename _Fn, typename... _Args>

future< __async_result_of< _Fn, _Args... > > std::async | ( | launch | __policy,
|  | _Fn && | __fn,
|  | _Args &&... | __args )

nodiscard

async

Definition at line 1810 of file future.

References async(), forward(), and move().

Referenced by async(), and async().

## future_category()

const error_category & std::future_category | ( |  | ) |

noexcept

Points to a statically-allocated object derived from error_category.

Referenced by make_error_code(), and make_error_condition().

## make_error_code()

error_code std::make_error_code | ( | future_errc | __errc | ) |

inline noexcept

Overload of make_error_code for future_errc.

Definition at line 96 of file future.

References future_category(), and make_error_code().

Referenced by make_error_code(), system_category(), and std::filesystem::filesystem_error::what().

## make_error_condition()

error_condition std::make_error_condition | ( | future_errc | __errc | ) |

inline noexcept

Overload of make_error_condition for future_errc.

Definition at line 102 of file future.

References future_category().

Referenced by system_category().

## operator&()

launch std::operator& | ( | launch | __x,
|  | launch | __y )

constexpr noexcept

Definition at line 158 of file future.

## operator&=()

launch & std::operator&= | ( | launch & | __x,
|  | launch | __y )

inline constexpr noexcept

Definition at line 183 of file future.

## operator^()

launch std::operator^ | ( | launch | __x,
|  | launch | __y )

constexpr noexcept

Definition at line 172 of file future.

## operator^=()

launch & std::operator^= | ( | launch & | __x,
|  | launch | __y )

inline constexpr noexcept

Definition at line 191 of file future.

## operator|()

launch std::operator| | ( | launch | __x,
|  | launch | __y )

constexpr noexcept

Definition at line 165 of file future.

## operator|=()

launch & std::operator|= | ( | launch & | __x,
|  | launch | __y )

inline constexpr noexcept

Definition at line 187 of file future.

## operator~()

launch std::operator~ | ( | launch | __x | ) |

constexpr noexcept

Definition at line 179 of file future.

## share() [1/3]

template<typename _Res>

shared_future< _Res > std::future< _Res >::share | ( |  | ) |

inline noexcept

Definition at line 1076 of file future.

## share() [2/3]

template<typename _Res>

shared_future< _Res & > std::future< _Res & >::share | ( |  | ) |

inline noexcept

Definition at line 1081 of file future.

## share() [3/3]

shared_future< void > std::future< void >::share | ( |  | ) |

inline noexcept

Definition at line 1085 of file future.

## swap() [1/2]

template<typename _Res, typename... _ArgTypes>

void std::swap | ( | packaged_task< _Res(_ArgTypes...)> & | __x,
|  | packaged_task< _Res(_ArgTypes...)> & | __y )

inline noexcept

swap

Definition at line 1678 of file future.

## swap() [2/2]

template<typename _Res>

void std::swap | ( | promise< _Res > & | __x,
|  | promise< _Res > & | __y )

inline noexcept

Definition at line 1206 of file future.