public member function
<future>

std::future::future

default (1)
future() noexcept;
copy [deleted] (2)
future (const future&) = delete;
move (3)
future (future&& x) noexcept;
Construct future
Constructs a future object:

(1) default constructor
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.

Parameters

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

Example

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


Output:

value: 10

Data races

The move constructor (3) modifies x.

Exception safety

No-throw guarantee: never throws exceptions.

See also