Ada Programming/Attributes/'Range
Appearance
Description
[edit | edit source]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 | edit source]type
Tis
range
1..10; -- T'Range is equal to Ttype
Ais
array
(T)of
S; -- these three A'Range is the same as Ttype
Ais
array
(T'Range)of
S; -- declarationstype
Ais
array
(T'First .. T'Last )of
S; -- are equivalenttype
Bis
array
(Trange
<>)of
S; -- B'Range is illegal (B is unconstrained)subtype
SBis
B (2 .. 5); -- SB'Range is the same as 2 .. 5type
Mis
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