A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/future/future/future/ below:

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:


Data races The move constructor (3) modifies x.

Exception safetyNo-throw guarantee: never throws exceptions.

See also
future::operator=
Move-assign future (public member function)
future::get
Get value (public member function)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4