Ada Conformity Assessment Authority      Home Conformity Assessment   Test Suite ARGAda Standard
Overview of Ada 2022
Jeff Cousins
Contents   Index   Search   Previous   Next 

4.7 Iterators in array aggregates

In addition to container aggregates, Container aggregates; generalized array aggregates (AI12-0212) adds iterator associations to array aggregates (see RM 4.3.3), in order to keep the capabilities of container aggregates and array aggregates roughly the same. This feature allows the use of iterators to construct an array object directly without needing to write a loop statement.
If an array aggregate contains an iterator association then no other associations are allowed other than other iterator associations (there may be more than one of these). Since the number of items is only known at runtime, the lower bound of the array value is determined as for a positional array aggregate, and the upper bound is determined by the number of actual values in the array value.
Array aggregate iterator associations can have filters (see 4.6) which allow the selection of specific elements to create an array. One could create an array of all of elements of a container C with all of the even elements first:
    type Arr is array (Positive range <>) of Natural;
    A : constant Arr :=
           [for E of C when E mod 2 = 0 => E,
            for E of C when E mod 2 = 1 => E];
Note that an iterator over a discrete range is provided by the ability to specify an index parameter (as introduced by Index parameters in array aggregates (AI12-0061) – see 7.4); unlike other iterator associations, it retains the usual compile-time aggregate checks and capabilities.

Contents   Index   Search   Previous   Next 
© 2021, 2022 Jeff Cousins