Ada Programming/Attributes/'Range


Ada. Time-tested, safe and secure.
Ada. Time-tested, safe and secure.

Description

edit

The meaning of the attribute depends on the meaning of the prefix X.

If X is a scalar subtype, X'Range represents the range of valid values for that subtype, i.e. it is the same as the subtype itself.

If X is a constrained array subtype or an array object, X'Range denotes the index range of X.

In any case, X'Range is equivalent to X'First .. X'Last, but X is only evaluated once.

If X is multidimensional, the attribute needs a static parameter N to identify the N-th index; 'Range (1) is the same as 'Range.

X'Range (N) is equivalent to X'First(N) .. X'Last(N), but X is only evaluated once.

Examples

edit
type T is range 1..10;  --  T'Range is equal to T

type A is array (T) of S;                  --  these three     A'Range is the same as T
type A is array (T'Range) of S;            --  declarations
type A is array (T'First .. T'Last ) of S; --  are equivalent

type B is array (T range <>) of S;  --  B'Range is illegal (B is unconstrained)
subtype SB is B (2 .. 5);           --  SB'Range is the same as 2 .. 5

type M is array (Boolean, T) of S;  --  M'Range is equivalent to M'Range (1), which is Boolean
                                    --  M'Range (2) is the same as T
OA: A;           --  OA'Range is the same as T
OB: B (2 .. 5);  --  OB'Range is equal to 2 .. 5

See also

edit

Wikibook

edit

Ada Reference Manual

edit