std::promise<R>::get_future
来自 cppreference.cn
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。