Next: Aspect Linker_Section, Previous: Aspect Invariant'Class, Up: Implementation Defined Aspects [Contents][Index]
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]);
First
must denote a primitive operation of the
container type that returns a Cursor
, which must a be a type declared in
the container package or visible from it. For example:
function First_Cursor (Cont : Container) return Cursor;
Next
is a primitive operation of the container type that takes
both a container and a cursor and yields a cursor. For example:
function Advance (Cont : Container; Position : Cursor) return Cursor;
Has_Element
is a primitive operation of the container type
that takes both a container and a cursor and yields a boolean. For example:
function Cursor_Has_Element (Cont : Container; Position : Cursor) return Boolean;
Element
is a primitive operation of the container type that
takes both a container and a cursor and yields an Element_Type
, which must
be a type declared in the container package or visible from it. For example:
function Get_Element (Cont : Container; Position : Cursor) return Element_Type;
This aspect is used in the GNAT-defined formal container packages.
Next: Aspect Linker_Section, Previous: Aspect Invariant'Class, Up: Implementation Defined Aspects [Contents][Index]