public member function
<future>
bool valid() const noexcept;
Check for valid shared state
Return value
true if the object is associated with a shared state.
false otherwise.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| // future::valid #include <iostream> // std::cout #include <future> // std::async, std::future #include <utility> // std::move int get_value() { return 10; } int main () { std::future<int> foo,bar; foo = std::async (get_value); bar = std::move(foo); if (foo.valid()) std::cout << "foo's value: " << foo.get() << '\n'; else std::cout << "foo is not valid\n"; if (bar.valid()) std::cout << "bar's value: " << bar.get() << '\n'; else std::cout << "bar is not valid\n"; return 0; }
|
Output:
foo is not valid bar's value: 10 |
Data races
The future object is accessed.
Exception safety
No-throw guarantee: never throws exceptions.