std::promise<R>::get_future
來自 cppreference.com
std::future<R> get_future(); |
(C++11 起) | |
返回一個與 *this 共享相同狀態的 `future` 物件。
如果 *this 沒有共享狀態或 `get_future` 已被呼叫,則會丟擲異常。為了獲取 promise-future 通訊通道的多個“接收”端,請使用 std::future::share。
對此函式的呼叫不會與對 set_value、set_exception、set_value_at_thread_exit 或 set_exception_at_thread_exit 的呼叫引入資料競爭(因此它們之間不需要同步)。
[編輯] 引數
(無)
[編輯] 返回值
一個引用 *this 共享狀態的 future。
[編輯] 異常
在以下條件下丟擲 std::future_error:
- *this 沒有共享狀態。錯誤碼被設定為 no_state。
- 已在與 *this 具有相同共享狀態的 promise 上呼叫過
get_future()
。錯誤碼被設定為 future_already_retrieved。