Main template
T get();
(1) (since C++11)T& get();
(2) (since C++11)void get();
(3) (since C++11)The get
member function waits (by calling wait()) until the shared state is ready, then retrieves the value stored in the shared state (if any). Right after calling this function, valid() is false.
If valid() is false before the call to this function, the behavior is undefined.
[edit] Return value1) The value v stored in the shared state, as std::move(v).
2) The reference stored as value in the shared state.
3) (none)
[edit] ExceptionsIf an exception was stored in the shared state referenced by the future (e.g. via a call to std::promise::set_exception()) then that exception will be thrown.
[edit] NotesThe C++ standard recommends the implementations to detect the case when valid() is false before the call and throw a std::future_error with an error condition of std::future_errc::no_state.
[edit] ExamplePossible output:
[0.000004s] launching thread [0.000461s] waiting for the future, f.valid() = 1 [1.001156s] f.get() returned with 7, f.valid() = 0 [1.001192s] launching thread [1.001275s] waiting for the future, f.valid() = 1 [2.002356s] caught exception 7, f.valid() = 0[edit] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior LWG 2096 C++11 overload (1) needed to check whetherT
is MoveAssignable not required [edit] See also checks if the future has a shared state
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