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).

Parameters

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

Return value

*this

Example

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;
}


Output:

value: 10

Data races

Both the object and rhs are modified.

Exception safety

No-throw guarantee: never throws exceptions.

See also