-
Notifications
You must be signed in to change notification settings - Fork 20
/
N4313_future.html
1034 lines (864 loc) · 39.3 KB
/
N4313_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
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<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. <ins>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>.</ins>
</p>
</cxx-section>
<cxx-section id="header.future.synop">
<h1><ins>Header <experimental/future> synopsis</ins></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><ins>#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>
future<decay_t<T>> make_ready_future(T&& value);
future<void> make_ready_future();
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</ins></code></pre>
</cxx-section>
<cxx-section id="futures.unique_future">
<h1> <del>Changes to c</del><ins>C</ins>lass template <code>future</code></h1>
<p>
The specification of all declarations within this sub-clause <cxx-ref to="futures.unique_future"></cxx-ref>
and its sub-clauses 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>
<del>
To the class declaration found in <cxx-ref in="cxx" to="futures.unique_future"></cxx-ref> paragraph 3, add the following to the public
functions:</del>
<cxx-function>
<cxx-signature><del>
bool is_ready() const;
future(future<future<R>>&&) noexcept;
template <typename F>
<em>see below</em> then(F&& func);
template <typename F>
<em>see below</em> then(launch policy, F&& func);
</del>
</cxx-signature>
</cxx-function>
<pre><code><ins>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 <ins>noexcept</ins>;
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</ins></code></pre>
<p>
In <cxx-ref in="cxx" to="futures.unique_future"></cxx-ref> between paragraphs 9 and 10, add the following:
</p>
<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><del> and unwrapping the inner <code>future</code></del>.
<ins>
The <code>future</code> becomes ready when one of the following occurs:</ins>
<ul>
<li><ins>
Both the outer and the inner <code>future</code>s are ready. The <code>future</code> stores the value or the exception from the inner <code>future</code>.
</ins></li>
<li><ins>
The outer <code>future</code> is ready but the inner <code>future</code> is invalid. The <code>future</code> stores an exception of type <code>std::future_error</code>, with an error condition of <code>std::future_errc::broken_promise</code>.
</ins></li>
</ul>
</cxx-Effects>
<cxx-postconditions>
<ul>
<li><del><code>valid()</code> returns the same value as <code>rhs.valid()</code> prior to the
constructor invocation.</del></li>
<li><ins><code>valid() == true</code>.</ins></li>
<li><code>rhs.valid() == false</code>.</li>
</ul>
</cxx-postconditions>
</cxx-function>
<p>
After <cxx-ref in="cxx" to="futures.unique_future"></cxx-ref> paragraph 26, add the following:
</p>
<p>
<ins>
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.
</ins>
</p>
<cxx-function>
<cxx-signature>
template <<del>typename</del><ins>class</ins> F>
<em>see below</em> then(F&& func);
<del>template <typename F>
<em>see below</em> then(launch policy, F&& func);
</del>
</cxx-signature>
<cxx-requires><ins><code><em>INVOKE</em>(<em>DECAY_COPY</em> (std::forward<F>(func)), std::move(*this))</code> shall be a valid expression.</ins></cxx-requires>
<cxx-Notes>
<del>The two functions differ only by input parameters. The first only
takes a callable object which accepts a <code>future</code> object as a parameter. The
second function takes a launch policy as the first
parameter and a callable object as the second parameter.</del>
<ins>The function takes a callable object which accepts a <code>future</code>
object as a parameter. </ins>
</cxx-Notes>
<cxx-Effects>
<ins>
The function creates a shared state that is associated with the returned
<code>future</code> object. The further behavior of the function is as follows.
</ins>
<ul>
<li>
<del>
The continuation <code><em>INVOKE</em>(<em>DECAY_COPY</em> (std::forward<F>(func)))</code> is called when the object's shared state is ready (has a value or exception stored).</del>
</li>
<li><ins>
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>.
</ins><li>
<li><del>The continuation launches according to the specified launch policy.</del></li>
<li><del>When the launch policy is not provided the continuation inherits
the parent's launch policy.</del></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>
<li><del>If the parent was created with <code>std::promise</code> or with a <code>packaged_task</code> (has
no associated launch policy), the continuation behaves the same as in the second
overload with a policy argument of <code>launch::async | launch::deferred</code> and the
same argument for <code>func</code>.<del></li>
<li><del>If the parent has a policy of <code>launch::deferred</code>, then it is filled by
calling <code>wait()</code> or <code>get()</code> on the resulting <code>future</code>.
<a id="futures.unique_future.example"></a></del>
<cxx-example>
<pre><del>
auto f1 = async(launch::deferred, [] { return 1; });
auto f2 = f1.then([](future n) { return 2; });
f2.wait(); // execution of f1 starts here, followed by f2
</del></pre> </cxx-example>
</li>
</ul>
</cxx-Effects>
<cxx-Returns>
The return type of <code>then</code> depends on the return type of the closure
<code>func</code> as defined below:
<ul>
<li>
When <code>result_of_t<decay_t<F>(<ins>future<R></ins>)></code>
is <code>future<R<ins>2</ins>></code>, the function returns <code>future<R<ins>2</ins>></code>.
</li>
<li>
Otherwise, the function returns <code>future<result_of_t<decay_t<F>(<ins>future<R></ins>)>></code>.
</p>
<cxx-Note>
The first rule above is called <em>implicit unwrapping</em>. Without this rule,
the return type of <code>then</code> taking a closure 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>
<ul>
<li><del>The <code>future</code> object is moved to the parameter of the continuation function.</del></li>
<li><code>valid() == false</code> on the original <code>future</code>.</li>
<li>
<ins><code>valid() == true</code> on the <code>future</code> returned from <code>then.</code></ins><del> object immediately after it returns.</del>
<cxx-Notes>
<ins>
In case of implicit unwrapping, the validity of the <code>future</code> returned from
<code>then</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>.
</ins>
</cxx-Notes>
</li>
</ul>
</cxx-Postconditions>
</cxx-function>
<cxx-function>
<cxx-signature>bool is_ready() const <ins>noexcept</ins>;</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> <del>Changes to c</del><ins>C</ins>lass template <code>shared_future</code></h1>
<p>
The specification of all declarations within this sub-clause <cxx-ref to="futures.shared_future"></cxx-ref>
and its sub-clauses 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>
<del>
To the class declaration found in <cxx-ref in="cxx" to="futures.shared_future"></cxx-ref>
paragraph 3, add the following to the public functions:
</del>
</p>
<pre><del>
bool is_ready() const;
template <typename F>
<em>see below</em> then(F&& func);
template <typename F>
<em>see below</em> then(launch policy, F&& func);
</pre>
</del>
<p>
<pre><code><ins>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(shared_future&&) 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 noexcept;
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</ins></code></pre>
<p><ins>
After <cxx-ref in="cxx" to="futures.shared_future"></cxx-ref> paragraph 10, add the following:
</ins></p>
<cxx-function>
<cxx-signature><ins>shared_future(future<shared_future<R>>&& rhs) noexcept;</ins></cxx-signature>
<cxx-Effects><ins>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:</ins>
<ul>
<li><ins>
Both the outer <code>future</code> and the inner <code>shared_future</code> are ready.
The <code>shared_future</code> stores the value or the exception from the inner <code>shared_future</code>.
</ins></li>
<li><ins>
The outer <code>future</code> is ready but the inner <code>shared_future</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>.
</ins></li>
</ul>
</cxx-Effects>
<cxx-postconditions>
<ul>
<li><del><code>valid()</code> returns the same value as <code>rhs.valid()</code> prior to the
constructor invocation.</del></li>
<li><ins><code>valid() == true</code>.</ins></li>
<li><code>rhs.valid() == false</code>.</li>
</ul>
</cxx-postconditions>
</cxx-function>
<p>
After <cxx-ref in="cxx" to="futures.shared_future"></cxx-ref> paragraph 28, add the following:
</p>
<p>
<ins>
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.
</ins>
</p>
<cxx-function>
<cxx-signature>
template <<del>typename</del><ins>class</ins> F>
<em>see below</em> then(F&& func) <ins>const</ins>;
<del>
template <class F>
<em>see below</em> then(launch policy, F&& func) const;</del>
</cxx-signature>
<cxx-requires><ins><code><em>INVOKE</em>(<em>DECAY_COPY</em> (std::forward<F>(func)), *this)</code> shall be a valid expression.</ins></cxx-requires>
<cxx-Notes>
<del>The two functions differ only by input parameters. The first
only takes a callable object which accepts a <code>shared_future</code> object as a
parameter. The second function takes a launch
policy as the first parameter and a callable object as the second parameter.</del>
<ins>The function takes a callable object which accepts a
<code>shared_future</code> object as a parameter.</ins>
</cxx-Notes>
<cxx-Effects>
<ins>
The function creates a shared state that is associated with the returned
<code>future</code> object. The further behavior of the function is as follows.
</ins>
<ul>
<li>
<del>The continuation <code><em>INVOKE</em>(<em>DECAY_COPY</em> (std::forward<F>(func)), *this)</code> is called when the object's shared state is ready (has a value or exception stored).</del>
</li>
<li><ins>
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>.
</ins><li>
<li><del>The continuation launches according to the specified policy.</del></li>
<li><del>When the launch policy is not provided the continuation
inherits the parent's launch policy.</del></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>
<li><del>If the parent was created with <code>std::promise</code> (has no associated launch
policy), the continuation behaves the same as in the second function with a policy
argument of <code>launch::async | launch::deferred</code> and the same argument for <code>func</code>.</del></li>
<li><del>If the parent has a policy of <code>launch::deferred</code>, then it is filled by
calling <code>wait()</code> or <code>get()</code> on the resulting <code><del>shared_</del>future</code>.
<cxx-note>
This is similar to <code>future</code>. See example in <cxx-ref to="futures.unique_future"></cxx-ref>.
</del></cxx-note>
</li>
</ul>
</cxx-Effects>
<cxx-Returns>
The return type of <code>then</code> depends on the return type of the closure
<code>func</code> as defined below:
<ul>
<li>
When <code>result_of_t<decay_t<F>(<ins>shared_future<R></ins>)></code>
is <code>future<R<ins>2</ins>></code>, the function returns <code>future<R<ins>2</ins>></code>.
</li>
<li>
Otherwise, the function returns <code>future<result_of_t<decay_t<F>(<ins>shared_future<R></ins>)>></code>.
<p>
<cxx-note>
This is analogous to <code>future</code>. See the notes on <code>future::then</code> return type in <cxx-ref to="futures.unique_future"></cxx-ref>.
</cxx-note>
</li>
</ul>
</cxx-Returns>
<cxx-postconditions>
<ul>
<li><del>
The <code>shared_future</code> passed to the continuation function is
a copy of the original <code>shared_future</code>.</del>
</li>
<li>
<code>valid() == true</code> on the original <code>shared_future</code> object.
<ins><code>valid() == true</code> on the <code><del>shared_</del>future</code> returned from <code>then.</code></ins>
<cxx-Notes>
<ins>
In case of implicit unwrapping, the validity of the <code>future</code> returned from
<code>then</code> cannot be established until after the completion of the
continuation. In such case, 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>.
</ins>
</cxx-Notes>
</li>
</ul>
</cxx-postconditions>
</cxx-function>
<cxx-function>
<cxx-signature>bool is_ready() const noexcept;</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><ins>Class template <code>promise</code></ins></h1>
<p><ins>
The specification of all declarations within this sub-clause <cxx-ref to="futures.promise"></cxx-ref>
and its sub-clauses are the same as the corresponding declarations,
as specified in <cxx-ref in="cxx" to="futures.promise"></cxx-ref>,
unless explicitly specified otherwise.
</ins></p>
<p><ins>
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>).
</ins></p>
</cxx-section>
<cxx-section id="futures.task">
<h1><ins>Class template <code>packaged_task</code></ins></h1>
<p><ins>
The specification of all declarations within this sub-clause <cxx-ref to="futures.task"></cxx-ref>
and its sub-clauses are the same as the corresponding declarations,
as specified in <cxx-ref in="cxx" to="futures.task"></cxx-ref>,
unless explicitly specified otherwise.
</ins></p>
<p><ins>
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>).
</ins></p>
</cxx-section>
<!-- -->
<!-- M00when_all -->
<!-- -->
<cxx-section id="futures.when_all">
<h1> Function template <code>when_all</code></h1>
<p><del>
A new section 30.6.10 shall be inserted at the end of <cxx-ref in="cxx" to="futures"></cxx-ref>. Below is the content of that section.
</del></p>
<p><ins>
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.
</ins></p>
<cxx-function>
<cxx-signature>
template <ins><class InputIterator></ins>
<del><em>see below</em></del>
<ins>future<vector<typename iterator_traits<InputIterator>::value_type>></ins>
when_all(InputIterator first, InputIterator last);
template <<del>typename</del><ins>class</ins>... <del>T</del><ins>Futures</ins>>
<del><em>see below</em></del>
<ins>future<tuple<decay_t<Futures>...>></ins> when_all(<del>T</del><ins>Futures</ins>&&... futures);
</cxx-signature>
<cxx-requires>
<ul>
<li>
<ins>
For the first overload, <code>iterator_traits<InputIterator>::value_type</code> must be <code>future<R></code>
or <code>shared_future<R></code>, for some type <code>R</code>.
</ins>
</li>
<li><del><code>T</code> is of type <code>future<R></code> or <code>shared_future<R></code></del><ins>
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>).
</ins></li>
</ul>
</cxx-requires>
<cxx-Notes>
<ul>
<li><del>There are two variations of <code>when_all</code>. The first version takes a pair of
<code>InputIterators</code>. The second takes any arbitrary number of <code>future<R0></code> and
<code>shared_future<R1></code> objects, where <code>R0</code> and <code>R1</code> need not be the same type.</del></li>
<li>Calling the first <del>signature</del><ins>overload</ins> of <code>when_all</code> where
<code>first == last</code>, returns a <code>future</code>
with an empty vector that is immediately ready.</li>
<li>Calling the second <del>signature</del><ins>overload</ins> of <code><ins>when_all</ins><del>when_any</del></code> with no arguments returns a
<code>future<tuple<>></code> that is immediately ready.</li>
</ul>
</cxx-Notes>
<cxx-remarks>
<ins>
For the second overload, let <em><code>U<sub>i</sub></code></em> be
<code>decay_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 each
<em><code>U<sub>i</sub></code></em> is either <code>future<<em>R<sub>i</sub></em>></code>
or <code>shared_future<<em>R<sub>i</sub></em>></code>.
</ins>
</cxx-remarks>
<cxx-Effects>
<!-- M0when_all_effects -->
<ul>
<li>
<del>
Each <code>future</code> and <code>shared_future</code> is waited upon and then copied into the
collection of the output (returned) <code>future</code>, maintaining the order of the
<code>future</code>s in the input collection.
</del>
<ins>
A new shared state containing a <code>Sequence</code> is
created, where <code>Sequence</code> is either <code>tuple</code> or a
<code>vector</code> based on the overload, as specified above.
A new <code>future</code> object that refers to that shared state is created
and returned from <code>when_all</code>.
</ins>
</li>
<li><ins>
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 <code>future</code>s
are moved, and the <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>Sequence</code> in the shared state.</ins></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>The <code>future</code> returned by <code>when_all</code> will not throw an exception, but the
<code>future</code><ins>s and <code>shared_future</code>s</ins> held in the shared state may.</li>
</ul>
</cxx-Effects>
<cxx-postconditions>
<ul>
<li><ins><code>valid() == true</code><ins>.</li>
<li>For all input <code>future</code>s, <code>valid() == false</code>.</li>
<li>For all <ins>input</ins><del>output</del> <code>shared_future</code>s, <code>valid() == true</code>.</li>
</ul>
</cxx-postconditions>
<cxx-Returns>
<ul>
<li><ins>A <code>future</code> object that becomes ready when all the input
<code>future</code>s/<code>shared_future</code>s are ready.<ins>
</li>
<li><del><code>future<tuple<>></code> if <code>when_all</code> is called with zero arguments.</del></li>
<li><del><code>future<vector<future<R>>></code> if the input cardinality is unknown at compile
and the iterator pair yields <code>future<R></code>. <code>R</code> may be <code>void</code>. The order of the
<code>future</code> in the output vector will be the same as given by the input iterator.</del></li>
<li><del><code>future<vector<shared_future<R>>></code> if the input cardinality is unknown at
compile time and the iterator pair yields <code>shared_future<R></code>. <code>R</code> may be
<code>void</code>. The order of the <code>future</code> in the output vector will be the same as given
by the input iterator.</del></li>
<li>
<del><code>future<tuple<future<R0>, future<R1>, future<R2>...>></code>
if inputs are fixed in
number.
The inputs can be any arbitrary number of <code>future</code> and <code>shared_future</code> objects.
The type of the element at each position of the tuple corresponds to
the type of the argument at the same position. Any of <code>R0</code>, <code>R1</code>, <code>R2</code>, etc.
maybe <code>void</code>.</del>
</li>
</ul>
</cxx-Returns>
</cxx-function>
</cxx-section>
<!-- -->
<!-- M00when_any -->
<!-- -->
<cxx-section id="futures.when_any_result">
<h1><ins>Class template <code>when_any_result</code></ins></h1>
<p><ins>
The library provides a template for storing the result of <code>when_any</code>.
</ins></p>
<pre><code><ins>
template<class Sequence>
struct when_any_result {
size_t index;
Sequence futures;
};
</ins></code></pre>
</cxx-section>
<cxx-section id="futures.when_any">
<h1> Function template <code>when_any</code></h1>
<p><del>
A new section 30.6.11 shall be inserted at the end of <cxx-ref in="cxx" to="futures"></cxx-ref>. Below is the content of that section.
</del></p>
<p><ins>
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.
</ins></p>
<cxx-function>
<cxx-signature>
template <class InputIterator>
<del><em>see below</em></del>
<ins>future<when_any_result<vector<typename iterator_traits<InputIterator>::value_type>>></ins>
when_any(InputIterator first, InputIterator last);
template <<del>typename</del><ins>class</ins>... <del>T</del><ins>Futures</ins>>
<del><em>see below</em></del>
<ins>future<when_any_result<tuple<decay_t<Futures>...>>> when_any(Futures&&... futures);
</ins>
</cxx-signature>
<cxx-requires>
<ul>
<li>
<ins>
For the first overload, <code>iterator_traits<InputIterator>::value_type</code> must be <code>future<R></code>
or <code>shared_future<R></code>, for some type <code>R</code>.
</ins>
</li>
<li><del><code>T</code> is of type <code>future<R></code> or <code>shared_future<R></code></del><ins>
All <code>future</code>s and <code>shared_future</code>s passed into
<code>when_any</code> must be in a valid state (i.e. <code>valid() == true</code>).
</ins></li>
</ul>
</cxx-requires>
<cxx-Notes>
<ul>
<li><del>There are two variations of <code>when_any</code>. The first version takes a pair of
<code>InputIterators</code>. The second takes any arbitrary number of <code>future<R></code> and
<code>shared_future<R></code> objects, where <code>R</code> need not be the same type.</del></li>
<li><del>Calling the first signature of <code>when_any</code> where <code>InputIterator</code> <code>first</code>
equals <code>last</code>, returns a <code>future</code> with an empty vector that is immediately
ready.</del></li>
<li><del>Calling the second signature of <code>when_any</code> with no arguments returns a
<code>future<tuple<>></code> that is immediately ready.</del></li>
<li><ins>Calling the first overload of <code>when_any</code> where
<code>first == last</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
unspecified. The <code>futures</code> field is an empty <code>vector</code>.</ins>
</li>
<li><ins>Calling the second overload of <code>when_any</code> with no arguments 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
unspecified. The <code>futures</code> field is <code>tuple<></code>.</ins>
</li>
</ul>
</cxx-Notes>
<cxx-remarks>
<ins>
For the second overload, let <em><code>U<sub>i</sub></code></em> be
<code>decay_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 each
<em><code>U<sub>i</sub></code></em> is either <code>future<<em>R<sub>i</sub></em>></code>
or <code>shared_future<<em>R<sub>i</sub></em>></code>.
</ins>
</cxx-remarks>
<cxx-Effects>
<!-- M0when_any_effects -->
<ul>
<li><del>Each <code>future</code> and <code>shared_future</code> is waited upon. When at least one is ready,
all the <code>future</code>s are copied into the collection of the output (returned) <code>future</code>,
maintaining the order of the <code>future</code>s in the input collection.</del></li>
<li><ins>
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>.
</ins></li>
<li><ins>
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 <code>future</code>s
are moved, and the <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>Sequence</code> in the shared state.</ins></li>
<li><ins>
The order of the objects in the shared state matches the order
of the arguments supplied to <code>when_any</code>.
</ins></li>
<li>The <code>future</code> returned by <code>when_any</code> will not throw
an exception, but the <code>future</code><ins>s and <code>shared_future</code>s</ins>
held in the shared state may.
</li>
</ul>
</cxx-Effects>
<cxx-postconditions>
<ul>
<li><ins><code>valid() == true</code><ins>.</li>
<li>For all input <code>future</code>s, <code>valid() == false</code>.</li>
<li>For all <ins>input</ins><del>output</del> <code>shared_future</code>s, <code>valid() == true</code>.</li>
</ul>
</cxx-postconditions>
<cxx-Returns>
<ul>
<li><ins>A <code>future</code> object that becomes ready when any of the input
<code>future</code>s/<code>shared_future</code>s are ready.<ins>
</li>
<li><del><code>future<tuple<>></code> if <code>when_any</code> is called with zero arguments.<del></li>
<li><del><code>future<vector<future<R>>></code> if the input cardinality is unknown at compile
time and the iterator pair yields <code>future<R></code>. <code>R</code> may be void. The order of
the <code>future</code> in the output vector will be the same as given by the input
iterator.</del></li>
<li><del><code>future<vector<shared_future<R>>></code> if the input cardinality is unknown at
compile time and the iterator pair yields <code>shared_future<R></code>. <code>R</code> may be
<code>void</code>. The order of the <code>future</code> in the output vector will be the same as given
by the input iterator.</del></li>
<li>
<del><code>future<tuple<future<R0>, future<R1>, future<R2>...>></code>
if inputs are fixed in
number.
The inputs can be any arbitrary number of <code>future</code> and <code>shared_future</code> objects.
The type of the element at each position of the tuple corresponds to
the type of the argument at the same position. Any of <code>R0</code>, <code>R1</code>, <code>R2</code>, etc.
maybe <code>void</code>.</del>
</li>
</ul>
</cxx-Returns>
</cxx-function>
</cxx-section>
<!-- -->
<!-- M00when_any_back -->
<!-- -->
<cxx-section id="futures.when_any_back">
<h1><del>Function template <code>when_any_back</code></del></h1>
<p>
<del>A new section 30.6.12 shall be inserted at the end of <cxx-ref in="cxx" to="futures"></cxx-ref>. Below is the content of that section.
</del>
</p>
<cxx-function>
<cxx-signature><del>
template <class InputIterator>
<em>see below</em>
when_any_back(InputIterator first, InputIterator last);</del>
</cxx-signature>
<cxx-Effects>
<!-- M0when_any_back_effects -->
<ul>
<li><del>Each <code>future</code> and <code>shared_future</code> is waited upon. When at least one is ready,
all the <code>future</code> are copied into the collection of the output (returned)
<code>future</code>.</del></li>
<li><del>The <code>future</code> returned by <code>when_any_back</code> will not throw
an exception, but the <code>future</code>s and <code>shared_future</code>s
held in the shared state may.</del>
</li>
<li><del>After the copy, the <code>future</code> or <code>shared_future</code> that was first detected as
being ready swaps its position with that of the last element of the result
collection, so that the ready <code>future</code> or <code>shared_future</code> may be identified in
constant time. Only one <code>future</code> or <code>shared_future</code> is thus moved.</del></li>
</ul>
</cxx-Effects>
<cxx-postconditions>
<ul>
<li><del><code>valid() == true</code>.</del></li>
<li><del>All input <code>future<T></code>s <code>valid() == false</code>.</del></li>
<li><del>All input <code>shared_future<T></code> <code>valid() == true</code>.</del></li>
</ul>
</cxx-postconditions>
<cxx-Returns>
<ul>
<li><del><code>future<vector<future<R>>></code> if the input cardinality is unknown at compile
time and the iterator pair yields <code>future<R></code>. <code>R</code> may be <code>void</code>.</del></li>
<li><del><code>future<vector<shared_future<R>>></code> if the input cardinality is unknown at
compile time and the iterator pair yields <code>shared_future<R></code>. <code>R</code> may be
<code>void</code>.</del></li>
</ul>
</cxx-Returns>
</cxx-function>
</cxx-section>
<cxx-section id="futures.make_ready_future">
<h1><ins>Function template <code>make_ready_future</code></ins></h1>
<p><ins>
A new section 30.6.13 shall be inserted at the end of <cxx-ref in="cxx" to="futures"></cxx-ref>. Below is the content of that section.
</ins></p>
<cxx-function>
<cxx-signature><ins>
template <class T>
future<V> make_ready_future(T&& value);
future<void> make_ready_future();</ins>
</cxx-signature>
<p><ins>
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>.
</ins></p>
<cxx-Effects>
<ul>
<li><ins>
For the first overload, the value that is passed in to the
function is moved to the shared state of the returned <code>future</code> if it
is an rvalue. Otherwise the value is copied to the shared state of the returned
<code>future</code>.</ins></li>
<li><ins>
The second overload creates a shared state for the returned <code>future</code>.
</ins></li>
</ul>
</cxx-Effects>
<cxx-Returns>
<ul>
<li><ins><code>future<V></code>, if function is given a value of type <code>T</code>.</ins></li>
<li><ins><code>future<void></code>, if the function is not given any inputs.</ins></li>
</ul>
</cxx-Returns>
<cxx-postconditions>
<ul>
<li><ins>Returned <code>future, valid() == true</code>.</ins></li>
<li><ins>Returned <code>future, is_ready() == true</code>.</ins></li>
</ul>
</cxx-postconditions>
</cxx-function>
</cxx-section>
<cxx-section id="futures.make_exceptional_future">
<h1><ins>Function template <code>make_exceptional_future</code></ins></h1>
<p>
<ins>A new section 30.6.13 shall be inserted at the end of <cxx-ref in="cxx" to="futures"></cxx-ref>. Below is the content of that section.</ins>
</p>