Debian Codegraph @

headers/future

raw
1 /* Copyright (C) 2015 Povilas Kanapickas <[email protected]>
2
3 This file is part of cppreference-doc
4
5 This work is licensed under the Creative Commons Attribution-ShareAlike 3.0
6 Unported License. To view a copy of this license, visit
7 http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative
8 Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
9
10 Permission is granted to copy, distribute and/or modify this document
11 under the terms of the GNU Free Documentation License, Version 1.3 or
12 any later version published by the Free Software Foundation; with no
13 Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
14 */
15
16 #ifndef CPPREFERENCE_FUTURE_H
17 #define CPPREFERENCE_FUTURE_H
18
19 #if CPPREFERENCE_STDVER>= 2011
20 #include <stdexcept>
21
22 namespace std {
23
24 template<class R>
25 class promise { // SIMPLIFIED: removed R& and void specializations
26 public:
27 promise();
28 template<class Alloc>
29 promise(std::allocator_arg_t, const Alloc& alloc);
30 promise(promise&& other);
31 promise(const promise& other) = delete;
32
33 ~promise();
34
35 promise& operator=(promise&& other);
36 promise& operator=(const promise& rhs) = delete;
37
38 void swap(promise& other);
39
40 std::future<T> get_future();
41
42 void set_value(const R& value);
43 void set_value(R&& value);
44 void set_value(R& value); // member of R& specialization
45 void set_value(); // member of void specialization
46 void set_value_at_thread_exit(const R& value);
47 void set_value_at_thread_exit(R&& value);
48 void set_value_at_thread_exit(R& value); // member of R& specialization
49 void set_value_at_thread_exit(); // member of void specialization
50 void set_exception(std::exception_ptr p);
51 void set_exception_at_thread_exit(std::exception_ptr p);
52 };
53
54 template<class R>
55 void swap(promise<R>& lhs, promise<R>& rhs);
56
57 template<class R, class ...Args>
58 class packaged_task<R(Args...)> {
59 public:
60 packaged_task();
61
62 template <class F>
63 explicit packaged_task(F&& f);
64
65 template <class F, class Allocator>
66 explicit packaged_task(std::allocator_arg_t, const Allocator& a, F&& f);
67
68 packaged_task(const packaged_task&) = delete;
69 packaged_task(packaged_task&& rhs);
70
71 ~packaged_task();
72
73 packaged_task& operator=(const packaged_task&) = delete;
74 packaged_task& operator=(packaged_task&& rhs);
75
76 bool valid() const;
77
78 void swap(packaged_task& other);
79
80 std::future<R> get_future();
81
82 void operator()(ArgTypes... args);
83
84 void make_ready_at_thread_exit(ArgTypes... args);
85
86 void reset();
87 };
88
89 template<class Function, class... Args>
90 void swap(packaged_task<Function(Args...)>& lhs,
91 packaged_task<Function(Args...)>& rhs);
92
93 template<class T>
94 class future { // SIMPLIFIED: removed T& and void specializations
95 public:
96 future();
97 future(future&& other);
98 future(const future& other) = delete;
99 ~future();
100
101 future& operator=(future&& other);
102 future& operator=(const future& other) = delete;
103
104 std::shared_future<T> share();
105
106 T get(); // member only of generic specialization
107 T& get(); // member only of T& specialization
108 void get(); // member only of void specialization
109
110 bool valid() const;
111
112 void wait() const;
113
114 template<class Rep, class Period>
115 std::future_status wait_for(const std::chrono::duration<Rep, Period>& timeout_duration) const;
116
117 template<class Clock, class Duration>
118 std::future_status wait_until(const std::chrono::time_point<Clock, Duration>& timeout_time) const;
119 };
120
121 template<class T>
122 class shared_future { // SIMPLIFIED: removed T& and void specializations
123 public:
124 shared_future();
125 shared_future(const shared_future& other);
126 shared_future(std::future<T>&& other);
127 shared_future(shared_future&& other);
128
129 ~shared_future();
130
131 shared_future& operator=(const shared_future& other);
132 shared_future& operator=(shared_future&& other);
133
134 T get(); // member only of generic specialization
135 T& get(); // member only of T& specialization
136 void get(); // member only of void specialization
137
138 bool valid() const;
139
140 void wait() const;
141
142 template<class Rep, class Period>
143 std::future_status wait_for(const std::chrono::duration<Rep, Period>& timeout_duration) const;
144
145 template<class Clock, class Duration>
146 std::future_status wait_until(const std::chrono::time_point<Clock, Duration>& timeout_time) const;
147 };
148
149 enum class launch {
150 async,
151 deferred
152 };
153
154 enum class future_status {
155 ready,
156 timeout,
157 deferred
158 };
159
160 enum class future_errc {
161 broken_promise,
162 future_already_retrieved,
163 promise_already_satisfied,
164 no_state
165 };
166
167 class future_error : public logic_error {
168 public:
169 future_error(std::error_code ec);
170 const std::error_code& code() const;
171 };
172
173 template<class Function, class... Args>
174 std::future<typename std::result_of<Function(Args...)>::type>
175 async(Function&& f, Args&& ... args);
176
177 template<class Function, class... Args>
178 std::future<typename std::result_of<Function(Args...)>::type>
179 async(std::launch policy, Function&& f, Args&& ... args);
180
181 const std::error_category& future_category();
182
183 } // namespace std
184
185 #endif // CPPREFERENCE_STDVER>= 2011
186
187 #endif // CPPREFERENCE_FUTURE_H