Namespaces
Variants

std::promise<R>:: promise

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
promise ( ) ;
(1) (自 C++11 起)
template < class Alloc >
promise ( std:: allocator_arg_t , const Alloc & alloc ) ;
(2) (自 C++11 起)
promise ( promise && other ) noexcept ;
(3) (自 C++11 起)
promise ( const promise & other ) = delete ;
(4) (自 C++11 起)

构造一个 promise 对象。

1) 默认构造函数。构造具有空共享状态的 promise。
2) 构造具有空共享状态的 promise。共享状态使用 alloc 进行分配。 Alloc 必须满足 Allocator 的要求。
3) 移动构造函数。使用移动语义构造具有 other 共享状态的 promise。构造完成后, other 不再拥有共享状态。
4) promise 不可复制。

参数

alloc - 用于分配共享状态的分配器
other - 用于获取状态的另一个 promise

异常

1,2) 可能抛出由实现定义的异常。

示例