|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | ||||
| Getting the result | ||||
| State | ||||
future::valid | ||||
bool valid()constnoexcept; | (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 bystd::promise::get_future(),std::packaged_task::get_future() orstd::async()) until the first timeget() orshare() is called.
The behavior is undefined if any member function other than the destructor, the move-assignment operator, orvalid is called on afuture that does not refer to shared state (although implementations are encouraged to throwstd::future_error indicatingno_state in this case). It is valid to move from a future object for whichvalid() isfalse.
Contents |
(none)
true if*this refers to a shared state, otherwisefalse.
#include <future>#include <iostream> int main(){std::promise<void> p;std::future<void> f= p.get_future(); std::cout<<std::boolalpha; std::cout<< f.valid()<<'\n'; p.set_value();std::cout<< f.valid()<<'\n'; f.get();std::cout<< f.valid()<<'\n';}
Output:
truetruefalse
| waits for the result to become available (public member function)[edit] |