std::promise<R>::get_future
来自 cppreference.cn
std::future<R> get_future(); |
(since C++11) | |
返回与 *this 共享相同状态的 future 对象。
如果 *this 没有共享状态或已调用 get_future
,则会抛出异常。要获取 promise-future 通信通道的多个“pop”端,请使用 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。