Overview of Ada 2022
Jeff Cousins
Contents   Index   Search   Previous   Next 

7.4 Index parameters in array aggregates

Index parameters in array aggregates (AI12-0061) adds an optional index in array aggregates (see RM 4.3.3). Consider:
subtype Index is Positive range 1 .. 10;
type Array_Type is array (Index) of Positive;
Squares_Array : Array_Type := (for I in Index => I * I);
This provides a means of creating an aggregate when the element type is limited, provides a better means of initialising an array with a type invariant, and should be useful for everyday programming.
While these associations look like an iterator association in an array aggregate (see 4.7), they actually are closely related to normal named associations, with the same usage rules. Thus, multiple associations are allowed (so long as all of the choices are static), with or without index parameters in those other associations. Similarly, the usual completeness checks apply to an aggregate with these associations. Since these associations are not iterators, they do not allow iterator filters (see 4.6), as filters would make the completeness checks impossible.

Contents   Index   Search   Previous   Next 
© 2021, 2022 Jeff Cousins