-
Notifications
You must be signed in to change notification settings - Fork 0
/
array-traits-proposal.html
169 lines (144 loc) · 6.75 KB
/
array-traits-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
<!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 Array-Oriented Type-Traits</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 Evolution Group
Date: 2013-11-12
Reply-to: Daryle Walker <darylew at gmail dot com></pre>
<h1>Proposal to Add Array-Oriented Type-Traits</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>There are several class templates in the Standard that relate to analyzing
array types. There are (at least) several obvious extensions that can be added.
This proposal aims to add such classes.</p>
<h2 id="Ch03">III. Motivation and Scope</h2>
<p>The class templates proposed were originally in N3794. The main aim of that
proposal needs the classes listed in this new proposal, but not the other way
around. The templates were moved to a new proposal to compartmentalize work and
ease considering what to accept.</p>
<p>Besides that, these templates "complete" to work already done on
array-oriented type-traits. There are two current transformation-style
array-oriented type-traits: to strip the outermost extent and to strip all
extents. This proposal adds: stripping an intermediate amount of extents and
adding extents, where the user controls how many extents to strip or which
extents to add.</p>
<h2 id="Ch04">IV. Impact on the Standard</h2>
<p>The proposal adds two class templates (and corresponding type-alias
templates). The implementation should work with current language features.</p>
<h2 id="Ch05">V. Design Decisions</h2>
<h2 id="Ch06">VI. Technical Specifications</h2>
<p>The changes are based off C++ Working Draft Standard N3797.</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>
<h2 id="Ch07">VII. Acknowledgments</h2>
<h2 id="Ch08">VIII. History</h2>
<ul>
<li>Split from N3794 </li>
</ul>
<h2 id="Ch09">IX. References</h2>
<ul>
<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>
</ul>
</body>
</html>