public member function
<future>
std::future::validbool valid() const noexcept;
Check for valid shared state
Returns whether the future object is currently associated with a shared state.For default-constructed future objects, this function returns false (unless move-assigned a valid future).
Futures can only be initially constructed with valid shared states by certain provider functions, such as async, promise::get_future or packaged_task::get_future.
Once the value of the shared state is retrieved with future::get, calling this function returns false
(unless move-assigned a new valid future).
true
if the object is associated with a shared state.
false
otherwise.
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;
}
foo is not valid bar's value: 10
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4