Skip to content

futures::promise_base

Futures / Shared State / promise_base

Defined in header <futures/promise.hpp>

template <class R, class Options = future_options<continuable_opt>> 
class promise_base;

Common members to promises of all types.

Description

This includes a pointer to the corresponding shared_state for the future and the functions to manage the promise.

The specific promise specialization will only differ by their set_value functions.

Inherited by: promise_base is a base class for promise< R, Options >

Public Functions

Member Functions Description
(constructor) Create the base promise with std::allocator.
(function)
operator= No copy assignment.
(function)
(destructor) Destructor.
(virtual function)
get_future Gets a future that shares its state with this promise.
(function)
set_exception Set the promise result as an exception.
(function)

Protected Functions

Member Protected Functions Description
swap (function)
get_shared_state (function)

Public Functions

function promise_base

Defined in header <futures/promise.hpp>

(1)
promise_base();
(2)
template <typename Allocator>
promise_base(std::allocator_arg_t, Allocator const & alloc);
(3)
promise_base(promise_base const &) = delete;
(4)
promise_base(promise_base && other) noexcept;
  1. Create the base promise with std::allocator.
  2. Create a base promise setting the shared state with the specified allocator.
  3. No copy constructor.
  4. Move constructor.

Description

(1) Use std::allocator_arg tag to dispatch and select allocator aware constructor

(2) This function allocates memory for and allocates an initial promise_shared_state (the future value) with the specified allocator. This object is stored in the internal intrusive pointer as the future shared state.

Exception Safety

  • (1) Basic exception guarantee.
  • (2) Basic exception guarantee.
  • (3) Basic exception guarantee.

  • (4) Throws nothing.

function operator=

Defined in header <futures/promise.hpp>

(1)
promise_base &
operator=(promise_base const &) = delete;
(2)
promise_base &
operator=(promise_base && other) noexcept;
  1. No copy assignment.
  2. Move assignment.

Exception Safety

  • (1) Basic exception guarantee.

  • (2) Throws nothing.

function ~promise_base

Defined in header <futures/promise.hpp>

virtual ~promise_base();

Destructor.

Description

This promise owns the shared state, so we need to warn the shared state when it's destroyed.

Exception Safety

Basic exception guarantee.

function get_future

Defined in header <futures/promise.hpp>

basic_future< R, Options >
get_future();

Gets a future that shares its state with this promise.

Description

This function constructs a future object that shares its state with this promise. Because this library handles more than a single future type, the future type we want is a template parameter.

This function expects future type constructors to accept pointers to shared states.

Exception Safety

Basic exception guarantee.

function set_exception

Defined in header <futures/promise.hpp>

(1)
void
set_exception(std::exception_ptr p);
(2)
template <class E>
requires std::is_base_of_v<std::exception, E>
void
set_exception(E e);

Set the promise result as an exception.

Notes

The set_value operation is only available at the concrete derived class, where we know the class type

Exception Safety

Basic exception guarantee.

Protected Functions

function swap

Defined in header <futures/promise.hpp>

void
swap(promise_base & other) noexcept;

Exception Safety

Throws nothing.

function get_shared_state

Defined in header <futures/promise.hpp>

constexpr
/* see return type below */
get_shared_state();

Exception Safety

Basic exception guarantee.


Updated on 2023-01-04