Skip to content

Commit 3a6e1a9

Browse files
committed
Rename *Array Usage* -> *Array Assignment* and tweak wording
Also move *Array Literals* above it.
1 parent 9b1beb9 commit 3a6e1a9

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

spec/arrays.dd

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,24 @@ int[]* e; // pointer to dynamic array of ints
121121
---------
122122
)
123123

124-
$(H2 $(LNAME2 usage, Array Usage))
124+
$(H2 $(LNAME2 literals, Array Literals))
125125

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))
130137

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.
133142
)
134143

135144
$(SPEC_RUNNABLE_EXAMPLE_RUN
@@ -144,31 +153,23 @@ p = a.ptr; // p points to the first element of the array a.
144153
// error, since the length of the array pointed to by p is unknown
145154
//s = p;
146155
//s = a; // error, as a's length is not known at compile-time
156+
s = [1,2,3];
147157

148158
//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
150160
assert(a.ptr == s.ptr);
161+
assert(a == [1,2,3]);
151162

152163
int[] b;
153164
a = b; // a points to the same array as b does
154165
assert(a.ptr == b.ptr);
166+
assert(a == []);
155167
---------
156168
)
157169
$(P Each of the three error lines above can be made to copy elements
158170
using $(RELATIVE_LINK2 slicing, slicing), so that the number of elements
159171
to copy is then known.)
160172

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-
172173
$(H2 $(LNAME2 indexing, Indexing))
173174

174175
$(P Indexing allows access to an element of an array:)

0 commit comments

Comments
 (0)