Namespaces
Variants

std::shared_future<T>:: get

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
主模板
const T & get ( ) const ;
(1) (C++11 起)
std:: shared_future < T & > 特化
T & get ( ) const ;
(2) (C++11 起)
std:: shared_future < void > 特化
void get ( ) const ;
(3) (C++11 起)

get 成员函数通过调用 wait() 等待共享状态就绪,随后获取存储在共享状态中的值(如果存在)。

如果在调用此函数前 valid() false ,则行为未定义。

目录

返回值

1) 指向共享状态中存储值的常量引用。在共享状态被销毁后通过此引用访问值的行为是未定义的。
2) 作为值存储在共享状态中的引用。
3) (无)

异常

如果在 future 引用的共享状态中存储了异常(例如通过调用 std::promise::set_exception() ),那么该异常将被抛出。

注释

C++标准建议实现应在调用前检测 valid() false 的情况,并抛出带有错误条件 std::future_error std::future_errc::no_state 异常。

示例

参见

检查 future 是否具有共享状态
(公开成员函数)