@@ -1702,7 +1702,7 @@ $(GNAME ArrayMemberInitialization):
1702
1702
$(GLINK AssignExpression) $(D :) $(GLINK2 declaration, NonVoidInitializer)
1703
1703
)
1704
1704
1705
- $(P Array literals are a comma-separated list of expressions
1705
+ $(P An array literal is a comma-separated list of expressions
1706
1706
between square brackets $(D [) and $(D ]).
1707
1707
The expressions form the elements of a dynamic array.
1708
1708
The length of the array is the number of elements.
@@ -1764,6 +1764,27 @@ $(GNAME ArrayMemberInitialization):
1764
1764
}
1765
1765
---
1766
1766
1767
+ $(P To initialize an element at a particular index, use the
1768
+ *AssignExpression* `:` *NonVoidInitializer* syntax.
1769
+ The *AssignExpression* must be known at compile-time.
1770
+ Any missing elements will be initialized to the default value
1771
+ of the element type.
1772
+ Note that if the array type is not specified, the literal will
1773
+ be parsed as an
1774
+ $(RELATIVE_LINK2 associative_array_literals, associative array).)
1775
+
1776
+ $(SPEC_RUNNABLE_EXAMPLE_COMPILE
1777
+ ---
1778
+ int n = 4;
1779
+ auto aa = [0:1, 3:n]; // associative array `int[int]`
1780
+
1781
+ int[] a = [1, 3:n, 5];
1782
+ assert(a == [1, 0, 0, n, 5]);
1783
+
1784
+ //int[] e = [n:2]; // error, n not known at compile-time
1785
+ ---
1786
+ )
1787
+
1767
1788
$(H3 $(LNAME2 cast_array_literal, Casting))
1768
1789
1769
1790
$(P When array literals are cast to another array type, each
0 commit comments