public member function
<future>
std::promise::promise default (1)promise();with allocator (2)
template <class Alloc> promise (allocator_arg_t aa, const Alloc& alloc);copy [deleted] (3)
promise (const promise&) = delete;move (4)
promise (promise&& x) noexcept;
Construct promise
Constructs a promise object:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// promise constructors
#include <iostream> // std::cout
#include <functional> // std::ref
#include <memory> // std::allocator, std::allocator_arg
#include <thread> // std::thread
#include <future> // std::promise, std::future
void print_int (std::future<int>& fut) {
int x = fut.get();
std::cout << "value: " << x << '\n';
}
int main ()
{
std::promise<int> foo;
std::promise<int> bar = std::promise<int>(std::allocator_arg,std::allocator<int>());
std::future<int> fut = bar.get_future();
std::thread th (print_int, std::ref(fut));
bar.set_value (20);
th.join();
return 0;
}
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