Support Constant_Reference in Iterable aspect.
Ada's Iterable aspect now supports `Constant_Reference` functions for container iteration.
This commit enhances Ada’s Iterable aspect, allowing it to utilize a Constant_Reference function instead of the Element primitive for iterating over container elements. This provides more flexibility in how users can define iteration for their custom container types, particularly when an anonymous access-to-constant type is returned. The change updates expansion and semantic analysis routines to recognize and correctly process Constant_Reference, improving the expressiveness of Ada’s iteration model.
In Details
The Iterable aspect in Ada allows for defining custom iteration behavior for types. Previously, this primarily relied on the Element primitive. This commit introduces support for Constant_Reference as an alternative to Element in the Iterable aspect. Specifically, Expand_Formal_Container_Element_Loop in exp_ch5.adb and Resolve_Iterable_Operation and Validate_Iterable_Aspect in sem_ch13.adb are updated to check for and utilize Constant_Reference. This is particularly useful for containers that want to expose their elements as anonymous access-to-constant types for iterati…
For Context
In Ada, you can make your custom data structures (like lists or trees) "iterable," meaning you can easily loop through their contents using a for..in loop. Traditionally, you would define an Element function to tell the compiler how to get each item during iteration. This change introduces more flexibility: now, you can also provide a Constant_Reference function. This function returns a special kind of pointer (an 'access-to-constant type') that lets you look at the elements of your container without being able to change them. This is useful for containers where direct access to a modifiable element isn't desired or possible, and it gives developers more options for designing how their data structures can be traversed.