Ada Programming/Attributes/'Range
Description
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
typeTisrange1..10; -- T'Range is equal to TtypeAisarray(T)ofS; -- these three A'Range is the same as TtypeAisarray(T'Range)ofS; -- declarationstypeAisarray(T'First .. T'Last )ofS; -- are equivalenttypeBisarray(Trange<>)ofS; -- B'Range is illegal (B is unconstrained)subtypeSBisB (2 .. 5); -- SB'Range is the same as 2 .. 5typeMisarray(Boolean, T)ofS; -- 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