5.5.1 User-Defined Iterator Types
Static Semantics
The following language-defined
generic library package exists:
generic
type Cursor;
with function Has_Element (Position : Cursor)
return Boolean;
package Ada.Iterator_Interfaces
with Pure, Nonblocking => False
is
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;
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;
type Parallel_Iterator
is limited interface and Forward_Iterator;
subtype Chunk_Index
is Positive;
function Is_Split (Object : Parallel_Iterator)
return Boolean
is abstract;
procedure Split_Into_Chunks (Object :
in out Parallel_Iterator;
Max_Chunks :
in Chunk_Index)
is abstract
with Pre'Class =>
not Object.Is_Split
or else raise Program_Error,
Post'Class => Object.Is_Split
and then
Object.Chunk_Count <= Max_Chunks;
function Chunk_Count (Object : Parallel_Iterator)
return Chunk_Index
is abstract
with Pre'Class => Object.Is_Split
or else raise Program_Error;
function First (Object : Parallel_Iterator;
Chunk : Chunk_Index)
return Cursor
is abstract
with Pre'Class => (Object.Is_Split
and then
Chunk <= Object.Chunk_Count)
or else raise Program_Error;
function Next (Object : Parallel_Iterator;
Position : Cursor;
Chunk : Chunk_Index)
return Cursor
is abstract
with Pre'Class => (Object.Is_Split
and then
Chunk <= Object.Chunk_Count)
or else raise Program_Error;
type Parallel_Reversible_Iterator
is limited interface
and Parallel_Iterator
and Reversible_Iterator;
end Ada.Iterator_Interfaces;
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.
A
parallel iterator type is a type descended
from the Parallel_Iterator interface from some instance of Ada.Iterator_Interfaces.
A type descended from the Parallel_Reversible_Iterator interface from
some instance of Ada.Iterator_Interfaces is both a parallel iterator
type and a reversible iterator type. An
iterator object is an
object of an iterator type.
A
reversible iterator
object is an object of a reversible iterator type.
A
parallel iterator object is an object of a parallel iterator
type.
The formal subtype Cursor from the associated
instance of Ada.Iterator_Interfaces is the
iteration cursor subtype
for the iterator type.
The following type-related
operational aspects may be specified for an indexable container type
T (see
4.1.6):
Default_Iterator
This aspect is specified by a
name
that denotes exactly one function declared immediately within the same
declaration list in which
T, or the declaration completed by
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.
This aspect is inherited by descendants of type
T (including
T'Class).
Iterator_Element
This aspect is specified by a
name
that denotes a subtype. This is the
default element subtype for
T.
This aspect is inherited by descendants of type
T (including
T'Class).
Iterator_View
This aspect is specified by a
name
that denotes a type
T2 with the following properties:
T2 is declared in the same compilation
unit as T;
T2 is an iterable container type;
T2 has a single discriminant which
is an access discriminant designating T; and
The default iterator subtypes for T
and T2 statically match.
This aspect is never inherited, even by
T'Class.
This paragraph was
deleted.
An
iterable container type is an indexable
container type with specified Default_Iterator and Iterator_Element aspects.
A
reversible iterable container type is an iterable container
type with the default iterator type being a reversible iterator type.
A
parallel iterable container type is an iterable container type
with the default iterator type being a parallel iterator type.
An
iterable container object is an object of an iterable container
type.
A
reversible iterable container object
is an object of a reversible iterable container type.
A
parallel iterable container object is an object of a parallel
iterable container type.
The Default_Iterator and Iterator_Element aspects
are nonoverridable (see
13.1.1).
Legality Rules
The Constant_Indexing
aspect (if any) of an iterable container type T shall denote exactly
one function with the following properties:
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;
the type of the second parameter of the function
covers the default cursor type for T;
if there are more than two parameters, the additional
parameters all have default expressions.
This function (if any) is the
default constant
indexing function for
T.
The Variable_Indexing
aspect (if any) of an iterable container type T shall denote exactly
one function with the following properties:
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;
the type of the second parameter of the function
covers the default cursor type for T;
if there are more than two parameters, the additional
parameters all have default expressions.
This function (if any) is the
default variable
indexing function for
T.
Erroneous Execution
A call on the First or Next operation on a given
Parallel_Iterator object with a given Chunk value, which does not propagate
an exception, should return a Cursor value that either yields False when
passed to Has_Element, or that identifies an element distinct from any
Cursor value returned by a call on a First or Next operation on the same
Parallel_Iterator object with a different Chunk value. If the First or
Next operations with a Chunk parameter behave in any other manner, execution
is erroneous.
Ada 2005 and 2012 Editions sponsored in part by Ada-Europe