@@ -1266,43 +1266,51 @@ $(GNAME Slice):
1266
1266
)
1267
1267
1268
1268
$(P $(I PostfixExpression) is evaluated.
1269
- if $(I PostfixExpression) is an expression of type
1270
- static array or dynamic array, the special variable $(DOLLAR)
1271
- is declared and set to be the length of the array.
1269
+ If $(I PostfixExpression) is an expression of static array or
1270
+ dynamic array type, the result of the slice is a dynamic array
1271
+ of the element type of the $(I PostfixExpression).
1272
+ )
1273
+
1274
+ $(P If $(I PostfixExpression) is a $(DDSUBLINK spec/template, variadic-templates, $(I ValueSeq)), then
1275
+ the result of the slice is a new $(I ValueSeq) formed
1276
+ from the upper and lower bounds, which must statically evaluate
1277
+ to integral constants.
1278
+ It is an error if those bounds are out of range.
1279
+ )
1280
+
1281
+ $(P The special variable `$`
1282
+ is declared and set to be the number of elements in the $(I PostfixExpression).
1272
1283
A new declaration scope is created for the evaluation of the
1273
1284
$(GLINK AssignExpression)..$(GLINK AssignExpression)
1274
- and $(DOLLAR) appears in that scope only.
1285
+ and `$` appears in that scope only.
1275
1286
)
1276
1287
1277
1288
$(P The first $(I AssignExpression) is taken to be the inclusive
1278
1289
lower bound
1279
1290
of the slice, and the second $(I AssignExpression) is the
1280
1291
exclusive upper bound.
1281
- The result of the expression is a slice of the $(I PostfixExpression)
1282
- array.
1283
- )
1284
-
1285
- $(P If the $(D [ ]) form is used, the slice is of the entire
1286
- array.
1292
+ The result of the expression is a slice of the elements in $(I PostfixExpression).
1287
1293
)
1288
1294
1289
- $(P The type of the slice is a dynamic array of the element
1290
- type of the $(I PostfixExpression).
1295
+ $(P If the $(D [ ]) form is used, the slice is of all the elements in $(I PostfixExpression).
1291
1296
)
1292
1297
1293
1298
$(P A $(I SliceExpression) is not a modifiable lvalue.)
1294
1299
1300
+ $(H3 $(LNAME2 slice_to_static_array, Slice Conversion to Static Array))
1301
+
1295
1302
$(P If the slice bounds can be known at compile time, the slice expression
1296
- is implicitly convertible to an lvalue of static array. For example:)
1303
+ may be implicitly convertible to an lvalue of static array. For example:)
1297
1304
1298
1305
-------------
1299
1306
arr[a .. b] // typed T[]
1300
1307
-------------
1301
1308
1302
- If both $(CODE a) and $(CODE b) are integers (may be constant-folded),
1309
+ If both $(CODE a) and $(CODE b) are integers (which may be constant-folded),
1303
1310
the slice expression can be converted to a static array type
1304
1311
$(D T[b - a]).
1305
1312
1313
+ $(SPEC_RUNNABLE_EXAMPLE_RUN
1306
1314
-------------
1307
1315
void foo(int[2] a)
1308
1316
{
@@ -1327,9 +1335,10 @@ $(GNAME Slice):
1327
1335
bar(arr[1 .. 3]);
1328
1336
assert(arr == [1, 4, 5]);
1329
1337
1330
- //baz(arr[1 .. 3]); // cannot match length
1338
+ //baz(arr[1 .. 3]); // cannot match length
1331
1339
}
1332
1340
-------------
1341
+ )
1333
1342
1334
1343
$(P The following forms of slice expression can be convertible to a static array
1335
1344
type:)
@@ -1350,14 +1359,6 @@ type:)
1350
1359
$(TROW $(D arr[e-a .. e-b]), $(D a - b) $(I if) $(D a >= b))
1351
1360
)
1352
1361
1353
- $(P If $(I PostfixExpression) is a $(I ValueSeq), then
1354
- the result of the slice is a new $(I ValueSeq) formed
1355
- from the upper and lower bounds, which must statically evaluate
1356
- to integral constants.
1357
- It is an error if those
1358
- bounds are out of range.
1359
- )
1360
-
1361
1362
$(H2 $(LNAME2 primary_expressions, Primary Expressions))
1362
1363
1363
1364
$(GRAMMAR
0 commit comments