12.5 Formal Types
A generic formal subtype can be used to pass to a
generic unit a subtype whose type is in a certain category of types.
Syntax
Legality Rules
For
a generic formal subtype, the actual shall be a
subtype_mark;
it denotes the
(generic) actual subtype.
Static Semantics
Legality Rules
The actual type shall be in the category determined
for the formal.
Static Semantics
The formal type also belongs to each category that
contains the determined category. The primitive subprograms of the type
are as for any type in the determined category. For a formal type other
than a formal derived type, these are the predefined operators of the
type. For an elementary formal type, the predefined operators are implicitly
declared immediately after the declaration of the formal type. For a
composite formal type, the predefined operators are implicitly declared
either immediately after the declaration of the formal type, or later
immediately within the declarative region in which the type is declared
according to the rules of
7.3.1. In an instance,
the copy of such an implicit declaration declares a view of the predefined
operator of the actual type, even if this operator has been overridden
for the actual type. The rules specific to formal derived types are given
in
12.5.1.
7 Generic formal types, like all types,
are not named. Instead, a
name
can denote a generic formal subtype. Within a generic unit, a generic
formal type is considered as being distinct from all other (formal or
nonformal) types.
8 A
discriminant_part
is allowed only for certain kinds of types, and therefore only for certain
kinds of generic formal types. See
3.7.
Examples
Examples of generic
formal types:
type Item is private;
type Buffer(Length : Natural) is limited private;
type Enum is (<>);
type Int is range <>;
type Angle is delta <>;
type Mass is digits <>;
type Table is array (Enum) of Item;
Example of a generic
formal part declaring a formal integer type:
generic
type Rank is range <>;
First : Rank := Rank'First;
Second : Rank := First + 1; -- the operator "+" of the type Rank