5.5.1 User-Defined Iterator Types
Static Semantics
1/3
{
AI05-0139-2}
The following language-defined generic library
package exists:
2/3
generic
type Cursor;
with function Has_Element (Position : Cursor) return Boolean;
package Ada.Iterator_Interfaces is
pragma Pure (Iterator_Interfaces);
3/3
type Forward_Iterator is limited interface;
function First (Object : Forward_Iterator) return Cursor is abstract;
function Next (Object : Forward_Iterator; Position : Cursor)
return Cursor is abstract;
4/3
type Reversible_Iterator is limited interface and Forward_Iterator;
function Last (Object : Reversible_Iterator) return Cursor is abstract;
function Previous (Object : Reversible_Iterator; Position : Cursor)
return Cursor is abstract;
5/3
end Ada.Iterator_Interfaces;
6/3
{
AI05-0139-2}
An iterator type is a type descended from
the Forward_Iterator interface from some instance of Ada.Iterator_Interfaces.
A reversible iterator type is a type descended from the Reversible_Iterator
interface from some instance of Ada.Iterator_Interfaces.
An iterator object is an object of an iterator type.
A reversible iterator object is an object of a reversible iterator
type. The formal subtype Cursor from the associated
instance of Ada.Iterator_Interfaces is the iteration cursor subtype
for the iterator type.
7/3
{
AI05-0139-2}
The following type-related operational aspects
may be specified for an indexable type T (see 4.1.6):
8/3
Default_Iterator
This aspect is specified by a name
that denotes exactly one function declared immediately within the same
declaration list in which T is declared, whose first parameter
is of type T or T'Class or an access parameter whose designated
type is type T or T'Class, whose other parameters, if any,
have default expressions, and whose result type is an iterator type.
This function is the default iterator function for T.
Its result subtype is the default iterator subtype for T.
The iteration cursor subtype for the default iterator subtype is the
default cursor subtype for T.
8.a/3
Aspect Description
for Default_Iterator: Default
iterator to be used in for loops.
9/3
Iterator_Element
This aspect is specified by a name
that denotes a subtype. This is the default element subtype for
T.
9.a/3
Aspect Description
for Iterator_Element: Element
type to be used for user-defined iterators.
10/3
These aspects are inherited
by descendants of type T (including T'Class).
11/3
{
AI05-0139-2}
An iterable type is an indexable type with
specified Default_Iterator and Iterator_Element aspects.
A reversible iterable type is an iterable type with the default
iterator type being a reversible iterator type. An
iterable object is an object of an iterable type.
A reversible iterable object is an object of a reversible iterable
type.
Legality Rules
12/3
{
AI05-0139-2}
The Constant_Indexing aspect (if any) of an iterable
type T shall denote exactly one function with the following properties:
13/3
the result type of the function
is covered by the default element type of T or is a reference
type (see 4.1.5) with an access discriminant
designating a type covered by the default element type of T;
14/3
the type of the second parameter
of the function covers the default cursor type for T;
15/3
if there are more than two
parameters, the additional parameters all have default expressions.
16/3
This function (if any) is
the default constant indexing function for T.
16.a/3
Ramification: This
does not mean that Constant_Indexing has to designate only one subprogram,
only that there is only one routine that meets all of these properties.
There can be other routines designated by Constant_Indexing, but they
cannot have the profile described above. For instance, map containers
have a version of Constant_Indexing that takes a key instead of a cursor;
this is allowed.
17/3
{
AI05-0139-2}
The Variable_Indexing aspect (if any) of an iterable
type T shall denote exactly one function with the following properties:
18/3
the result type of the function
is a reference type (see 4.1.5) with an access
discriminant designating a type covered by the default element type of
T;
19/3
the type of the second parameter
of the function covers the default cursor type for T;
20/3
if there are more than two
parameters, the additional parameters all have default expressions.
21/3
This function (if any) is
the default variable indexing function for T.
Extensions to Ada 2005
21.a/3
{
AI05-0139-2}
User-defined iterator types
are new in Ada 2012.
Ada 2005 and 2012 Editions sponsored in part by Ada-Europe