public member function
<future>

std::future::operator=

move (1)
future& operator= (future&& rhs) noexcept;
copy [deleted] (2)
future& operator= (const future&) = delete;
Move-assign future
Acquires the shared state of rhs (if any).

If the object was valid (i.e., it had access to a shared state) before the call, it is disassociated from that shared state. If it was the only object associated to that shared state, the former shared state is itself also destroyed.

rhs is left with no shared state (as if default-constructed): it is no longer valid.

future objects cannot be copied (2).

引數

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

返回值

*this

示例

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

int get_value() { return 10; }

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

  std::cout << "value: " << fut.get() << '\n';

  return 0;
}

輸出

value: 10


資料競爭

Both the object and rhs are modified.

異常安全

無異常保證: 絕不丟擲異常。

另見