-
Notifications
You must be signed in to change notification settings - Fork 0
/
array-proposal.html
842 lines (705 loc) · 39.6 KB
/
array-proposal.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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=us-ascii">
<title>Proposal to Add Multi-Dimensional Support to std::array</title>
<meta name="generator" content="Amaya, see http://www.w3.org/Amaya/">
<style type="text/css">
ins { background-color: #A0FFA0 }
del { background-color: #FFA0A0 }
</style>
</head>
<body>
<pre>Document number: Dnnnn
Project: Programming Language C++, Library Working Group
Date: 2013-11-18
Reply-to: Daryle Walker <darylew at gmail dot com></pre>
<h1>Proposal to Add Multi-Dimensional Support to <code>std::array</code>,
Version 2</h1>
<h2 id="Ch01">I. Table of Contents</h2>
<ol>
<li><a href="#Ch01">Table of Contents</a></li>
<li><a href="#Ch02">Introduction</a></li>
<li><a href="#Ch03">Motivation and Scope</a></li>
<li><a href="#Ch04">Impact on the Standard</a></li>
<li><a href="#Ch05">Design Decisions</a></li>
<li><a href="#Ch06">Technical Specifications</a></li>
<li><a href="#Ch07">Acknowledgments</a></li>
<li><a href="#Ch08">History</a></li>
<li><a href="#Ch09">References</a></li>
</ol>
<h2 id="Ch02">II. Introduction</h2>
<p>The <code>std::array</code> class template adapts array types to standard
library classes. But the adaptation is only for the outermost level; the inner
dimensions of a multidimensional array type are not considered. This proposal
is to change <code>std::array</code> to take multiple dimensions as variadic
template arguments.</p>
<h2 id="Ch03">III. Motivation and Scope</h2>
<p>When reading up on the variadic template feature, I made a multidimensional
variant of <code>std::array</code> as an exercise. After making the
single-extent case compatible with <code>std::array</code>, I realized it is
better to propose a change in <code>std::array</code> instead of creating a
near-identical class template. The exercise code, at <<a
href="https://github.com/CTMacUser/ArrayMD">https://github.com/CTMacUser/ArrayMD</a>>,
could be considered as a reference implementation and test suite.</p>
<p>I later found out that a multidimensional array class template was one of
the examples given in the original variadic template proposal.</p>
<p>With constructions that can express array types and array subscript usage in
comma-separated lists, array entities may be invoked during variadic template-
and function-argument processing.</p>
<p>This implementation makes multidimensional arrays by nesting at the array
type level. A more common, and requested, variant is to apply the nesting at
the class type level. An alias template that exposes the class-nesting style
has been added.</p>
<h2 id="Ch04">IV. Impact on the Standard</h2>
<p>The proposal adds two class templates (and corresponding type-alias
templates), one more alias template, three function templates, and several
members to an existing class template. It modifies descriptions of
<code>std::array</code> in the sequence container requirements. And it modifies
the relational operator function templates to take mixed element types. The
implementation should work with current language features.</p>
<h2 id="Ch05">V. Design Decisions</h2>
<p>I adapted <code>std::array</code> for multidimensional arrays by making the
inner array object a built-in multidimensional array type. Since built-in types
are used, only the first level of access via <code>operator []()</code> has to
be a function instead of a built-in operation. Similar multidimensional
container libraries where the array class template consists of nested
instantiations of itself have the disadvantages of possible padding (making the
elements noncontiguous) and of working in the wrong units (the largest
sub-array type instead of the user's original element type).</p>
<p>The implementation is mostly as straight forward as the current
<code>std::array</code>, so there is not much effort needed from
implementers.</p>
<p>The data within <code>std::array</code> is fixed as being implemented as one
non-static data member so brace-elision for class types, as described in N3526
and similar proposals, may be enabled for <code>array</code>. The section about
the creation functions (23.3.2.A) assumes that proposal is in force.</p>
<p>The creation functions have been influenced by similar ones proposed in
N3824. This proposal shall take N3824's stance on
<code>std::reference_wrapper</code> and block its instantiations from being
used with the <code>make_array</code> overload that (completely) deduces the
<code>std::array</code> instantiation return type. This proposal needs both the
element type and dimension(s) shape for the <code>make_array</code> overload
needing at least the <code>array</code> element type, while N3824 also needs
the element type but automatically sets the shape to a fitted linear array.</p>
<h2 id="Ch06">VI. Technical Specifications</h2>
<p>The changes are based off C++ Working Draft Standard N3797. The section
numbers for new sections have letters as place-holders; the final numbers, plus
moving existing section numbers to fit, are to be determined later.</p>
<p>In section 20.10.2 [meta.type.synop], change the subsection introducing
array modifications:</p>
<blockquote>
<pre><i>// 20.10.7.4, array modifications:</i>
template <class T> struct remove_extent;
template <class T> struct remove_all_extents;
<ins>template <class T, size_t I> struct remove_some_extents;
template <class T, size_t... N> struct append_extents;</ins>
template <class T>
using remove_extent_t = typename remove_extent<T>::type;
template <class T>
using remove_all_extents_t = typename remove_all_extents<T>::type;
<ins>template <class T, size_t I>
using remove_some_extents_t = typename remove_some_extents<T, I>::type;
template <class T, size_t... N>
using append_extents_t = typename append_extents<T, N...>::type;</ins></pre>
</blockquote>
<p>In section 20.10.7.4 [meta.trans.arr], add a third and fourth row to Table
55:</p>
<blockquote>
<table border="1">
<caption>Addition to: Table 55 — Array modifications</caption>
<thead>
<tr>
<th>Template</th>
<th>Comments</th>
</tr>
</thead>
<tbody>
<tr>
<td><pre>template <class T, size_t I>
struct remove_some_extents;</pre>
</td>
<td>If <code>I</code> is zero, then the member typedef
<code>type</code> shall be <code>T</code>. Otherwise, the member
typedef <code>type</code> shall be the same as applying
<code>remove_extent</code> <code>I</code> times. [<em>Note:</em> When
<code>T</code> is either a non-array type or an array type with an
extent count at most <code>I</code>, this class template acts like
<code>remove_all_extents</code>. <em>—end note</em>]</td>
</tr>
<tr>
<td><pre>template <class T, size_t... N>
struct append_extents;</pre>
</td>
<td>If <code>N</code> is an empty parameter pack, then the member
typedef <code>type</code> shall be <code>T</code>. Otherwise, let
<var><code>X</code></var> be the first entry of <code>N</code>,
<var><code>Y</code></var> be a (possibly empty) parameter pack
representing the remainder of <code>N</code>, and
<var><code>U</code></var> be an alias to <code>typename
append_extents<T, Y...>::type</code>. Then the member typedef
<code>type</code> shall alias <code>U[X]</code> when <code>X</code>
is non-zero, else it shall alias <code>U[]</code>. [<em>Note:</em>
Since an array of unknown bound is not permitted to be an array
element type (8.3.4), only the first (i.e. left-most) entry of
<code>N</code> may be zero. <em>—end note</em>]</td>
</tr>
</tbody>
</table>
</blockquote>
<p>and add a third example:</p>
<blockquote>
<p><strong>-3-</strong> [<em>Example</em></p>
<pre><i>// the following assertions hold:</i>
assert((is_same<remove_some_extents<int, 0>::type, int>::value));
assert((is_same<remove_some_extents<int, 1>::type, int>::value));
assert((is_same<remove_some_extents<int[2], 0>::type, int[2]>::value));
assert((is_same<remove_some_extents<int[2], 1>::type, int>::value));
assert((is_same<remove_some_extents<int[2], 2>::type, int>::value));
assert((is_same<remove_some_extents<int[2][3], 0>::type, int[2][3]>::value));
assert((is_same<remove_some_extents<int[2][3], 1>::type, int[3]>::value));
assert((is_same<remove_some_extents<int[2][3], 2>::type, int>::value));
assert((is_same<remove_some_extents<int[][3], 0>::type, int[][3]>::value));
assert((is_same<remove_some_extents<int[][3], 1>::type, int[3]>::value));
assert((is_same<remove_some_extents<int[][3], 2>::type, int>::value));
assert((is_same<remove_some_extents<int[][3], 3>::type, int>::value));</pre>
<p><em>—end example</em>]</p>
</blockquote>
<p>In section 23.2.3 [sequence.reqmts], modify the last column for the last two
rows of Table 101:</p>
<blockquote>
<table border="1">
<caption>Modification to: Table 101 — Optional sequence container
operations (continued)</caption>
<thead>
<tr>
<th>Expression</th>
<th>Return type</th>
<th>Operational semantics</th>
<th>Container</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>a[n]</code></td>
<td><code>reference</code>; <code>const_reference</code> for constant
<code>a</code></td>
<td><code>*(a.begin() + n)</code></td>
<td><code>basic_string</code>, <code>array</code> <ins>(with one
extent)</ins>, <code>deque</code>, <code>dynarray</code>,
<code>vector</code></td>
</tr>
<tr>
<td><code>a.at(n)</code></td>
<td><code>reference</code>; <code>const_reference</code> for constant
<code>a</code></td>
<td><code>*(a.begin() + n)</code></td>
<td><code>basic_string</code>, <code>array</code> <ins>(with one
extent)</ins>, <code>deque</code>, <code>dynarray</code>,
<code>vector</code></td>
</tr>
</tbody>
</table>
</blockquote>
<p>and modify the paragraph that follows that table:</p>
<blockquote>
<p><strong>-17-</strong> The member function <code>at()</code> provides
bounds-checked access to container elements. <code>at()</code> throws
<code>out_of_range</code> if <code>n >= a.size()</code>. <ins>For
instantiations of <code>array</code> with an extent count besides one, there
are modifications (23.3.2.D) to the return types and the operational
semantics of <code>a[n]</code> and <code>a.at()</code>.</ins> </p>
</blockquote>
<p>In section 23.3.1 [sequences.general], modify the "<strong>Header
<code><array></code> synopsis</strong>":</p>
<blockquote>
<pre>#include <initializer_list>
<ins>#include <type_traits></ins>
namespace std {
template <class T, size_t<ins>...</ins> N > struct array;
template <class T, <ins>class U,</ins> size_t<ins>...</ins> N>
bool operator==(const array<T,N<ins>...</ins>>& x, const array<<del>T</del><ins>U</ins>,N<ins>...</ins>>& y);
template <class T, <ins>class U,</ins> size_t<ins>...</ins> N>
bool operator!=(const array<T,N<ins>...</ins>>& x, const array<<del>T</del><ins>U</ins>,N<ins>...</ins>>& y);
template <class T, <ins>class U,</ins> size_t<ins>...</ins> N>
bool operator<(const array<T,N<ins>...</ins>>& x, const array<<del>T</del><ins>U</ins>,N<ins>...</ins>>& y);
template <class T, <ins>class U,</ins> size_t<ins>...</ins> N>
bool operator>(const array<T,N<ins>...</ins>>& x, const array<<del>T</del><ins>U</ins>,N<ins>...</ins>>& y);
template <class T, <ins>class U,</ins> size_t<ins>...</ins> N>
bool operator<=(const array<T,N<ins>...</ins>>& x, const array<<del>T</del><ins>U</ins>,N<ins>...</ins>>& y);
template <class T, <ins>class U,</ins> size_t<ins>...</ins> N>
bool operator>=(const array<T,N<ins>...</ins>>& x, const array<<del>T</del><ins>U</ins>,N<ins>...</ins>>& y);
template <class T, size_t<ins>...</ins> N >
void swap(array<T,N<ins>...</ins>>& x, array<T,N<ins>...</ins>>& y) noexcept(noexcept(x.swap(y)));
template <class T> class tuple_size;
template <size_t I, class T> class tuple_element;
template <class T, size_t<ins>...</ins> N>
struct tuple_size<array<T, N<ins>...</ins>> >;
template <size_t I, class T, size_t<ins>...</ins> N>
struct tuple_element<I, array<T, N<ins>...</ins>> >;
template <size_t I, class T, size_t<ins>...</ins> N>
constexpr T& get(array<T, N<ins>...</ins>>&) noexcept;
template <size_t I, class T, size_t<ins>...</ins> N>
constexpr T&& get(array<T, N<ins>...</ins>>&&) noexcept;
template <size_t I, class T, size_t<ins>...</ins> N>
constexpr const T& get(const array<T, N<ins>...</ins>>&) noexcept;
<ins>template <class T, size_t... N, class... Args>
constexpr array<T, N...> make_array(Args&&...);
template <class... Args>
constexpr array<common_type_t<Args...>, sizeof...(Args)>
make_array(Args&&...);
template <class TO, size_t... NO, class TI, size_t... NI>
constexpr array<TO, NO...> remake_array(const array<TI, NI...>&);</ins>
<ins>template <class T, size_t... N>
using nested_array = <i>see below</i>;</ins>
}</pre>
</blockquote>
<p>Modify section 23.3.2.1 [array.overview]:</p>
<blockquote>
<p><strong>-1-</strong> The header <code><array></code> defines a class
template for storing fixed-size sequences of objects. An array supports
random access iterators. An instance of <code>array<T,
N<ins>...</ins>></code> stores
<code><del>N</del></code><ins><code>P</code></ins> elements of type
<code>T</code>, <ins>where <code>P</code> is the product of the entries from
the pack expansion <code>N</code>,</ins> so that <code>size() ==
<del>N</del></code><ins><code>P</code></ins> is an invariant. The elements of
an array are stored contiguously, meaning that if <code>a</code> is an
<code>array<T, N<ins>...</ins>></code> then it obeys the identity
<code>&<ins>((T*)&</ins>a<ins>)</ins>[n] ==
&<ins>((T*)&</ins>a<ins>)</ins>[0] + n</code> for all <code>0 <= n
< <del>N</del></code><ins><code>P</code></ins>.</p>
<p><strong>-2-</strong> An <code>array</code> is an aggregate (8.5.1) that
can be initialized with the syntax<br>
<code>array<T, <del>N</del><ins>N<sub>0</sub>, ...,
N<sub>sizeof...(N)-1</sub></ins>> a = { <em>initializer-list</em>
};</code><br>
where <em>initializer-list</em> is a comma-separated <ins>(and possibly
braced-partitioned)</ins> list of up to
<code><del>N</del></code><ins><code>P</code></ins> elements whose types are
convertible to <code>T</code><ins>, and <code>P</code> is the product of the
entries <code>N<sub>0</sub></code> through
<sub></sub><code>N<sub>sizeof...(N)-1</sub></code> from the pack expansion
<code>N</code></ins>. <ins>[<em>Note:</em> <code>P</code> is <code>1</code>
when <code>N</code> is empty. <em>—end note</em>]</ins></p>
<p><strong>-3-</strong> An <code>array</code> satisfies all of the
requirements of a container and of a reversible container (23.2), except that
a default constructed <code>array</code> object is not empty and that
<code>swap</code> does not have constant complexity. An <code>array</code>
satisfies some of the requirements of a sequence container (23.2.3).
Descriptions are provided here only for operations on <code>array</code> that
are not described in one of these tables and for operations where there is
additional semantic information.</p>
<pre>namespace std {
template <class T, size_t <ins>...</ins>N >
struct array {
<i>// types:</i>
<ins>typedef append_extents_t<T, N...> type;</ins>
typedef T& reference;
typedef const T& const_reference;
typedef <i>implementation-defined</i> iterator;
typedef <i>implementation-defined</i> const_iterator;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef T value_type;
typedef T* pointer;
typedef const T* const_pointer;
typedef reverse_iterator<iterator> reverse_iterator;
typedef reverse_iterator<const_iterator> const_reverse_iterator;
<ins>typedef remove_extent_t<type> dereference; <i>// iff sizeof...(N) > 0</i></ins>
<del>T</del><ins>conditional_t<!sizeof...(N) ||
extent<type>::value, type,
aligned_storage_t<sizeof(T), alignof(T)>></ins> elems<del>[N]</del>; <i>// exposition only</i>
<ins>static constexpr size_type
value_count = sizeof...(N) ? extent<type>::value * sizeof(dereference) / sizeof(value_type) : 1,
extent_count = sizeof...(N),
extents[] = { N... }; <i>// iff sizeof...(N) > 0</i></ins>
<i>// no explicit construct/copy/destroy for aggregate type</i>
void fill(const T& u);
void swap(array&) noexcept(noexcept(swap(declval<T&>(), declval<T&>())));
<ins>template <class F> void apply(F&& f);
template <class F> void apply(F&& f) const;
template <class F> void capply(F&& f) const;</ins>
<i>// iterators:</i>
iterator begin() noexcept;
const_iterator begin() const noexcept;
iterator end() noexcept;
const_iterator end() const noexcept;
reverse_iterator rbegin() noexcept;
const_reverse_iterator rbegin() const noexcept;
reverse_iterator rend() noexcept;
const_reverse_iterator rend() const noexcept;
const_iterator cbegin() const noexcept;
const_iterator cend() const noexcept;
const_reverse_iterator crbegin() const noexcept;
const_reverse_iterator crend() const noexcept;
<i>// capacity:</i>
constexpr size_type size() const noexcept;
constexpr size_type max_size() const noexcept;
constexpr bool empty() const noexcept;
<i>// element access:</i>
<del>reference</del><ins>dereference&</ins> operator[](size_type n); <ins><i>// iff sizeof...(N) > 0</i></ins>
constexpr <del>const_reference</del><ins>const dereference&</ins> operator[](size_type n) const; <ins><i>// iff sizeof...(N) > 0</i></ins>
<del>reference at(size_type n);
constexpr const_reference at(size_type n) const;</del>
<ins>template <class ...SizeType> auto operator()(const SizeType&... n)
-> remove_some_extents_t<type, sizeof...(SizeType)>&;
template <class ...SizeType> constexpr auto operator()(const SizeType&... n) const
-> const remove_some_extents_t<type, sizeof...(SizeType)>&;
template <class ...SizeType> auto at(const SizeType&... n)
-> remove_some_extents_t<type, sizeof...(SizeType)>&;
template <class ...SizeType> constexpr auto at(const SizeType&... n) const
-> const remove_some_extents_t<type, sizeof...(SizeType)>&;</ins>
<ins>reference operator[](initializer_list<size_type> i);
constexpr const_reference operator[](initializer_list<size_type> i) const;
reference operator()(initializer_list<size_type> i);
constexpr const_reference operator()(initializer_list<size_type> i) const;
reference at(initializer_list<size_type> i);
constexpr const_reference at(initializer_list<size_type> i) const;</ins>
reference front();
constexpr const_reference front() const;
reference back();
constexpr const_reference back() const;
<del>T *</del><ins>pointer</ins> data() noexcept;
<del>const T *</del><ins>const_pointer</ins> data() const noexcept;
};
}</pre>
<p><strong>-4-</strong> <ins>Object-specific data shall be implemented as a
single non-static data member.</ins> [<em>Note:</em> The member variable
<code>elems</code> is shown for exposition only, to emphasize that
<code>array</code> is a class aggregate. The name <code>elems</code> is not
part of <code>array</code>’s interface. <em>—end note</em>]</p>
</blockquote>
<p>No modifications for section 23.3.2.2 [array.cons]:</p>
<blockquote>
<p><strong>-1-</strong> The conditions for an aggregate (8.5.1) shall be met.
Class <code>array</code> relies on the implicitly-declared special member
functions (12.1, 12.4, and 12.8) to conform to the container requirements
table in 23.2. In addition to the requirements specified in the container
requirements table, the implicit move constructor and move assignment
operator for <code>array</code> require that <code>T</code> be
<code>MoveConstructible</code> or <code>MoveAssignable</code>,
respectively.</p>
</blockquote>
<p>Add new section 23.3.2.A [array.create], titled "<strong><code>array</code>
creation</strong>":</p>
<blockquote>
<pre>template <class T, size_t... N, class... Args> constexpr array<T, N...> make_array(Args&&... args);</pre>
<p><strong>-1-</strong> <em>Requires:</em> <code>sizeof...(Args) <=
array<T, N...>::value_count</code>. When <code>T</code> is not
<code>DefaultConstructible</code>, <code>sizeof...(Args) == array<T,
N...>::value_count</code>. Each type within <code>Args</code> is
explicitly convertible to <code>T</code>.</p>
<p><strong>-</strong><strong>2-</strong> <em>Returns:</em> an object
list-initialized via <code>{ static_cast<T>( forward<Args>(args)
)... }</code>.</p>
<pre>template <class... Args> constexpr array<common_type_t<Args...>, sizeof...(Args)> make_array(Args&&... args);</pre>
<p><strong>-3-</strong> <em>Requires:</em> <code>sizeof...(Args) >
0</code>. <code>common_type_t<Args...></code> is well-formed.</p>
<p><strong>-4-</strong> <em>Returns:</em>
<code>make_array<common_type_t<Args...>, sizeof...(Args)>(
forward<Args>(args)... )</code>.</p>
<p><strong>-5-</strong> <em>Remarks:</em> If any of the types in the pack
expansion <code>Args</code> is an instantiation of
<code>reference_wrapper</code>, then that function shall not participate in
overload resolution.</p>
<pre>template <class TO, size_t... NO, class TI, size_t... NI> constexpr array<TO, NO...> remake_array(const array<TI, NI...>& x);</pre>
<p><strong>-6-</strong> <em>Requires:</em> <code>TO</code> is
<code>DefaultConstructible</code>. <code>TI</code> is explicitly convertible
to <code>TO</code>.</p>
<p><strong>-7-</strong> <em>Returns:</em> an object <code>y</code> created as
if it was value-initialized then had <code>transform( x.begin(), x.begin() +
min( x.size(), y.size() ), y.begin(), []( const TI& z ){ return
static_cast<TO>(z); } )</code> applied.</p>
</blockquote>
<p><u>Author's Note:</u> For the first <code>make_array</code> overload, if
brace-elision hasn't been added to class types (N3526), then a (new) pair of
braces needs to surround the result when the number of array dimensions is at
least one.</p>
<p>Modify section 23.3.2.3 [array.special]:</p>
<blockquote>
<pre>template <class T, size_t<ins>...</ins> N> void swap(array<T,N<ins>...</ins>>& x, array<T,N<ins>...</ins>>& y) noexcept(noexcept(x.swap(y)));</pre>
<p><strong>-1-</strong> <em>Effects:</em><br>
<code>x.swap(y);</code></p>
<p><strong>-2-</strong> <em>Complexity:</em> linear in
<code><del>N</del></code><ins><code>array<T,N...>::value_count</code></ins>.</p>
</blockquote>
<p>Modify section 23.3.2.4 [array.size]:</p>
<blockquote>
<pre>template <class T, size_t<ins>...</ins> N> constexpr size_type array<T,N<ins>...</ins>>::size() const noexcept;</pre>
<p><strong>-1-</strong> <em>Returns:</em>
<code><del>N</del><ins>value_count</ins></code></p>
</blockquote>
<p>Modify section 23.3.2.5 [array.data]:</p>
<blockquote>
<pre><del>T *</del><ins>pointer</ins> data() noexcept;</pre>
<pre><del>const T *</del><ins>const_pointer</ins> data() const noexcept;</pre>
<p><strong>-1-</strong> <em>Returns:</em> <ins>When <code>extent_count ==
0</code>, <code>addressof(elems)</code>, otherwise the address of the first
(possibly nested) element of <code>T</code> in</ins> <code>elems</code>.</p>
</blockquote>
<p>Modify section 23.3.2.6 [array.fill]:</p>
<blockquote>
<pre>void fill(const T& u);</pre>
<p><strong>-1-</strong> <em>Effects:</em> <code>fill_n(begin(),
<del>N</del><ins>value_count</ins>, u)</code></p>
</blockquote>
<p>No modifications for section 23.3.2.7 [array.swap]:</p>
<blockquote>
<pre>void swap(array& y) noexcept(noexcept(swap(declval<T&>(), declval<T&>())));</pre>
<p><strong>-1-</strong> <em>Effects:</em> <code>swap_ranges(begin(), end(),
y.begin())</code></p>
<p><strong>-2-</strong> <em>Throws:</em> Nothing unless one of the
element-wise swap calls throws an exception.</p>
<p><strong>-3-</strong> <em>Note:</em> Unlike the <code>swap</code> function
for other containers, <code>array::swap</code> takes linear time, may exit
via an exception, and does not cause iterators to become associated with the
other container.</p>
</blockquote>
<p>Add new section 23.3.2.B [array.apply]:</p>
<blockquote>
<pre>template <class F> void apply(F&& f);</pre>
<pre>template <class F> void apply(F&& f) const;</pre>
<pre>template <class F> void capply(F&& f) const;</pre>
<p><strong>-1-</strong> <em>Requires:</em> <code>f</code> is compatible with
<code>function<void(<var>cv</var> T&, size_type, ...,
size_type)></code>, where <var>cv</var> is the cv-qualification of
<code>*this</code> and the number of trailing <code>size_type</code>
arguments is <code>extent_count</code>.</p>
<p><strong>-2-</strong> <em>Effects:</em> <code>f</code> is called once for
each element with the following constraints:</p>
<ul>
<li>Given element <code>e</code> with <code>extent_count</code> ordered
indices i<sub>0</sub>, ..., i<sub>k</sub> required to dereference it from
<code>elems</code>, the application call will be compatible with
<code>forward<F>(f)(e, i<sub>0</sub>, ...,
i<sub>k</sub>)</code>.</li>
<li>The order of element traversal is implementation-defined.</li>
</ul>
<p><strong>-3-</strong> <em>Throws:</em> Nothing unless an application call
throws an exception.</p>
</blockquote>
<p><u>Author's Note:</u> Element traversal order should be the in-memory order
or some other order that minimizes cache misses.</p>
<p>Add new section 23.3.2.C [array.iter], titled "<strong><code>array</code>
iteration</strong>":</p>
<blockquote>
<p><strong>-1-</strong> The beginning value of forward iteration points to
the element at the address returned by <code>data()</code>. The past-the-end
value corresponds to <code>data() + value_count</code>. Propagation of
forward iteration follows the (nested) row-wise storage order (8.3.4).</p>
</blockquote>
<p><u>Author's Note:</u> The above section explicitly defines the intuitive
order elements are linearly visited when the <code>array</code> object is
multidimensional.</p>
<p>Add new section 23.3.2.D [array.access], titled "<strong>Element
access</strong>":</p>
<blockquote>
<pre>dereference& operator[](size_type n);
constexpr const dereference& operator[](size_type n) const;</pre>
<p><strong>-1-</strong> <em>Requires:</em> <code>sizeof...(N) > 0</code>
and <code>n < extents[0]</code>.</p>
<p><strong>-2-</strong> <em>Returns:</em> <code>elems[n]</code>.</p>
<p><strong>-3-</strong> <em>Throws:</em> Nothing.</p>
<pre>template <class ...SizeType> auto operator()(const SizeType&... n)
-> remove_some_extents_t<type, sizeof...(SizeType)>&;
template <class ...SizeType> constexpr auto operator()(const SizeType&... n) const
-> const remove_some_extents_t<type, sizeof...(SizeType)>&;</pre>
<p><strong>-4-</strong> <em>Requires:</em> <code>sizeof...(SizeType) <=
extent_count</code>. Each entry in the pack expansion <code>SizeType</code>
has to have an implicit conversion to <code>size_type</code>. Each entry in
the pack expansion <code>n</code>, in order, needs to be less than the
corresponding value in <code>extents</code>.</p>
<p><strong>-5-</strong> <em>Returns:</em> <code>elems</code> followed by
<code>sizeof...(n)</code> calls of the built-in subscript operator, with each
operator using an entry from the pack expansion <code>n</code>, in order, as
an index.</p>
<p><strong>-6-</strong> <em>Throws:</em> Nothing unless a conversion from an
entry of the pack expansion <code>n</code> to a <code>size_type</code> value
throws an exception.</p>
<p><strong>-7-</strong> <em>Remarks:</em> If any of the types in the pack
expansion <code>SizeType</code> cannot be implicitly converted to
<code>size_type</code>, or if <code>sizeof...(SizeType) >
extent_count</code>, then that function shall not participate in overload
resolution.</p>
<pre>reference operator[](initializer_list<size_type> i);
constexpr const_reference operator[](initializer_list<size_type> i) const;
reference operator()(initializer_list<size_type> i);
constexpr const_reference operator()(initializer_list<size_type> i) const;</pre>
<p><strong>-8-</strong> <em>Requires:</em> <code>i.size() ==
extent_count</code>. For <code>0 <= d < extent_count</code>,
<code>*(i.begin() + d) < extents[d]</code>.</p>
<p><strong>-9-</strong> <em>Returns:</em> <code>operator()(i<sub>0</sub>,
..., i<sub>extent_count-1</sub>)</code>, where the <code>i<sub>k</sub></code>
are the elements of <code>i</code>, in order.</p>
<p><strong>-10-</strong> <em>Throws:</em> Nothing.</p>
<pre>template <class ...SizeType> auto at(const SizeType&... n)
-> remove_some_extents_t<type, sizeof...(SizeType)>&;
template <class ...SizeType> constexpr auto at(const SizeType&... n) const
-> const remove_some_extents_t<type, sizeof...(SizeType)>&;
reference at(initializer_list<size_type> i);
constexpr const_reference at(initializer_list<size_type> i) const;</pre>
<p><strong>-11-</strong> <em>Requires:</em> the same requirements as the
corresponding version of <code>operator()()</code>.</p>
<p><strong>-12-</strong> <em>Returns:</em> <code>operator()( <var>X</var>
)</code>, where <var>X</var> is the argument list of <code>at()</code>.</p>
<p><strong>-13-</strong> <em>Throws:</em> Nothing unless: a conversion from
an entry of the pack expansion <code>n</code> to a <code>size_type</code>
value throws an exception; a particular index is equal or greater than its
corresponding entry in <code>extents</code>, in which
<code>out_of_range</code> is thrown; or <code>i.size() !=
extent_count</code>, in which <code>length_error</code> is thrown.</p>
<p><strong>-14-</strong> <em>Remarks:</em> If any of the types in the pack
expansion <code>SizeType</code> cannot be implicitly converted to
<code>size_type</code>, or if <code>sizeof...(SizeType) >
extent_count</code>, then that function shall not participate in overload
resolution.</p>
</blockquote>
<p><u>Author's Note:</u> The contained (array) object, <code>elems</code>, can
be directly referenced by calling <code>operator()()</code>, <code>at()</code>,
or the <code>initializer_list</code> overload of <code>operator[]()</code> with
no indexes.</p>
<p>Add new section 23.3.2.E [array.extents], titled "<strong>Zero extent
arrays</strong>":</p>
<blockquote>
<p><strong>-1-</strong> <code>array</code> shall provide support for the
special case of <code>N</code> being an empty pack expansion.</p>
<p><strong>-2-</strong> In the case that <code>sizeof...(N) == 0</code>, the
<code>dereference</code> and <code>extents</code> members are not provided.
Neither are the overloads of <code>operator[]()</code> that take one
<code>size_type</code> parameter provided. It is implementation-defined if
the overloads of <code>operator()()</code> and <code>at()</code> that do not
take an <code>initializer_list</code> are replaced with equivalent
non-template members that take zero parameters.</p>
</blockquote>
<p>Modify section 23.3.2.8 [array.zero]</p>
<blockquote>
<p><strong>-1-</strong> <code>array</code> shall provide support for the
special case <code><del>N</del><ins>value_count</ins> == 0</code>.
<ins>[<em>Note:</em> Such <code>array</code> instantiations are made by using
at least one extent and setting the first extent to zero. They have the same
size and alignment specifications as instantiations with <code>value_count ==
1</code>. They are always <code>DefaultConstructible</code>, even when
<code>T</code> is not. <em>—end note</em>]</ins></p>
<p><strong>-2-</strong> In the case that
<code><del>N</del><ins>value_count</ins> == 0</code>, <ins>the values
of</ins> <code>begin() <del>==</del></code><ins>and</ins> <code>end()</code>
<del><code>==</code> unique value</del><ins>are unspecified but they shall be
identical</ins>. The return value of <code>data()</code> is unspecified.</p>
<p><strong>-3-</strong> The effect of calling <code>front()</code> or
<code>back()</code> for a zero-sized array is undefined. </p>
<p><strong>-4-</strong> Member function <code>swap()</code> shall have a
<em>noexcept-specification</em> which is equivalent to
<code>noexcept(true)</code>.</p>
</blockquote>
<p>Modify section 23.3.2.9 [array.tuple]</p>
<blockquote>
<pre>tuple_size<array<T, N<ins>...</ins>> >::value</pre>
<p><strong>-1-</strong> <em>Return type:</em> integral constant
expression.</p>
<p><strong>-2-</strong> <em>Value:</em> <code><del>N</del><ins>array<T,
N...>::value_count</ins></code></p>
<pre>tuple_element<I, array<T, N<ins>...</ins>> >::type</pre>
<p><strong>-3-</strong> <em>Requires:</em> <code>I <
<del>N</del><ins>array<T, N...>::value_count</ins></code>. The program
is ill-formed if <code>I</code> is out of bounds.</p>
<p><strong>-4-</strong> <em>Value:</em> The type <code>T</code>.</p>
<pre>template <size_t I, class T, size_t <ins>...</ins>N>
constexpr T& get(array<T, N<ins>...</ins>>& a) noexcept;</pre>
<p><strong>-5-</strong> <em>Requires:</em> <code>I <
<del>N</del><ins>array<T, N...>::value_count</ins></code>. The program
is ill-formed if <code>I</code> is out of bounds.</p>
<p><strong>-6-</strong> <em>Returns:</em> A reference to the <code>I</code>th
element of <code>a</code>, where indexing is zero-based <ins>and uses the
forward-iteration order (23.3.2.C)</ins>.</p>
<pre>template <size_t I, class T, size_t <ins>...</ins>N>
constexpr T&& get(array<T, N<ins>...</ins>>&& a) noexcept;</pre>
<p><strong>-7-</strong> <em>Effects:</em> Equivalent to <code>return
std::move(get<I>(a));</code></p>
<pre>template <size_t I, class T, size_t <ins>...</ins>N>
constexpr const T& get(const array<T, N<ins>...</ins>>& a) noexcept;</pre>
<p><strong>-8-</strong> <em>Requires:</em> <code>I <
<del>N</del><ins>array<T, N...>::value_count</ins></code>. The program
is ill-formed if <code>I</code> is out of bounds.</p>
<p><strong>-9-</strong> <em>Returns:</em> A const reference to the
<code>I</code>th element of <code>a</code>, where indexing is zero-based
<ins>and uses the forward-iteration order (23.3.2.C)</ins>.</p>
</blockquote>
<p><u>Author's Note:</u> When <code>sizeof...(N) == 1</code>, <code>get</code>
acts with the expected semantics. When <code>N</code> is empty, <code>0</code>
is the only valid value for <code>I</code> and <code>get</code> returns the
sole element. Otherwise, the multiple indexes needed to reference an element
are flattened to the index in "row-major" linear traversal order.</p>
<p>Add new section 23.3.2.F [array.nest], titled "<strong>Alias template
<code>nested_array</code></strong>":</p>
<blockquote>
<pre>template <class T, size_t... N>
using nested_array = <i>implementation-defined</i>;</pre>
<p><strong>-1-</strong> An instantiated template alias of
<code>nested_array</code> implements multidimensionality by nesting class
types instead of array types. The <var>type-id</var> of the alias declaration
must be of a form such that:</p>
<ul>
<li><code>nested_array<T></code> shall alias
<code>array<T></code>, for a given type <code>T</code>.</li>
<li><code>nested_array<T, N></code> shall alias <code>array<T,
N></code>, for an additionally given value <code>N</code>.</li>
<li><code>nested_array<T, N, M, <var>L</var>></code> shall alias
<code>array<nested_array<T, M, <var>L</var>>, N></code>, for
additionally given value <code>M</code> and (possibly empty) list of
values <code><var>L</var></code>.</li>
</ul>
<p>[<em>Note:</em> The <code>value_type</code> member type-alias of a
<code>nested_array</code> instantiation will name the same type as the
instantiation's first template parameter only when the number of following
template parameters is less than two. <em>—end note</em>]</p>
</blockquote>
<h2 id="Ch07">VII. Acknowledgments</h2>
<h2 id="Ch08">VIII. History</h2>
<ul>
<li>From N3794
<ul>
<li>Add "History" chapter.</li>
<li>Add N3794 and N3526 to References.</li>
<li>Add alias template for nested <code>std::array</code>
instantiations.</li>
<li>Add that a single non-static data member is mandated for
<code>std::array</code>.</li>
<li>Change the array creation functions, partly as a compare/contrast to
N3824:
<ul>
<li>Rename <code>make_auto_array</code> and
<code>reshape_array</code> to <code>make_array</code> (second
overload) and <code>remake_array</code>, respectively.</li>
<li>Redo the descriptions of their behavior.</li>
<li>Move the section describing their behavior, 23.3.2.A
[array.create], to before 23.3.2.3 [array.special].</li>
</ul>
</li>
</ul>
</li>
</ul>
<h2 id="Ch09">IX. References</h2>
<ul>
<li>A Proposal to Add a Fixed Size Array Wrapper to the Standard Library,
WG21 Document N15458=03-0131, 2003. <a
href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1548.htm">www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1548.htm</a>
</li>
<li>Variadic Templates (Revision 3), WG21 Document N2080=06-0150, 2006. <a
href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2080.pdf">www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2080.pdf</a>
</li>
<li>Proposal to Add Multi-Dimensional Support to std::array, WG21 Document
N3794, 2013. <a
href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3794.html">www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3794.html</a>
</li>
<li>Uniform initialization for arrays and class aggregate types, WG21
Document N3526, 2013. <a
href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3526.html">www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3526.html</a>
</li>
<li>make_array, WG21 Document N3824, 2013. <a
href="http://isocpp.org/files/papers/N3824.html">isocpp.org/files/papers/N3824.html</a>
(interim)</li>
</ul>
</body>
</html>