Next: , Previous: , Up: Implementation Defined Aspects   [Contents][Index]


3.23 Aspect Iterable

This aspect provides a light-weight mechanism for loops and quantified expressions over container types, without the overhead imposed by the tampering checks of standard Ada 2012 iterators. The value of the aspect is an aggregate with six named components, of which the last three are optional: First, Next, Has_Element, Element, Last, and Previous. When only the first three components are specified, only the for .. in form of iteration over cursors is available. When Element is specified, both this form and the for .. of form of iteration over elements are available. If the last two components are specified, reverse iterations over the container can be specified (analogous to what can be done over predefined containers that support the Reverse_Iterator interface). The following is a typical example of use:

type List is private with
    Iterable => (First        => First_Cursor,
                 Next         => Advance,
                 Has_Element  => Cursor_Has_Element,
                [Element      => Get_Element]);
function First_Cursor (Cont : Container) return Cursor;
function Advance (Cont : Container; Position : Cursor) return Cursor;
function Cursor_Has_Element (Cont : Container; Position : Cursor) return Boolean;
function Get_Element (Cont : Container; Position : Cursor) return Element_Type;

This aspect is used in the GNAT-defined formal container packages.


Next: , Previous: , Up: Implementation Defined Aspects   [Contents][Index]