std::future_errc

Defined in header <future> enum class future_errc { broken_promise = /* implementation-defined */, future_already_retrieved = /* implementation-defined */, promise_already_satisfied = /* implementation-defined */, no_state = /* implementation-defined */ }; (since C++11) The scoped enumeration std::future_errc defines the error codes reported by std::future and related classes in std::future_error exception objects. Only four

std::future_category

Defined in header <future> const std::error_category& future_category(); (since C++11) Obtains a reference to the static error category object for future object errors. The object is required to override the virtual function error_category::name() to return a pointer to the string "future". It is used to identify error codes provided in the exceptions of type std::future_error. Parameters (none). Return value A reference to the static object of unspecified runtime

std::future_category

Defined in header <future> const std::error_category& future_category(); (since C++11) Obtains a reference to the static error category object for the errors related to futures and promises. The object is required to override the virtual function error_category::name() to return a pointer to the string "future". It is used to identify error codes provided in the exceptions of type std::future_error. Parameters (none). Return value A reference to the static object

std::future::wait_until

template< class Clock, class Duration > std::future_status wait_until( const std::chrono::time_point<Clock,Duration>& timeout_time ) const; (since C++11) wait_until waits for a result to become available. It blocks until specified timeout_time has been reached or the result becomes available, whichever comes first. The return value indicates why wait_until returned. The behavior is undefined if valid()== false before the call to this function. Parameters timeout_time

std::future::wait_for

template< class Rep, class Period > std::future_status wait_for( const std::chrono::duration<Rep,Period>& timeout_duration ) const; (since C++11) Waits for the result to become available. Blocks until specified timeout_duration has elapsed or the result becomes available, whichever comes first. Returns value identifies the state of the result. A steady clock is used to measure the duration. This function may block for longer than timeout_duration due to scheduling or res

std::future::wait

void wait() const; (since C++11) Blocks until the result becomes available. valid() == true after the call. The behavior is undefined if valid()== false before the call to this function. Parameters (none). Return value (none). Exceptions (none). Notes The implementations are encouraged to detect the case when valid == false before the call and throw a std::future_error with an error condition of std::future_errc::no_state. Example #include <iostream> #include <

std::future::valid

bool valid() const; (since C++11) Checks if the future refers to a shared state. This is the case only for futures that were not default-constructed or moved from (i.e. returned by std::promise::get_future(), std::packaged_task::get_future() or std::async()) until the first time get() or share() is called. The behavior is undefined if any member function other than the destructor, the move-assignment operator, or valid is called on a future that does not refer to shared state (although

std::future::share

std::shared_future<T> share(); Transfers the shared state of *this to a std::shared_future object. Multiple std::shared_future objects may reference the same shared state, which is not possible with std::future. After calling share on a std::future, valid() == false. The behavior is undefined if valid()== false before the call to this function. Parameters (none). Return value A std::shared_future object containing the shared state previously held by *this. Notes The imple

std::future::get

T get(); (1) (member only of generic future template)(since C++11) T& get(); (2) (member only of future<T&> template specialization)(since C++11) void get(); (3) (member only of future<void> template specialization)(since C++11) The get method waits until the future has a valid result and (depending on which template is used) retrieves it. It effectively calls wait() in order to wait for the result. The generic template and two template specializations ea

std::future::future

future(); (1) (since C++11) future( future&& other ); (2) (since C++11) future( const future& other ) = delete; (3) (since C++11) Constructs a std::future object. 1) Default constructor. Constructs a std::future with no shared state. After construction, valid() == false. 2) Move constructor. Constructs a std::future with the shared state of other using move semantics. After construction, other.valid() == false. 3) std::future is not CopyConstructible. Parame