std::promise<R>:: get_future
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | ||||
| Getting the result | ||||
|
promise::get_future
|
||||
| Setting the result | ||||
| Non-member Functions | ||||
| Helper Classes | ||||
|
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 。