Google Cloud C++ Client  1.42.0
C++ Client Library for Google Cloud Platform
Public Types | Public Member Functions | Friends | List of all members
google::cloud::future< T > Class Template Referencefinal

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

#include <google/cloud/future_generic.h>

Public Types

using shared_state_type = typename internal::future_base< T >::shared_state_type
 

Public Member Functions

 future () noexcept
 
 future (future< future< T >> &&rhs) noexcept(false)
 Creates a new future that unwraps rhs. More...
 
template<class U , typename Enable = absl::enable_if_t<std::is_constructible<T, U>::value>>
 future (future< U > &&rhs)
 Creates a future from a future whose result type is convertible to this future's result type. More...
 
get ()
 Waits until the shared state becomes ready, then retrieves the value stored in the shared state. More...
 
template<typename F >
internal::then_helper< F, T >::future_t then (F &&func)
 Attach a continuation to the future. More...
 
 future (std::shared_ptr< shared_state_type > state)
 

Friends

template<typename U >
class future
 
class future< void >
 

Detailed Description

template<typename T>
class google::cloud::future< T >

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

Definition at line 37 of file future_generic.h.

Member Typedef Documentation

◆ shared_state_type

template<typename T >
using google::cloud::future< T >::shared_state_type = typename internal::future_base<T>::shared_state_type

Definition at line 39 of file future_generic.h.

Constructor & Destructor Documentation

◆ future() [1/4]

template<typename T >
google::cloud::future< T >::future ( )
inlinenoexcept

Definition at line 44 of file future_generic.h.

◆ future() [2/4]

template<typename T >
google::cloud::future< T >::future ( future< future< T >> &&  rhs)
noexcept

Creates a new future that unwraps rhs.

This 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.

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.

◆ future() [3/4]

template<typename T >
template<class U , typename Enable = absl::enable_if_t<std::is_constructible<T, U>::value>>
google::cloud::future< T >::future ( future< U > &&  rhs)
inlineexplicit

Creates a future from a future whose result type is convertible to this future's result type.

Definition at line 70 of file future_generic.h.

◆ future() [4/4]

template<typename T >
google::cloud::future< T >::future ( std::shared_ptr< shared_state_type state)
inlineexplicit

Definition at line 122 of file future_generic.h.

Member Function Documentation

◆ get()

template<typename T >
T google::cloud::future< T >::get ( )
inline

Waits until the shared state becomes ready, then retrieves the value stored in the shared state.

Note
This operation invalidates the future, subsequent calls will fail, the application should capture the returned value because it would.
Exceptions
anyexceptions stored in the shared state.
std::future_errorwith std::no_state if the future does not have a shared state.

Definition at line 84 of file future_generic.h.

◆ then()

template<typename T >
template<typename F >
internal::then_helper<F, T>::future_t google::cloud::future< T >::then ( F &&  func)
inline

Attach a continuation to the future.

Attach a callable func to be invoked when the future is ready. The return type is a future wrapping the return type of func.

Returns
future<T> where T is std::result_of_t<F, R> (basically). If T matches future<U> then it returns future<U>. The returned future will contain the result of func.
Parameters
funca Callable to be invoked when the future is ready. The function might be called immediately, e.g., if the future is ready.

Side effects: valid() == false if the operation is successful.

Definition at line 115 of file future_generic.h.

Friends And Related Function Documentation

◆ future

template<typename T >
template<typename U >
friend class future
friend

Definition at line 137 of file future_generic.h.

◆ future< void >

template<typename T >
friend class future< void >
friend

Definition at line 137 of file future_generic.h.