std::future (3) - Linux Manuals
std::future: std::future
NAME
Synopsis
Defined in header <future>
template< class T > class future; (1) (since C++11)
template< class T > class future<T&>; (2) (since C++11)
template<> class future<void>; (3) (since C++11)
The class template std::future provides a mechanism to access the result of asynchronous operations:
* An asynchronous operation (created via std::async, std::packaged_task, or std::promise) can provide a std::future object to the creator of that asynchronous operation.
* The creator of the asynchronous operation can then use a variety of methods to query, wait for, or extract a value from the std::future. These methods may block if the asynchronous operation has not yet provided a value.
* When the asynchronous operation is ready to send a result to the creator, it can do so by modifying shared state (e.g. std::promise::set_value) that is linked to the creator's std::future.
Note that std::future references shared state that is not shared with any other asynchronous return objects (as opposed to std::shared_future).
Member functions
constructor (public member function)
destructor (public member function)
operator= (public member function)
share (public member function)
Getting the result
get (public member function)
State
valid (public member function)
wait (public member function)
wait_for (public member function)
wait_until (public member function)
Example
// Run this code
Output:
See also
async runs a function asynchronously (potentially in a new thread) and returns a std::future that will hold the result
(C++11)
shared_future waits for a value (possibly referenced by other futures) that is set asynchronously