@@ -121,15 +121,24 @@ int[]* e; // pointer to dynamic array of ints
121
121
---------
122
122
)
123
123
124
- $(H2 $(LNAME2 usage , Array Usage ))
124
+ $(H2 $(LNAME2 literals , Array Literals ))
125
125
126
- $(P There are two broad kinds of operations to do on an array -
127
- those affecting the handle to the array,
128
- and those affecting the contents of the array.
129
- )
126
+ ---
127
+ auto a1 = [1,2,3]; // type is int[], with elements 1, 2 and 3
128
+ auto a2 = [1u,2,3]; // type is uint[], with elements 1u, 2u, and 3u
129
+ int[2] = [1, 2];
130
+ ---
131
+ $(P `[]` is an empty array literal.)
132
+
133
+ $(P See $(DDSUBLINK expression, array_literals, Array Literals).)
134
+
135
+ $(LEGACY_LNAME2 usage)
136
+ $(H2 $(LNAME2 assignment, Array Assignment))
130
137
131
- $(P The handle to an array is specified by naming the array, as
132
- in p, s or a:
138
+ $(P There are two broad kinds of operations to do on dynamic arrays and
139
+ pointer arrays - those affecting the handle to the array,
140
+ and those affecting the contents of the array. Assignment only affects
141
+ the handle for these types.
133
142
)
134
143
135
144
$(SPEC_RUNNABLE_EXAMPLE_RUN
@@ -144,31 +153,23 @@ p = a.ptr; // p points to the first element of the array a.
144
153
// error, since the length of the array pointed to by p is unknown
145
154
//s = p;
146
155
//s = a; // error, as a's length is not known at compile-time
156
+ s = [1,2,3];
147
157
148
158
//a = p; // error, length unknown
149
- a = s; // a is initialized to point to the s array
159
+ a = s; // a points to the elements of s
150
160
assert(a.ptr == s.ptr);
161
+ assert(a == [1,2,3]);
151
162
152
163
int[] b;
153
164
a = b; // a points to the same array as b does
154
165
assert(a.ptr == b.ptr);
166
+ assert(a == []);
155
167
---------
156
168
)
157
169
$(P Each of the three error lines above can be made to copy elements
158
170
using $(RELATIVE_LINK2 slicing, slicing), so that the number of elements
159
171
to copy is then known.)
160
172
161
- $(H2 $(LNAME2 literals, Array Literals))
162
-
163
- ---
164
- auto a1 = [1,2,3]; // type is int[], with elements 1, 2 and 3
165
- a1 = []; // a1 is now empty
166
- auto a2 = [1u,2,3]; // type is uint[], with elements 1u, 2u, and 3u
167
- int[2] = [1, 2];
168
- ---
169
-
170
- $(P See $(DDSUBLINK expression, array_literals, Array Literals).)
171
-
172
173
$(H2 $(LNAME2 indexing, Indexing))
173
174
174
175
$(P Indexing allows access to an element of an array:)
0 commit comments