public member function
<future>

std::future::future

默认 (1)
future() noexcept;
copy [deleted] (2)
future (const future&) = delete;
移动 (3)
future (future&& x) noexcept;
Construct future
Constructs a future object

(1) 默认构造函数
Constructs an empty future: The object has no shared state, and thus is not valid, but it can be move-assigned another future value.
(2) copy constructor [deleted]
future objects cannot be copied (see shared_future for a copyable future class).
(3) move constructor
The constructed object acquires the shared state of x (if any).
x is left with no shared state (it is no longer valid).

Futures with valid shared states can only be initially constructed by certain provider functions, such as async, promise::get_future or packaged_task::get_future.

参数

x
Another future object of the same type (with the same template parameter, T).

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// future::future
#include <iostream>       // std::cout
#include <future>         // std::async, std::future

int get_value() { return 10; }

int main ()
{
  std::future<int> foo;                            // default-constructed
  std::future<int> bar = std::async (get_value);   // move-constructed

  int x = bar.get();

  std::cout << "value: " << x << '\n';

  return 0;
}

输出

value: 10


数据竞争

The move constructor (3) modifies x.

异常安全

无异常保证: 绝不抛出异常。

另见