Namespaces
Variants

std::future<T>:: share

From cppreference.net
Concurrency support library
Threads
(C++11)
(C++20)
this_thread namespace
(C++11)
(C++11)
Cooperative cancellation
Mutual exclusion
Generic lock management
Condition variables
(C++11)
Semaphores
Latches and Barriers
(C++20)
(C++20)
Futures
(C++11)
(C++11)
(C++11)
Safe reclamation
Hazard pointers
Atomic types
(C++11)
(C++20)
Initialization of atomic types
(C++11) (deprecated in C++20)
(C++11) (deprecated in C++20)
Memory ordering
(C++11) (deprecated in C++26)
Free functions for atomic operations
Free functions for atomic flags
std:: shared_future < T > share ( ) noexcept ;

* this 的共享状态(如果存在)转移给一个 std::shared_future 对象。多个 std::shared_future 对象可以引用同一个共享状态,而这在 std::future 中是无法实现的。

在调用 share 方法后, valid ( ) == false

目录

参数

(无)

返回值

一个包含先前由 * this 持有的共享状态(如果存在)的 std::shared_future 对象,其构造方式类似于 std:: shared_future < T > ( std :: move ( * this ) )

示例

缺陷报告

以下行为变更缺陷报告被追溯应用于先前发布的C++标准。

缺陷报告 应用于 发布时行为 正确行为
LWG 2556 C++11 share() 要求 valid() true 移除要求并设为 noexcept

参见

等待被异步设置的值(可能被其他 future 对象引用)
(类模板)