@@ -1235,22 +1235,29 @@ $(GNAME IndexExpression):
1235
1235
$(GLINK PostfixExpression) $(D [) $(GLINK ArgumentList) $(D ])
1236
1236
)
1237
1237
1238
- $(P $(I PostfixExpression) is evaluated. If $(I PostfixExpression) is an
1239
- expression of type static array or dynamic array, the symbol $(DOLLAR) is set to
1240
- be the number of elements in the array. If $(I PostfixExpression) is a $(I
1241
- ValueSeq), the symbol $(DOLLAR) is set to be the number of elements
1242
- in the sequence. A new declaration scope is created for the evaluation of the
1243
- $(GLINK ArgumentList) and $(DOLLAR) appears in that scope only.)
1244
-
1245
- $(P If $(I PostfixExpression) is a $(I ValueSeq),
1246
- then the $(GLINK ArgumentList) must consist of only one argument,
1238
+ $(P $(I PostfixExpression) is evaluated.
1239
+ If $(I PostfixExpression) is an expression of static or
1240
+ dynamic array type, the result of the indexing is an lvalue
1241
+ of the *i*th element in the array.
1242
+ If $(I PostfixExpression) is a pointer `p`, the result is `*(p + i)`.
1243
+ In each case, `i` is an integer evaluated from $(I ArgumentList).
1244
+ )
1245
+
1246
+ $(P If $(I PostfixExpression) is a $(DDSUBLINK spec/template, variadic-templates, $(I ValueSeq))
1247
+ then the $(I ArgumentList) must consist of only one argument,
1247
1248
and that must be statically evaluatable to an integral constant.
1248
1249
That integral constant $(I n) then selects the $(I n)th
1249
1250
expression in the $(I ValueSeq), which is the result
1250
1251
of the $(I IndexExpression).
1251
1252
It is an error if $(I n) is out of bounds of the $(I ValueSeq).
1252
1253
)
1253
1254
1255
+ $(P The special variable `$` is declared and set to be the number
1256
+ of elements in the $(I PostfixExpression) (when available).
1257
+ A new declaration scope is created for the evaluation of the
1258
+ $(I ArgumentList) and `$` appears in that scope only.
1259
+ )
1260
+
1254
1261
$(H2 $(LNAME2 slice_expressions, Slice Expressions))
1255
1262
1256
1263
$(GRAMMAR
@@ -1266,9 +1273,17 @@ $(GNAME Slice):
1266
1273
)
1267
1274
1268
1275
$(P $(I PostfixExpression) is evaluated.
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).
1276
+ If $(I PostfixExpression) is a static or dynamic
1277
+ array `a`, the result of the slice is a dynamic array
1278
+ referencing elements `a[i]` to `a[j-1]` inclusive, where `i`
1279
+ and `j` are integers evaluated from the first and second $(I
1280
+ AssignExpression) respectively.
1281
+ )
1282
+
1283
+ $(P If $(I PostfixExpression) is a pointer `p`, the result
1284
+ will be a dynamic array referencing elements from `p[i]` to `p[j-1]`
1285
+ inclusive, where `i` and `j` are integers evaluated from the
1286
+ first and second $(I AssignExpression) respectively.
1272
1287
)
1273
1288
1274
1289
$(P If $(I PostfixExpression) is a $(DDSUBLINK spec/template, variadic-templates, $(I ValueSeq)), then
@@ -1278,20 +1293,20 @@ $(GNAME Slice):
1278
1293
It is an error if those bounds are out of range.
1279
1294
)
1280
1295
1281
- $(P The special variable `$`
1282
- is declared and set to be the number of elements in the $(I PostfixExpression).
1283
- A new declaration scope is created for the evaluation of the
1284
- $(GLINK AssignExpression)..$(GLINK AssignExpression)
1285
- and `$` appears in that scope only.
1286
- )
1287
-
1288
1296
$(P The first $(I AssignExpression) is taken to be the inclusive
1289
1297
lower bound
1290
1298
of the slice, and the second $(I AssignExpression) is the
1291
1299
exclusive upper bound.
1292
1300
The result of the expression is a slice of the elements in $(I PostfixExpression).
1293
1301
)
1294
1302
1303
+ $(P The special variable `$` is declared and set to be the number
1304
+ of elements in the $(I PostfixExpression) (when available).
1305
+ A new declaration scope is created for the evaluation of the
1306
+ $(I AssignExpression)`..`$(I AssignExpression) and `$` appears in
1307
+ that scope only.
1308
+ )
1309
+
1295
1310
$(P If the $(D [ ]) form is used, the slice is of all the elements in $(I PostfixExpression).
1296
1311
)
1297
1312
0 commit comments