Portable concurrency  0.11.0
Public Member Functions | List of all members

The class template future provides a mechanism to access the result of asynchronous operations. More...

Public Member Functions

 future () noexcept=default
 
 future (future &&rhs) noexcept=default
 
 future (const future &)=delete
 
futureoperator= (const future &)=delete
 
futureoperator= (future &&rhs) noexcept=default
 
 ~future ()=default
 
shared_future< T > share () noexcept
 
get ()
 Get the result of asynchronyous operation stored in this future object. More...
 
void wait () const
 
bool valid () const noexcept
 
bool is_ready () const
 
template<typename F >
void notify (F &&notification)
 
template<typename E , typename F >
void notify (E &&exec, F &&notification)
 
future detach ()
 

Detailed Description

template<typename T>
class portable_concurrency::cxx14_v1::future< T >

The class template future provides a mechanism to access the result of asynchronous operations.

Constructor & Destructor Documentation

◆ future() [1/3]

future ( )
defaultnoexcept

Constructs invalid future object

Postcondition
this->valid() == false

◆ future() [2/3]

future ( future< T > &&  rhs)
defaultnoexcept

Move constructor

Postcondition
rhs.valid() == false

◆ future() [3/3]

future ( const future< T > &  )
delete

Copy constructor is explicitly deleted. Future object is not copyable.

◆ ~future()

~future ( )
default

Destroys associated shared state and cancel not yet started operations.

Member Function Documentation

◆ detach()

future detach ( )

Prevents cancellation of the operations of this future value calculation on its destruction.

Postcondition
this->valid() == false

◆ get()

T get ( )

Get the result of asynchronyous operation stored in this future object.

If the value is not yet set block current thread and wait for it. The value stored in the future is moved to the caller.

Postcondition
this->valid() == false

◆ is_ready()

bool is_ready ( ) const

Checks if associated shared state is ready

◆ notify() [1/2]

void notify ( E &&  exec,
F &&  notification 
)

Adds notification function to be called when this future object becomes ready.

Notification function must meet MoveConstructable, MoveAssignable and Callable (with signature void()) standard library requirements.

Both exec and notification objects are decay copied on the caller thread. Once this future object becomes ready post(exec, std::move(notification)) is executed on unspecified thread. Implementation provide strict guaranty that notification is scheduled for execution at most once. If this->is_ready() == true then notification is scheduled for execution immediatelly.

◆ notify() [2/2]

void notify ( F &&  notification)

Adds notification function to be called when this future object becomes ready.

Equivalent to this->notify(inplace_executor, notification).

Note
Thread of notification execution is unspecified.

◆ operator=() [1/2]

future& operator= ( const future< T > &  )
delete

Copy assignment operator is explicitly deleted. Future object is not copyable.

◆ operator=() [2/2]

future& operator= ( future< T > &&  rhs)
defaultnoexcept

Move assignmet

Postcondition
rhs.valid() == false

◆ share()

shared_future<T> share ( )
noexcept

Creates shared_future object and move ownership on the shared state associated to this object to it

Postcondition
this->valid() == false

◆ valid()

bool valid ( ) const
noexcept

Checks if future has associated shared state

Note
All operations except this method, move assignment and destructor on an invalid future are UB.

◆ wait()

void wait ( ) const

Blocks curent thread until this future object becomes ready.