-
Notifications
You must be signed in to change notification settings - Fork 20
/
future.html
757 lines (598 loc) · 25.5 KB
/
future.html
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
<cxx-clause id="futures">
<h1> Improvements to <code>std::future<T></code> and Related APIs</h1>
<cxx-section id="futures.general">
<h1>General</h1>
<p>
The extensions proposed here are an evolution of the functionality of
<code>std::future</code> and <code>std::shared_future</code>. The extensions
enable wait-free composition of asynchronous operations. Class templates
<code>std::promise</code> and <code>std::packaged_task</code> are also updated
to be compatible with the updated <code>std::future</code>.
</p>
</cxx-section>
<cxx-section id="header.future.synop">
<h1>Header <experimental/future> synopsis</h1>
<cxx-ednote>
An additional editorial fix as in Fundamental v1 TS is applied in the declaration of <code>swap</code> for <code>packaged_task</code>
</cxx-ednote>
<pre><code>#include <future>
namespace std {
namespace experimental {
inline namespace concurrency_v1 {
template <class R> class promise;
template <class R> class promise<R&>;
template <> class promise<void>;
template <class R>
void swap(promise<R>& x, promise<R>& y) noexcept;
template <class R> class future;
template <class R> class future<R&>;
template <> class future<void>;
template <class R> class shared_future;
template <class R> class shared_future<R&>;
template <> class shared_future<void>;
template <class> class packaged_task; // undefined
template <class R, class... ArgTypes>
class packaged_task<R(ArgTypes...)>;
template <class R, class... ArgTypes>
void swap(packaged_task<R(ArgTypes...)>&, packaged_task<R(ArgTypes...)>&) noexcept;
template <class T>
<em>see below</em> make_ready_future(T&& value);
future<void> make_ready_future();
template <class T>
future<T> make_exceptional_future(exception_ptr ex);
template <class T, class E>
future<T> make_exceptional_future(E ex);
template <class InputIterator>
<em>see below</em> when_all(InputIterator first, InputIterator last);
template <class... Futures>
<em>see below</em> when_all(Futures&&... futures);
template <class Sequence>
struct when_any_result;
template <class InputIterator>
<em>see below</em> when_any(InputIterator first, InputIterator last);
template <class... Futures>
<em>see below</em> when_any(Futures&&... futures);
} // namespace concurrency_v1
} // namespace experimental
template <class R, class Alloc>
struct uses_allocator<experimental::promise<R>, Alloc>;
template <class R, class Alloc>
struct uses_allocator<experimental::packaged_task<R>, Alloc>;
} // namespace std</code></pre>
</cxx-section>
<cxx-section id="futures.unique_future">
<h1>Class template <code>future</code></h1>
<p>
The specifications of all declarations within this subclause <cxx-ref to="futures.unique_future"></cxx-ref>
and its subclauses are the same as the corresponding declarations,
as specified in <cxx-ref in="cxx" to="futures.unique_future"></cxx-ref>,
unless explicitly specified otherwise.
</p>
<pre><code>namespace std {
namespace experimental {
inline namespace concurrency_v1 {
template <class R>
class future {
public:
future() noexcept;
future(future &&) noexcept;
future(const future&) = delete;
future(future<future<R>>&&) noexcept;
~future();
future& operator=(const future&) = delete;
future& operator=(future&&) noexcept;
shared_future<R> share();
// retrieving the value
<em>see below</em> get();
// functions to check state
bool valid() const noexcept;
bool is_ready() const;
void wait() const;
template <class Rep, class Period>
future_status wait_for(const chrono::duration<Rep, Period>& rel_time) const;
template <class Clock, class Duration>
future_status wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
// continuations
template <class F>
<em>see below</em> then(F&& func);
};
} // namespace concurrency_v1
} // namespace experimental
} // namespace std</code></pre>
<cxx-function>
<cxx-signature>future(future<future<R>>&& rhs) noexcept;</cxx-signature>
<cxx-Effects>Constructs a <code>future</code> object from the shared state referred to by
<code>rhs</code>.
The <code>future</code> becomes ready when one of the following occurs:
<ul>
<li>
Both the <code>rhs</code> and <code>rhs.get()</code> are ready. The value or the exception from <code>rhs.get()</code> is stored in the <code>future</code>'s shared state.
</li>
<li>
<code>rhs</code> is ready but <code>rhs.get()</code> is invalid. An exception of type <code>std::future_error</code>, with an error condition of <code>std::future_errc::broken_promise</code> is stored in the <code>future</code>'s shared state.
</li>
</ul>
</cxx-Effects>
<cxx-postconditions>
<ul>
<li><code>valid() == true</code>.</li>
<li><code>rhs.valid() == false</code>.</li>
</ul>
</cxx-postconditions>
</cxx-function>
<p>
The member function template <code>then</code> provides a mechanism for attaching
a <i>continuation</i> to a <code>future</code> object, which will be executed
as specified below.
</p>
<cxx-function>
<cxx-signature>
template <class F>
<em>see below</em> then(F&& func);
</cxx-signature>
<cxx-requires><code><em>INVOKE</em>(<em>DECAY_COPY</em> (std::forward<F>(func)), std::move(*this))</code> shall be a valid expression.</cxx-requires>
<cxx-Effects>
The function creates a shared state that is associated with the returned
<code>future</code> object. Additionally,
<ul>
<li>
When the object's shared state is ready, the continuation
<code><em>INVOKE</em>(<em>DECAY_COPY</em>(std::forward<F>(func)), std::move(*this))</code> is called on
an unspecified thread of execution with the call to
<code><em>DECAY_COPY</em>()</code> being evaluated in the thread that called
<code>then</code>.
</li>
<li>
Any value returned from the continuation is stored as the result in the
shared state of the resulting <code>future</code>. Any exception propagated from the execution of
the continuation is stored as the exceptional result in the shared state of the resulting <code>future</code>.
</li>
</ul>
</cxx-Effects>
<cxx-Returns>
When <code>result_of_t<decay_t<F>(future<R>)></code>
is <code>future<R2></code>, for some type <code>R2</code>, the function returns <code>future<R2></code>.
Otherwise, the function returns <code>future<result_of_t<decay_t<F>(future<R>)>></code>.
<cxx-Note>
The rule above is referred to as <em>implicit unwrapping</em>. Without this rule,
the return type of <code>then</code> taking a callable returning a
<code>future<R></code> would have been <code>future<future<R>></code>.
This rule avoids such nested <code>future</code> objects.
The type of <code>f2</code> below is
<code>future<int></code> and not <code>future<future<int>></code>:
<cxx-example>
<pre>
future<int> f1 = g();
future<int> f2 = f1.then([](future<int> f) {
future<int> f3 = h();
return f3;
});
</pre>
</cxx-example>
</cxx-Note>
</li>
</ul>
</cxx-Returns>
<cxx-Postconditions>
<code>valid() == false</code> on the original <code>future</code>.
<code>valid() == true</code> on the <code>future</code> returned from <code>then.</code>
<cxx-Note>
In case of implicit unwrapping, the validity of the <code>future</code> returned from
<code>func</code> cannot be established until after the completion of the
continuation. If it is not valid, the resulting <code>future</code>
becomes ready with an exception of type <code>std::future_error</code>,
with an error condition of <code>std::future_errc::broken_promise</code>.
</cxx-Note>
</cxx-Postconditions>
</cxx-function>
<cxx-function>
<cxx-signature>bool is_ready() const;</cxx-signature>
<cxx-Returns> <code>true</code> if the shared state is ready, otherwise <code>false</code>.</cxx-Returns>
</cxx-function>
</cxx-section>
<cxx-section id="futures.shared_future">
<h1>Class template <code>shared_future</code></h1>
<p>
The specifications of all declarations within this subclause <cxx-ref to="futures.shared_future"></cxx-ref>
and its subclauses are the same as the corresponding declarations,
as specified in <cxx-ref in="cxx" to="futures.shared_future"></cxx-ref>,
unless explicitly specified otherwise.
</p>
<pre>
namespace std {
namespace experimental {
inline namespace concurrency_v1 {
template <class R>
class shared_future {
public:
shared_future() noexcept;
shared_future(const shared_future&) noexcept;
shared_future(future<R>&&) noexcept;
shared_future(future<shared_future<R>>&& rhs) noexcept;
~shared_future();
shared_future& operator=(const shared_future&);
shared_future& operator=(shared_future&&) noexcept;
// retrieving the value
<em>see below</em> get();
// functions to check state
bool valid() const noexcept;
bool is_ready() const;
void wait() const;
template <class Rep, class Period>
future_status wait_for(const chrono::duration<Rep, Period>& rel_time) const;
template <class Clock, class Duration>
future_status wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
// continuations
template <class F>
<em>see below</em> then(F&& func) const;
};
} // namespace concurrency_v1
} // namespace experimental
} // namespace std
</pre>
<cxx-function>
<cxx-signature>shared_future(future<shared_future<R>>&& rhs) noexcept;</cxx-signature>
<cxx-Effects>Constructs a <code>shared_future</code> object from the shared state referred to by
<code>rhs</code>.
The <code>shared_future</code> becomes ready when one of the following occurs:
<ul>
<li>
Both the <code>rhs</code> and <code>rhs.get()</code> are ready. The value or the exception from <code>rhs.get()</code> is stored in the <code>shared_future</code>'s shared state.
</li>
<li>
<code>rhs</code> is ready but <code>rhs.get()</code> is invalid.
The <code>shared_future</code> stores an exception of type <code>std::future_error</code>, with an error condition of <code>std::future_errc::broken_promise</code>.
</li>
</ul>
</cxx-Effects>
<cxx-postconditions>
<ul>
<li><code>valid() == true</code>.</li>
<li><code>rhs.valid() == false</code>.</li>
</ul>
</cxx-postconditions>
</cxx-function>
<p>
The member function template <code>then</code> provides a mechanism for attaching
a <i>continuation</i> to a <code>shared_future</code> object, which will be executed
as specified below.
</p>
<cxx-function>
<cxx-signature>
template <class F>
<em>see below</em> then(F&& func) const;
</cxx-signature>
<cxx-requires><code><em>INVOKE</em>(<em>DECAY_COPY</em> (std::forward<F>(func)), *this)</code> shall be a valid expression.</cxx-requires>
<cxx-Effects>
The function creates a shared state that is associated with the returned
<code>future</code> object. Additionally,
<ul>
<li>
When the object's shared state is ready, the continuation
<code><em>INVOKE</em>(<em>DECAY_COPY</em>(std::forward<F>(func)), *this)</code> is called on
an unspecified thread of execution with the call to
<code><em>DECAY_COPY</em>()</code> being evaluated in the thread that called
<code>then</code>.
</li>
<li>
Any value returned from the continuation is stored as the result in the
shared state of the resulting <code>future</code>. Any exception propagated from the execution of
the continuation is stored as the exceptional result in the shared state of the resulting <code>future</code>.
</li>
</ul>
</cxx-Effects>
<cxx-Returns>
When <code>result_of_t<decay_t<F>(const shared_future&)></code>
is <code>future<R2></code>, for some type <code>R2</code>, the function returns <code>future<R2></code>.
Otherwise, the function returns <code>future<result_of_t<decay_t<F>(const shared_future&)>></code>.
<cxx-note>
This analogous to <code>future</code>. See the notes on
the return type of <code>future::then</code> in <cxx-ref to="futures.unique_future"></cxx-ref>.
</cxx-note>
</li>
</ul>
</cxx-Returns>
<cxx-postconditions>
<code>valid() == true</code> on the original <code>shared_future</code> object.
<code>valid() == true</code> on the <code>future</code> returned from <code>then.</code>
</cxx-postconditions>
</cxx-function>
<cxx-function>
<cxx-signature>bool is_ready() const;</cxx-signature>
<cxx-Returns> <code>true</code> if the shared state is ready, otherwise <code>false</code>.</cxx-Returns>
</cxx-function>
</cxx-section>
<cxx-section id="futures.promise">
<h1>Class template <code>promise</code></h1>
<p>
The specifications of all declarations within this subclause <cxx-ref to="futures.promise"></cxx-ref>
and its subclauses are the same as the corresponding declarations,
as specified in <cxx-ref in="cxx" to="futures.promise"></cxx-ref>,
unless explicitly specified otherwise.
</p>
<p>
The <code>future</code> returned by the function <code>get_future</code> is the one defined in the <code>experimental</code>
namespace (<cxx-ref to="futures.unique_future"></cxx-ref>).
</p>
</cxx-section>
<cxx-section id="futures.task">
<h1>Class template <code>packaged_task</code></h1>
<p>
The specifications of all declarations within this subclause <cxx-ref to="futures.task"></cxx-ref>
and its subclauses are the same as the corresponding declarations,
as specified in <cxx-ref in="cxx" to="futures.task"></cxx-ref>,
unless explicitly specified otherwise.
</p>
<p>
The <code>future</code> returned by the function <code>get_future</code> is the one defined in the <code>experimental</code>
namespace (<cxx-ref to="futures.unique_future"></cxx-ref>).
</p>
</cxx-section>
<!-- -->
<!-- M00when_all -->
<!-- -->
<cxx-section id="futures.when_all">
<h1> Function template <code>when_all</code></h1>
<p>
The function template <code>when_all</code> creates a <code>future</code> object that
becomes ready when all elements in a set of <code>future</code> and <code>shared_future</code> objects
become ready.
</p>
<cxx-function>
<cxx-signature>
template <class InputIterator>
future<vector<typename iterator_traits<InputIterator>::value_type>>
when_all(InputIterator first, InputIterator last);
template <class... Futures>
future<tuple<decay_t<Futures>...>> when_all(Futures&&... futures);
</cxx-signature>
<cxx-requires>
All <code>future</code>s and <code>shared_future</code>s passed into
<code>when_all</code> must be in a valid state (i.e. <code>valid() == true</code>).
</cxx-requires>
<cxx-remarks>
<ul>
<li>
The first overload shall not participate in overload resolution unless <code>iterator_traits<InputIterator>::value_type</code> is <code>future<R></code>
or <code>shared_future<R></code> for some type <code>R</code>.
</li>
<li>
For the second overload, let <em><code>D<sub>i</sub></code></em> be
<code>decay_t<F<sub>i</sub>></code>, and
let <em><code>U<sub>i</sub></code></em> be
<code>remove_reference_t<F<sub>i</sub>></code>
for each <code>F<sub>i</sub></code> in
<code>Futures</code>. This function shall not participate in overload resolution unless
for each <em>i</em> either <em><code>D<sub>i</sub></code></em>
is a <code>shared_future<<em>R<sub>i</sub></em>></code>
or <em><code>U<sub>i</sub></code></em> is a <code>future<<em>R<sub>i</sub></em>></code>.
</li>
</ul>
</cxx-remarks>
<cxx-Effects>
<!-- M0when_all_effects -->
<ul>
<li>
A new shared state containing a <code>Sequence</code> is
created, where <code>Sequence</code> is
a <code>vector</code> for the first overload and a
<code>tuple</code> for the second overload.
A new <code>future</code> object that refers to that shared state is created
and returned from <code>when_all</code>.
</li>
<li>
If the first overload is called with <code>first == last</code>, <code>when_all</code>
returns a <code>future</code> with an empty <code>vector</code> that is immediately
ready.
</li>
<li>If the second overload is called with no arguments,
<code>when_all</code> returns a <code>future<tuple<>></code>
that is immediately ready.</li>
<li>
Otherwise, any <code>future</code>s are moved, and any <code>shared_future</code>s
are copied into, correspondingly, <code>future</code>s or
<code>shared_future</code>s of
<code>Sequence</code> in the shared state.
</li>
<li>
The order of the objects in the shared state matches the order
of the arguments supplied to <code>when_all</code>.
</li>
<li>
Once all the <code>future</code>s and <code>shared_future</code>s supplied
to the call to <code>when_all</code> are ready, the resulting <code>future</code>,
as well as the <code>future</code>s and <code>shared_future</code>s
of the <code>Sequence</code>, are ready.
</li>
<li>
</li>
<li>The shared state of the <code>future</code> returned by <code>when_all</code>
will not store an exception, but the
shared states of <code>future</code>s and <code>shared_future</code>s held in the shared state may.</li>
</ul>
</cxx-Effects>
<cxx-postconditions>
<ul>
<li>For the returned <code>future</code>, <code>valid() == true</code>.</li>
<li>For all input <code>future</code>s, <code>valid() == false</code>.</li>
<li>For all input <code>shared_future</code>s, <code>valid() == true</code>.</li>
</ul>
</cxx-postconditions>
<cxx-returns>
A <code>future</code> object that becomes ready when all of the input
<code>future</code>sand <code>shared_future</code>s are ready.
</cxx-returns>
</cxx-function>
</cxx-section>
<!-- -->
<!-- M00when_any -->
<!-- -->
<cxx-section id="futures.when_any_result">
<h1> Class template <code>when_any_result</code></h1>
<p>
The library provides a template for storing the result of <code>when_any</code>.
</p>
<pre><code>
template<class Sequence>
struct when_any_result {
size_t index;
Sequence futures;
};
</code></pre>
</cxx-section>
<cxx-section id="futures.when_any">
<h1> Function template <code>when_any</code></h1>
<p>
The function template <code>when_any</code> creates a <code>future</code> object that
becomes ready when at least one element in a set of <code>future</code> and <code>shared_future</code> objects
becomes ready.
</p>
<cxx-function>
<cxx-signature>
template <class InputIterator>
future<when_any_result<vector<typename iterator_traits<InputIterator>::value_type>>>
when_any(InputIterator first, InputIterator last);
template <class... Futures>
future<when_any_result<tuple<decay_t<Futures>...>>> when_any(Futures&&... futures);
</cxx-signature>
<cxx-requires>
All <code>future</code>s and <code>shared_future</code>s passed into
<code>when_all</code> must be in a valid state (i.e. <code>valid() == true</code>).
</cxx-requires>
<cxx-remarks>
<ul>
<li>
The first overload shall not participate in overload resolution unless <code>iterator_traits<InputIterator>::value_type</code> is <code>future<R></code>
or <code>shared_future<R></code> for some type <code>R</code>.
</li>
<li>
For the second overload, let <em><code>D<sub>i</sub></code></em> be
<code>decay_t<F<sub>i</sub>></code>, and
let <em><code>U<sub>i</sub></code></em> be
<code>remove_reference_t<F<sub>i</sub>></code>
for each <code>F<sub>i</sub></code> in
<code>Futures</code>. This function shall not participate in overload resolution unless
for each <em>i</em> either <em><code>D<sub>i</sub></code></em>
is a <code>shared_future<<em>R<sub>i</sub></em>></code>
or <em><code>U<sub>i</sub></code></em> is a <code>future<<em>R<sub>i</sub></em>></code>.
</li>
</ul>
</cxx-remarks>
<cxx-Effects>
<!-- M0when_any_effects -->
<ul>
<li>
A new shared state containing <code>when_any_result<Sequence></code> is created,
where <code>Sequence</code> is a <code>vector</code> for the first overload and a
<code>tuple</code> for the second overload.
A new <code>future</code> object that refers to that shared state is created and returned
from <code>when_any</code>.
</li>
<li>
If the first overload is called with <code>first == last</code>,
<code>when_any</code> returns a <code>future</code> that is immediately ready.
The value of the <code>index</code> field of the <code>when_any_result</code> is
<code>static_cast<size_t>(-1)</code>. The <code>futures</code> field is an empty <code>vector</code>.
</li>
<li>If the second overload of is called with no arguments,
<code>when_any</code> returns a <code>future</code> that is immediately ready.
The value of the <code>index</code> field of the <code>when_any_result</code> is
<code>static_cast<size_t>(-1)</code>.
The <code>futures</code> field is <code>tuple<></code>.
</li>
<li>
Otherwise, any <code>future</code>s are moved, and any <code>shared_future</code>s
are copied into, correspondingly, <code>future</code>s or
<code>shared_future</code>s of the <code>futures</code> member of
<code>when_any_result<Sequence></code> in the shared state.
</li>
<li>
The order of the objects in the <code>futures</code> shared state matches the order
of the arguments supplied to <code>when_any</code>.
</li>
<li>
Once at least one of the <code>future</code>s or <code>shared_future</code>s supplied
to the call to <code>when_any</code> is ready, the resulting <code>future</code>
is ready.
Given the result future <code>f</code>,
<code>f.get().index</code> is the position of the ready <code>future</code>
or <code>shared_future</code> in the
<code>futures</code> member of
<code>when_any_result<Sequence></code> in the shared state.
</li>
<li>The shared state of the <code>future</code> returned by <code>when_all</code>
will not store an exception, but the
shared states of <code>future</code>s and <code>shared_future</code>s held in the shared state may.</li>
</li>
</ul>
</cxx-Effects>
<cxx-postconditions>
<ul>
<li>For the returned <code>future</code>, <code>valid() == true</code>.</li>
<li>For all input <code>future</code>s, <code>valid() == false</code>.</li>
<li>For all input <code>shared_future</code>s, <code>valid() == true</code>.</li>
</ul>
</cxx-postconditions>
<cxx-Returns>
<ul>
<li>A <code>future</code> object that becomes ready when any of the input
<code>future</code>s and <code>shared_future</code>s are ready.
</li>
</ul>
</cxx-Returns>
</cxx-function>
</cxx-section>
<cxx-section id="futures.make_ready_future">
<h1> Function template <code>make_ready_future</code></h1>
<cxx-function>
<cxx-signature>
template <class T>
future<V> make_ready_future(T&& value);
future<void> make_ready_future();
</cxx-signature>
<p>
Let <code>U</code> be <code>decay_t<T></code>. Then <code>V</code> is <code>X&</code> if <code>U</code> equals
<code>reference_wrapper<X></code>, otherwise <code>V</code> is <code>U</code>.
</p>
<cxx-Effects>
The function creates a shared state
that is immediately ready and returns a <code>future</code> associated
with that shared state.
For the first overload, the type of the shared state is <code>V</code> and the result is
constructed from <code>std::forward<T>(value)</code>.
For the second overload, the type of the shared state is <code>void</code>.
</cxx-Effects>
<cxx-postconditions>
For the returned <code>future, valid() == true</code> and <code>is_ready() == true</code>.
</cxx-postconditions>
</cxx-function>
</cxx-section>
<cxx-section id="futures.make_exceptional_future">
<h1>Function template <code>make_exceptional_future</code></h1>
<cxx-function>
<cxx-signature>
template <class T>
future<T> make_exceptional_future(exception_ptr ex);
</cxx-signature>
<cxx-Effects>Equivalent to
<cxx-codeblock>
promise<T> p;
p.set_exception(ex);
return p.get_future();</cxx-codeblock>
</cxx-Effects>
</cxx-function>
<cxx-function>
<cxx-codeblock>
template <class T, class E>
future<T> make_exceptional_future(E ex);</cxx-codeblock>
<cxx-Effects>Equivalent to
<cxx-codeblock>
promise<T> p;
p.set_exception(make_exception_ptr(ex));
return p.get_future();
</cxx-codeblock>
</cxx-Effects>
</cxx-function>
</cxx-section>
</cxx-section>
</cxx-clause>