-
Notifications
You must be signed in to change notification settings - Fork 26
/
P0009.bs
2521 lines (1998 loc) · 77 KB
/
P0009.bs
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
<pre class='metadata'>
Title: <code>mdspan</code>: A Non-Owning Multidimensional Array Reference
Shortname: D0009
URL: wg21.link/P0009r6
Revision: 7
Audience: LWG
Status: D
Group: WG21
Issue Tracking: GitHub https://github.com/ORNL/cpp-proposals-pub
!Source: <a href="https://github.com/ORNL/cpp-proposals-pub/blob/master/P0009/P0009.bs">github.com/ORNL/cpp-proposals-pub/blob/master/P0009/P0009.bs</a>
No Abstract: yes
Markup Shorthands: markdown yes
Markup Shorthands: biblio yes
Editor: H. Carter Edwards, hedwards@nvidia.com
Editor: Bryce Adelstein Lelbach, blelbach@nvidia.com
Editor: Daniel Sunderland, dsunder@sandia.gov
Editor: David Hollman, dshollm@sandia.gov
Editor: Christian Trott, crtrott@sandia.gov
Editor: Mauro Bianco, mbianco@cscs.ch
Editor: Ben Sander, ben.sander@amd.com
Editor: Athanasios Iliopoulos, athanasios.iliopoulos@nrl.navy.mil
Editor: John Michopoulos, john.michopoulos@nrl.navy.mil
</pre>
Revision History
================
## P0009r7: Post 2018-06-Rapperswil Mailing
- [LWG review at 2018-06-Rapperswil](wiki.edge.com/bin/view/Wg21rapperswil2018/LWGSatAM)
- usage of `span` requires reference to C++20 working draft
- namespace for library TS `std::experimental::fundamentals_v3`
- exposition only members are in italics and each is marked with *exposition only*
## P0009r6 : Pre 2018-06-Rapperswil Mailing
P0009r5 was not taken up at 2018-03-Jacksonville meeting. Related [LEWG
review of P0900 at 2018-03-Jacksonville
meeting](http://wiki.edg.com/bin/view/Wg21jacksonville2018/P0900)
**LEWG Poll**: We want the ability to customize the access to elements
of span (ability to restrict, etc):
```c++
span<T, N, Accessor=...>
```
<table>
<thead>
<tr>
<th>SF</th>
<th>F</th>
<th>N</th>
<th>A</th>
<th>SA</th>
</tr>
</thead>
<tbody>
<tr>
<td> 1 </td>
<td> 1 </td>
<td> 1 </td>
<td> 2 </td>
<td> 8 </td>
</tr>
</tbody>
</table>
**LEWG Poll**: We want the customization of `basic_mdspan` to be two
concepts `Mapper` and `Accessor` (akin to `Allocator` design).
```c++
basic_mdspan<T, Extents, Mapper, Accessor>
mdspan<T, N...>
```
<table>
<thead>
<tr>
<th>SF</th>
<th>F</th>
<th>N</th>
<th>A</th>
<th>SA</th>
</tr>
</thead>
<tbody>
<tr>
<td> 3 </td>
<td> 4 </td>
<td> 5 </td>
<td> 1 </td>
<td> 0 </td>
</tr>
</tbody>
</table>
**LEWG Poll**: We want the customization of `basic_mdspan` to be an
arbitrary (and potentially user-extensible) list of properties.
```c++
basic_mdspan<T, Extents, Properties...>
```
<table>
<thead>
<tr>
<th>SF</th>
<th>F</th>
<th>N</th>
<th>A</th>
<th>SA</th>
</tr>
</thead>
<tbody>
<tr>
<td> 1 </td>
<td> 2 </td>
<td> 2 </td>
<td> 6 </td>
<td> 2 </td>
</tr>
</tbody>
</table>
**Changes from P0009r5 due to related LEWG reviews**:
- Replaced variadic property list with *extents*, *layout mapping*,
and *accessor* properties.
- Incorporated [P0454r1](https://wg21.link/P0454r1).
- Added accessor policy concept.
- Renamed `mdspan` to `basic_mdspan`.
- Added a `mdspan` alias to `basic_mdspan`.
## P0009r5 : Pre 2018-03-Jacksonville Mailing
[LEWG review of P0009r4 at 2017-11-Albuquerque
meeting](http://wiki.edg.com/bin/view/Wg21albuquerque/P0009)
**LEWG Poll**: We should be able to index with `span<int type[N]>` (in
addition to array).
<table>
<thead>
<tr>
<th>SF</th>
<th>F</th>
<th>N</th>
<th>A</th>
<th>SA</th>
</tr>
</thead>
<tbody>
<tr>
<td> 2 </td>
<td>11</td>
<td> 1 </td>
<td> 1 </td>
<td> 0 </td>
</tr>
</tbody>
</table>
Against comment - there is not a proven needs for this feature.
**LEWG Poll**: We should be able to index with 1d `mdspan`.
<table>
<thead>
<tr>
<th>SF</th>
<th>F</th>
<th>N</th>
<th>A</th>
<th>SA</th>
</tr>
</thead>
<tbody>
<tr>
<td> 0 </td>
<td> 8 </td>
<td> 7 </td>
<td> 0 </td>
<td> 0 </td>
</tr>
</tbody>
</table>
**LEWG Poll**: We should put the requirement on "rank() <= N" back to
"rank() == N".
*Unanimous consent*
**LEWG Poll**: With the editorial changes from small group, plus the
above polls, forward this to LWG for Fundamentals v3.
*Unanimous consent*
**Changes from P0009r4**:
- Removed nullptr constructor.
- Added constexpr to indexing operator.
- Indexing operator requires that `rank() == sizeof...(indices)`.
- Fixed typos in examples and moved them to appendix.
- Converted note on how extentions to access properties may cause
reference to be a proxy type to an "see below" to make it
normative.
## P0009r4 : Pre 2017-11-Albuquerque Mailing
[LEWG review at 2017-03-Kona meeting](http://wiki.edg.com/bin/view/Wg21kona2017/P0009)
[LEWG review of P0546r1 at 2017-03-Kona meeting](http://wiki.edg.com/bin/view/Wg21kona2017/P0546)
**LEWG Poll**: Should we have a single template that covers both single
and multi-dimensional spans?
<table>
<thead>
<tr>
<th>SF</th>
<th>F</th>
<th>N</th>
<th>A</th>
<th>SA</th>
</tr>
</thead>
<tbody>
<tr>
<td> 1 </td>
<td> 6 </td>
<td> 2 </td>
<td> 6 </td>
<td> 3 </td>
</tr>
</tbody>
</table>
**Changes from P0009r3**:
- Align with P0122r5 span[proposal](https://wg21.link/P0122r5).
- Rename to `mdspan`, multidimensional span, to align with `span`.
- Move preferred array extents mechanism to appendix.
- Expose codomain as a `span`.
- Add layout mapping concept.
## P0009r3 : Post 2016-06-Oulu Mailing
[LEWG review at 2016-06-Oulu](http://wiki.edg.com/bin/view/Wg21oulu/P0009)
LEWG did not like the name `array_ref`, and suggested the following
alternatives: - `sci_span` - `numeric_span` - `multidimensional_span` -
`multidim_span` - `mdspan` - `md_span` - `vla_span` - `multispan` -
`multi_span`
**LEWG Poll**: Are member `begin()`/`end()` still good?
<table>
<thead>
<tr>
<th>SF</th>
<th>F</th>
<th>N</th>
<th>A</th>
<th>SA</th>
</tr>
</thead>
<tbody>
<tr>
<td>0</td>
<td> 2 </td>
<td> 4 </td>
<td> 3 </td>
<td> 1 </td>
</tr>
</tbody>
</table>
**LEWG Poll**: Want this proposal to provide range-producing functions
outside `array_ref`?
<table>
<thead>
<tr>
<th>SF</th>
<th>F</th>
<th>N</th>
<th>A</th>
<th>SA</th>
</tr>
</thead>
<tbody>
<tr>
<td> 0 </td>
<td> 1 </td>
<td> 3 </td>
<td> 2 </td>
<td> 3 </td>
</tr>
</tbody>
</table>
**LEWG Poll**: Want a separate proposal to explore iteration design
space?
<table>
<thead>
<tr>
<th>SF</th>
<th>F</th>
<th>N</th>
<th>A</th>
<th>SA</th>
</tr>
</thead>
<tbody>
<tr>
<td> 9 </td>
<td> 1 </td>
<td> 0 </td>
<td> 0 </td>
<td> 0 </td>
</tr>
</tbody>
</table>
**Changes from P0009r2**:
- Removed iterator support; a future paper will be written on the
subject.
- Noted difference between multidimensional array versus language's
array-of-array-of-array...
- Clearly describe requirements for the embedded type aliases
(`element_type`, `reference`, etc).
- Expanded description of how the variadic properties list would
work.
- Stopped allowing `array_ref<T[N]>` in addition to
`array_ref<extents<N>>`.
- Clarified domain, codomain, and domain -> codomain mapping
specifications.
- Consistently use *extent* and *extents* for the multidimensional
index space.
## P0009r2 : Pre 2016-06-Oulu Mailing
[LEWG review at 2016-02-Jacksonville](http://wiki.edg.com/bin/view/Wg21jacksonville/P0009).
**Changes from P0009r1**:
- Adding details for extensibility of layout mapping.
- Move motivation, examples, and relaxed incomplete array type
proposal to separate papers.
- [P0331: Motivation and Examples for Polymorphic
Multidimensional Array](https://wg21.link/P0331).
- [P0332: Relaxed Incomplete Multidimensional Array Type
Declaration](https://wg21.link/P0332).
## P0009r1 : Pre 2016-02-Jacksonville Mailing
[LEWG review at 2015-10-Kona](http://wiki.edg.com/bin/view/Wg21kona2015/P0009).
**LEWG Poll**: What should this feature be called?
<table>
<thead>
<tr>
<th>Name</th>
<th>#</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>view</code></td>
<td> 5 </td>
</tr>
<tr>
<td><code>span</code></td>
<td> 9 </td>
</tr>
<tr>
<td><code>array_ref</code></td>
<td> 6 </td>
</tr>
<tr>
<td><code>slice</code></td>
<td> 6 </td>
</tr>
<tr>
<td><code>array_view</code></td>
<td> 6 </td>
</tr>
<tr>
<td><code>ref</code></td>
<td> 0 </td>
</tr>
<tr>
<td><code>array_span</code></td>
<td> 7 </td>
</tr>
<tr>
<td><code>basic_span</code></td>
<td> 1 </td>
</tr>
<tr>
<td><code>object_span</code></td>
<td> 3 </td>
</tr>
<tr>
<td><code>field</code></td>
<td> 0 </td>
</tr>
</tbody>
</table>
**LEWG Poll**: Do we want 0-length static extents?
<table>
<thead>
<tr>
<th>SF</th>
<th>F</th>
<th>N</th>
<th>A</th>
<th>SA</th>
</tr>
</thead>
<tbody>
<tr>
<td> 3 </td>
<td> 4 </td>
<td> 2 </td>
<td> 3 </td>
<td> 0 </td>
</tr>
</tbody>
</table>
**LEWG POLL**: Do we want the language to support syntaxes like
`X[3][][][5]`?
<table>
<thead>
<tr>
<th>Syntax</th>
<th>#</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>view<int[3][0][][5], property1></code></td>
<td>12</td>
</tr>
<tr>
<td><code>view<int, dimension<3, 0, dynamic_extent, 5>, property1></code></td>
<td> 4 </td>
</tr>
<tr>
<td><code>view<int[3][0][dynamic_extent][5], property1></code></td>
<td> 5 </td>
</tr>
<tr>
<td><code>view<int, 3, 0, dynamic_extent, 5, property1></code></td>
<td> 4 </td>
</tr>
<tr>
<td><code>view<int, 3, 0, dynamic_extent, 5, properties<property1>></code></td>
<td> 2 </td>
</tr>
<tr>
<td><code>view<arr<int, 3, 0, dynamic_extent, 5>, property1></code></td>
<td> 4 </td>
</tr>
<tr>
<td><code>view<int[3][0][][5], properties<property1>></code></td>
<td> 9 </td>
</tr>
</tbody>
</table>
**LEWG POLL**: Do we want the variadic property list in template args
(either raw or in `properties<>`)? Note there is no precedence for this
in the library.
<table>
<thead>
<tr>
<th>SF</th>
<th>F</th>
<th>N</th>
<th>A</th>
<th>SA</th>
</tr>
</thead>
<tbody>
<tr>
<td> 3 </td>
<td> 6 </td>
<td> 3 </td>
<td> 0 </td>
<td> 0 </td>
</tr>
</tbody>
</table>
**LEWG POLL**: Do we want the per-view bounds-checking knob?
<table>
<thead>
<tr>
<th>SF</th>
<th>F</th>
<th>N</th>
<th>A</th>
<th>SA</th>
</tr>
</thead>
<tbody>
<tr>
<td> 3 </td>
<td> 4 </td>
<td> 1 </td>
<td> 2 </td>
<td> 1 </td>
</tr>
</tbody>
</table>
**Changes from P0009r0**:
- Renamed `view` to `array_ref`.
- How are users allowed to add properties? Needs elaboration in
paper.
- `view<int[][][]>::layout` should be named.
- Rename `is_regular` (possibly to `is_affine`) to avoid overloading
the term with the `Regular` concept.
- Make static span(), operator(), constructor, etc variadic.
- Demonstrate the need for improper access in the paper.
- In `operator()`, take integral types by value.
## P0009r0 : Pre 2015-10-Kona Mailing
Original non-owning multidimensional array reference (`view`) paper with
motivation, specification, and examples.
## Related Activity
Related [LEWG review of P0546r1 at 2017-11-Albuquerque meeting](http://wiki.edg.com/bin/view/Wg21albuquerque/P0546)
**LEWG Poll**: `span` should specify the dynamic extent as the element
type of the first template parameter rather than the (current) second
template parameter
<table>
<thead>
<tr>
<th>SF</th>
<th>F</th>
<th>N</th>
<th>A</th>
<th>SA</th>
</tr>
</thead>
<tbody>
<tr>
<td> 5 </td>
<td> 3 </td>
<td> 2 </td>
<td> 2 </td>
<td> 0 </td>
</tr>
</tbody>
</table>
**LEWG Poll**: `span` should support the addition of access properties
variadic template parameters
<table>
<thead>
<tr>
<th>SF</th>
<th>F</th>
<th>N</th>
<th>A</th>
<th>SA</th>
</tr>
</thead>
<tbody>
<tr>
<td>0</td>
<td>10</td>
<td> 1 </td>
<td> 5 </td>
<td> 0 </td>
</tr>
</tbody>
</table>
Authors agreed to bring a separate paper
([[P0900r0]]) discussing how the variadic
properties will work.
Description
===========
The proposed polymorphic multidimensional array reference (`mdspan`)
defines types and functions for mapping indices from the **domain**, a
**multidimensional index space**, to the **codomain**, elements of a
contiguous span of objects. A multidimensional index space is defined as
the Cartesian product of integer extents, *[0..N0) X [0..N1) X [0..N2) ...*.
An `mdspan` has two policies: the **layout mapping**
and the **accessor**. The layout mapping specifies the formula, and
properties of the formula, for mapping a multi-index from the domain to
an element in the codomain. The accessor is an extension point that
allows modification of how elements are accessed. For example, the
Accessors paper (P0367) proposed a rich set of potential access
properties.
**A multidimensional array is not an array-of-array-of-array-of-array...**
The multidimensional array abstraction has been fundamental to numerical
computations for over five decades. However, the C/C++ language provides
only a one dimensional array abstraction which can be composed into
array-of-array-of-array... types. While such types have some similarity
to multidimensional arrays they do not provide adequate multidimensional
array functionality of this proposal. Two critical functionality
differences are (1) multiple dynamic extents and (2) polymorphic mapping
of multi-indices to element objects.
**Optimized Implementation of Layout Mapping**
The layout mapping of a multi-index intended to be an O(1) constexpr
operation that is trivially inlined and optimized. Note that FORTRAN
compilers' optimizations include loop invariant code motion, including
partial evaluation of multi-index layout mappings when indices are
loop-invariant.
Editing Notes
=============
The proposed changes are relative to the working draft of the standard
as of \[N4750](http://wg21.link/n4750).
The � character is used to denote a placeholder section number, table number,
or paragraph number which the editor shall determine.
Add the header `<mdspan>` to table 16 in **[headers]**.
Add the header `<mdspan>` to Table 76 in 26.1 **[containers.general]** below
the listing for `<span>`.
Wording
=======
---
<br/>
*Add the following paragraphs to* **[views.general]*:
�. The header `<mdspan>` defines the view `basic_mdspan`, the type alias `mdspan`,
and other facilities for interacting with these views.
The `basic_mdspan` class template maps a multi-index within a multi-index *domain*
to a reference an element in the *codomain* `span`.
�. The `subspan` function generates a `basic_mdspan` with a domain
contained within the input `basic_mdspan` domain and codomain contained
within the input `basic_mdspan` codomain.
---
<br/>
*Add the following subclauses to the end of the* **[views]** *subclause (currently 26.7)*:
<!--
.d8888b. d8b
d88P Y88b Y8P
Y88b.
"Y888b. 888 888 88888b. .d88b. 88888b. .d8888b 888 .d8888b
"Y88b. 888 888 888 "88b d88""88b 888 "88b 88K 888 88K
"888 888 888 888 888 888 888 888 888 "Y8888b. 888 "Y8888b.
Y88b d88P Y88b 888 888 888 Y88..88P 888 d88P X88 888 X88
"Y8888P" "Y88888 888 888 "Y88P" 88888P" 88888P' 888 88888P'
888 888
Y8b d88P 888
"Y88P" 888
-->
<!-- TODO references to subclauses in synopsis comments -->
<br/>
<b>26.7.� Header `<mdspan>` synopsis [mdspan.syn]</b>
```c++
namespace std {
namespace experimental {
namespace fundamentals_v3 {
// [mdspan.extents], class template extents
template<ptrdiff_t... StaticExtents>
class extents;
// [mdspan.layout], Layout mapping policies
class layout_left;
class layout_right;
class layout_stride;
// [mdspan.accessor.basic], class template accessor_basic
template<class ElementType>
class accessor_basic;
// [mdspan.basic], class template mdspan
template<class ElementType,
class Extents,
class LayoutPolicy = layout_right,
class Accessor = accessor_basic<ElementType>>
class basic_mdspan;
template<class T, ptrdiff_t... Extents>
using mdspan = basic_mdspan<T, extents<Extents...>>;
// [mdspan.extents.compare], extents comparison operators
template<ptrdiff_t... LHS, ptrdiff_t... RHS>
constexpr bool operator==(const extents<LHS...>& lhs, const extents<RHS...>& rhs) noexcept;
template<ptrdiff_t... LHS, ptrdiff_t... RHS>
constexpr bool operator!=(const extents<LHS...>& lhs, const extents<RHS...>& rhs) noexcept;
// [mdspan.subspan], subspan creation
template<class ElementType, class Extents, class LayoutPolicy,
class Accessor, class... SliceSpecifiers>
basic_mdspan<ElementType, /* see-below */>
subspan(const basic_mdspan<ElementType, Extents, LayoutPolicy, Accessor>&, SliceSpecifiers...) noexcept;
// tag supporting subspan
struct all_type {};
inline constexpr all_type all = all_type{};
}}}
```
<!--
888 888
888 888
888 888
.d88b. 888 888 888888 .d88b. 88888b. 888888 .d8888b
d8P Y8b `Y8bd8P' 888 d8P Y8b 888 "88b 888 88K
88888888 X88K 888 88888888 888 888 888 "Y8888b.
Y8b. .d8""8b. Y88b. Y8b. 888 888 Y88b. X88
"Y8888 888 888 "Y888 "Y8888 888 888 "Y888 88888P'
-->
<b>26.7.� Class template `extents` [mdspan.extents]</b>
<b>26.7.�.1 Overview [mdspan.extents.overview]</b>
1. An `extents` object defines a *multidimensional index space* which is the Cartesian product of integers extents *[0..N0) X [0..N1) X ...*.
2. The *dynamic extents* of an `extents` object correspond to the `StaticExtents` template parameters that are equal to `dynamic_extent`. Let *DynamicRank[i]* denote the index of the *i*th such extent in the `StaticExtents` template parameter pack, and let *DynamicIndex[r]* indicate the number of such extents in the first *r* entries of the `StaticExtents` parameter pack
3. An `extents` object is expected to store dynamic extents. *[Note:* An implementation should not consume storage for static extents. *— end note]*
4. If any of `StaticExtents` are negative and not equal to `dynamic_extent`, the program is ill-formed.
<!-- TODO review change to make rank() and rank_dynamic() size_t -->
<!-- TODO review addition of array constructor -->
<!-- TODO review addition of compatible extents constructor -->
<!-- TODO comparison operators -->
<!-- TODO initializer list constructor? -->
```c++
namespace std {
namespace experimental {
namespace fundamentals_v3 {
template<ptrdiff_t... StaticExtents>
class extents {
public:
// types
using index_type = ptrdiff_t;
// 26.7.�.2 Constructors and assignment
constexpr extents() noexcept;
constexpr extents(const extents&) noexcept;
constexpr extents(extents&&) noexcept;
template<class... IndexType>
constexpr extents(IndexType... dynamic_extents) noexcept;
template<class IndexType, size_t N>
constexpr extents(const array<IndexType, N>&) noexcept;
template<ptrdiff_t... OtherStaticExtents>
constexpr extents(const extents<OtherStaticExtents...>& other) noexcept;
~extents() = default;
constexpr extents& operator=(const extents&) noexcept = default;
constexpr extents& operator=(extents&&) noexcept = default;
template<ptrdiff_t... OtherStaticExtents>
constexpr extents& operator=(const extents<OtherStaticExtents...>& other) noexcept;
// 26.7.�.3 Observers of the index space domain:
static constexpr size_t rank() noexcept;
static constexpr size_t rank_dynamic() noexcept;
static constexpr index_type static_extent(int) noexcept;
constexpr index_type extent(int) const noexcept;
private:
array<index_type, rank_dynamic()> dynamic_extents_; // exposition only
};
}}}
```
<b>26.7.�.2 Constructors and assignment [mdspan.extents.cons]</b>
```c++
constexpr extents() noexcept;
```
* *Effects:* Aggregate-initializes `dynamic_extents_` to `{ }`
* *Postconditions:* `extent(r)` if `static_extent(r) == dynamic_extent` for all `r` in the range `[0, rank())`
<br/>
```c++
constexpr extents(const extents& other);
constexpr extents(extents&& other);
```
<!-- TODO Review this. Should this be two different sections, or does it not matter for move initialization of array? -->
* *Effects:* Initializes `dynamic_extents_` with `other.dynamic_extents_`
* *Postconditions:* `extent(r) == other.extent(r)` for all `r` in the range `[0, rank())`
<br/>
```c++
template<ptrdiff_t... OtherStaticExtents>
constexpr extents(const extents<OtherStaticExtents...>& other) noexcept;
```
* *Requires:* For each `r` in the range `[0, rank())`, if `static_extent(r) != dynamic_extent` and `other.static_extent(r) == dynamic_extent`, then `static_extent(r) == other.extent(r)`.
* *Effects:* For each `r` in the range `[0, rank())`, if `static_extent(r) == dynamic_extent`, initializes `dynamic_extents_[`*DynamicRank[*`r`*]*`]` with `other.extent(r)`.
* *Postconditions:* `*this == other`
* *Remarks:* This constructor shall not participate in overload resolution unless `sizeof...(StaticExtents) == sizeof...(OtherStaticExtents)`.
<br/>
```c++
template<class... IndexType>
constexpr extents(IndexType... dynamic_extents) noexcept;
```
<!-- TODO look at how parameter pack expansions are specified in, e.g., integer_sequence -->
<!-- TODO @CRT: Please review to make sure this is the desired behavior -->
* *Requires:* `((dynamic_extents >= 0) && ...)`
* *Effects:* Aggregate-initializes `dynamic_extents_` to `{dynamic_extents...}`
* *Postconditions:* `extent(`*DynamicRank[i]*`)` is equal to the *i*th entry in the parameter pack `dynamic_extents`
* *Remarks:* This constructor shall not participate in overload resolution unless:
+ `(is_convertible_v<IndexType, index_type> && ...)`
+ and `sizeof...(dynamic_extents) == rank_dynamic()`
```c++
template<class IndexType, size_t N>
constexpr extents(const array<IndexType, N> & dynamic_extents) noexcept;
```
* *Requires:* `dynamic_extents[i] >= 0` for all `i` where `0 <= i <= rank_dynamic()`
* *Effects:* Initializes `dynamic_extents_` with `dynamic_extents`
* *Postconditions:* `extent(`*DynamicRank[i]*`)` is equal to `dynamic_extents[i]`
* *Remarks:* This constructor shall not participate in overload resolution unless:
+ `is_convertible_v<IndexType, index_type>`
+ `N == rank_dynamic()`
```c++
template<ptrdiff_t... OtherStaticExtents>
constexpr extents& operator=(const extents<OtherStaticExtents...>& other) noexcept;
```
* *Requires:* For each `r` in the range `[0, rank())`, if `static_extent(r) != dynamic_extent` and `other.static_extent(r) == dynamic_extent`, then `static_extent(r) == other.extent(r)`.
* *Effects:* For each `r` in the range `[0, rank())`, if `static_extent(r) == dynamic_extent`, assigns `dynamic_extents_[`*DynamicRank[*`r`*]*`]` to `other.extent(r)`.
* *Postconditions:* `*this == other`
* *Returns:* `*this`.
* *Remarks:* This constructor shall not participate in overload resolution unless `sizeof...(StaticExtents) == sizeof...(OtherStaticExtents)`.
<br/>
<br/>
<b>26.7.�.3 Observers of the domain multi-index space [mdspan.extents.obs]</b>
<br/>
```c++
static constexpr size_t rank() const noexcept;
```
* *Returns:* `sizeof...(StaticExtents)`
<br/>
```c++
static constexpr size_t rank_dynamic() const noexcept;
```
<!-- DSH: Added note because I was afraid I was being too clever -->
* *Returns:* `((StaticExtents == dynamic_extent) + ...)` *[Note:* This is the number of dynamic extents *—end note]*
<br/>
```c++
static constexpr index_type static_extent(int r) const noexcept;
```
* *Returns:* The `r`th entry in the `StaticExtents` parameter pack if 0 <= `r` < `rank()`, or 1 otherwise.
<br/>
```c++
constexpr index_type extent(int r) const noexcept;
```
<!-- TODO Does this need an example? -->
* *Returns:*
* If `static_extent(r) == dynamic_extent`, then `dynamic_extents_[`*DynamicRank[*`r`*]*`]`.
* Otherwise, `static_extent(r)`.
<br/>
<b>26.7.�.4 `extents` comparison operators [mdspan.extents.compare]</b>
```c++
template<ptrdiff_t... LHS, ptrdiff_t... RHS>
constexpr bool operator==(const extents<LHS...>& lhs, const extents<RHS...>& rhs) noexcept;
```
* *Returns:* `true` if `lhs.rank() == rhs.rank()` and `lhs.extents(r) == rhs.extents(r)` for all `r` in the range `[0, lhs.rank())`, or `false` otherwise.
<br/>
```c++
template<ptrdiff_t... LHS, ptrdiff_t... RHS>
constexpr bool operator!=(const extents<LHS...>& lhs, const extents<RHS...>& rhs) noexcept;
```
* *Returns:* `!(lhs == rhs)`
<!--
888 888 d8b
888 888 Y8P
888 888
888 8888b. 888 888 .d88b. 888 888 888888 88888b.d88b. 8888b. 88888b. 88888b. 888 88888b. .d88b.
888 "88b 888 888 d88""88b 888 888 888 888 "888 "88b "88b 888 "88b 888 "88b 888 888 "88b d88P"88b
888 .d888888 888 888 888 888 888 888 888 888 888 888 .d888888 888 888 888 888 888 888 888 888 888
888 888 888 Y88b 888 Y88..88P Y88b 888 Y88b. 888 888 888 888 888 888 d88P 888 d88P 888 888 888 Y88b 888
888 "Y888888 "Y88888 "Y88P" "Y88888 "Y888 888 888 888 "Y888888 88888P" 88888P" 888 888 888 "Y88888
888 888 888 888
Y8b d88P 888 888 Y8b d88P
"Y88P" 888 888 "Y88P"
-->
<br/>
<br/>
<b>26.7.� Layout mapping policy [mdspan.layout]</b>
<b>26.7.�.1 Layout mapping requirements [mdspan.layout.reqs]</b>
1. A *layout mapping policy* is a class that contains a *layout mapping*, a nested class template.
2. A *layout mapping policy* shall meet the requirements in table �.
3. A *layout mapping* shall meet the requirements of `DefaultConstructible`, `CopyAssignable`, `EqualityComparable`, and the requirements in table �.
4. In Table �:
* `MP` denotes a layout mapping policy.
* `E` denotes a specialization of `extents`.
* `e` denotes an object of type `E` defining a domain multi-index space.
* `r` is a value of an integral type such that `0 <= r < e.rank()`.
* `i...` and `j...` are packs of an integer type denoting values in the multi-index space `e`, the `r`*th member of packs `i...` and `j...` are denoted by `i[r]` and `j[r]`, and `sizeof...(i) == E::rank()` and `0 <= i[r] < e.extent(r)` for `i...` and `j...`.
* `M` denotes a layout mapping class.
* `m` denotes an object of type `M` that maps a multi-index `i...` to an integral value.
<!-- TODO @CRT and @HCE: Review minor design change consolidating extents-like member functions into get_extents() -->
Table � — Layout mapping policy and layout mapping requirements
<table border=1>
<tr>
<th>Expression</th>
<th>Return Type</th>
<th>Operational Semantics</th>
<th>Requires/Remarks</th>
</tr>
<tr>
<td>`MP::mapping<E>`</td>
<td>`M`</td>
<td></td>
<td></td>
</tr>
<tr>
<td>`m.get_extents()`</td>
<td>`E`</td>
<td>
*Returns:* `e`.
</td>
<td></td>
</tr>
<tr>
<td>`m(i...)`</td>
<td>`E::index_type`</td>